Skip to content

[lld][WebAssembly] --stack-first should be the default for wasm-ldΒ #151015

@whitequark

Description

@whitequark

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.
  • Using --stack-first has no code size overhead for the resulting artifact when otherwise default linker options are used.
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions