-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Implement stack overflow protection for webassembly #130397
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
Comments
If the spilled stack ever overflows, we can just recompile and make it bigger whereas the wasm stack size is determined by the runtime and can't easily be made bigger. At least for Emscripten run in the browser. Perhaps with wasmtime we can easily ask the runtime to make the stack bigger. |
This is about runtime detection of stack limits, rather than increasing the stack size. Is it possible to get the size of the wasm stack from the browser or wasmtime? Alternatively, is it possible to catch a stack overflow in JS? We could maybe write a JS helper function to probe the stack. |
It's possible to catch a js stack overflow. I've used the probe approach before but unfortunately the ratio of the number of js stack frames it takes to overflow vs the number of wasm frames is inconsistent between V8 and spider monkey. They have similar apparent wasm stack sizes but spider monkey can handle many more nested js frames than V8 iirc. |
I think in node there are ways to query the stack size and depth but it is not part of the web standard and I think browsers don't include any such APIs unless you start the browser in a debug mode. |
I don't think wasmtime specifically, or WASI in general, provides an API exposing stack details. As Hood said, the best you can probably do is set the stack larger than you're expecting when you launch the WebAssembly host and have Python's stack detection try to handle things, but I know that negates the point of what you're trying to do. |
Signed-off-by: Filipe Laíns <[email protected]>
The related issues all seem to be parser failures in test_compile. Maybe we should temporarily reduce the limit when parsing? |
Not anymore. With a checkout from yesterday running
test_ast
test_ttk_textonly
test_unparse which only fails in a full test suite run
|
Here is a code snippet taken from def test_format_layoutlist(self):
def sample(indent=0, indent_size=2):
return ttk._format_layoutlist(
[('a', {'other': [1, 2, 3], 'children':
[('b', {'children':
[('c', {'children':
[('d', {'nice': 'opt'})], 'something': (1, 2)
})]
})]
})], indent=indent, indent_size=indent_size)[0] This results in:
Maybe @pablogsal has an idea of how the parser might be using just enough memory on this snippet of code to fail? |
I don't understand why this is making it fail. Before, we had a hardcoded limit of 4000 levels for wasi and 6000 for non wasi, which was not failing. Maybe we are being a bit conservative? The parser will recurse naturally as it is exploring the grammar space. I assume for this code it may go 300 / 400 levels deep. According to GCC the average stack size of the parser rules is 118 bytes ( using |
I tried increasing the default value using the new stack protections system in #131770 (comment) , but it either continued to raise |
Implementing stack overflow protection for webassembly is tricky, as there are two stacks:
We need to avoid overflowing either. It generally seems that the first stack is the one most vulnerable to overflow, so perhaps a simple counter would work.
@brettcannon
@hoodmane
Linked PRs
The text was updated successfully, but these errors were encountered: