Skip to content

GH-130397: remove special-casing of C stack depth for WASI #134469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025

Conversation

brettcannon
Copy link
Member

@brettcannon brettcannon commented May 21, 2025

Along the way disable some tests which now fail (which were already disabled under Emscripten).

This doesn't pose any sercurity risk thanks to WebAssembly's stack protection.

Removed special-casing for WASI when setting C stack depth limits. Since WASI has its own C stack checking this isn't a security risk.

Also disabled some tests that stopped passing. They all happened to have already been disabled under Emscripten.
@brettcannon brettcannon merged commit ad42dc1 into python:main May 22, 2025
45 checks passed
@brettcannon brettcannon deleted the 130397-wasi-debug-passing branch May 22, 2025 21:08
@miss-islington-app
Copy link

Thanks @brettcannon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 22, 2025
…honGH-134469)

Removed special-casing for WASI when setting C stack depth limits. Since WASI has its own C stack checking this isn't a security risk.

Also disabled some tests that stopped passing. They all happened to have already been disabled under Emscripten.
(cherry picked from commit ad42dc1)

Co-authored-by: Brett Cannon <brett@python.org>
@bedevere-app
Copy link

bedevere-app bot commented May 22, 2025

GH-134547 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 22, 2025
brettcannon added a commit that referenced this pull request May 22, 2025
…-134469) (GH-134547)

GH-130397: remove special-casing of C stack depth for WASI (GH-134469)

Removed special-casing for WASI when setting C stack depth limits. Since WASI has its own C stack checking this isn't a security risk.

Also disabled some tests that stopped passing. They all happened to have already been disabled under Emscripten.
(cherry picked from commit ad42dc1)

Co-authored-by: Brett Cannon <brett@python.org>
@markshannon
Copy link
Member

One of us is misunderstanding the way stacks work in C compiled to webassembly.

As I understand it, there are two stacks: the built in webassembly stack which does have built in protected and and additional stack for arrays and other objects that can have their address taken on the stack. This second stack has no built in protection.

Removing the protection we provide makes it possible to trash the heap and could perhaps introduce security vulnerabilities.

@hoodmane is this correct?

@markshannon
Copy link
Member

What I think we should be doing is reducing the size of the webassembly stack and increasing the size of the in-heap stack, such that the majority of stack overflows are caught by our stack protection mechanism and reported as an exception.

@brettcannon
Copy link
Member Author

One of us is misunderstanding the way stacks work in C compiled to webassembly.

Quite possibly (and it very well could be me).

As I understand it, there are two stacks: the built in webassembly stack which does have built in protected and and additional stack for arrays and other objects that can have their address taken on the stack. This second stack has no built in protection.

Removing the protection we provide makes it possible to trash the heap and could perhaps introduce security vulnerabilities.

Maybe, but I also need to be able to parse Python code in WASI in a debug build and this was the only way I could find how without sinking days into trying to make this all work (assuming it would as I already spent days up to this point).

What I think we should be doing is reducing the size of the webassembly stack and increasing the size of the in-heap stack, such that the majority of stack overflows are caught by our stack protection mechanism and reported as an exception.

If you can explain how to make that happen or make a PR for that then that would be great. But I tried tweaking all of the numbers I had available to me and it never seemed to turn out to a result that didn't cause some critical test failure because the stack got too small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants