-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
Description
There are several arguments in favor of doing so:
- With stack protectors disabled by default, no dynamic stack overflow checks, a default stack size of 64K (the smallest of any non-bare-metal platform), and no memory protection, WebAssembly is uniquely vulnerable to stack smashing in a way that only the simplest microcontrollers that lack an MPU also are.
- Even ignoring the security aspect, the developer experience of encountering a stack overflow in the wild is confusing and difficult to recognize even for a professional systems developer, tools like Wasmtime's
wmemcheck
do not recognize it as a stack overflow specifically, and LLVM's suite of sanitizers isn't available to detect it when building for Wasm.- Emscripten provides stack overflow checks and ASan/MSan/UBSan, but ths isn't available on stock LLVM/Clang and wasi-sdk. (UBSan support could conceivably be polyfilled by an end user but the rest require compiler patches.)
- Using
--stack-first
has no code size overhead for the resulting artifact when otherwise default linker options are used.- Using
--stack-first
in conjunction with--compress-relocations
has well below 1% size overhead.
- Using
- Other languages like Rust and Zig pass this option by default for the same reasons.
Although the memory control proposal will mitigate the need for this change, that proposal doesn't negate the need to make --stack-first
the default now:
- Memory control is a Phase 1 proposal with uncertain design and adoption. We need to solve the problems listed above yesterday.
- Without inserting stack probes, using guard pages won't be enough to eliminate stack smashing for functions that use VLAs or alloca, so even if memory control was widely available,
--stack-first
has its merit until stack probes are implemented in LLVM for WebAssembly and enabled by default.
rajsite