Skip to content

bug: wasmtime stack corruption #797

@drapl0n

Description

@drapl0n

Executing strace-grate causes stack pointer to override frame pointer causing an overflow:

// At the start of each iteration of the loop, we know that `fp` is
// a frame pointer from Wasm code. Therefore, we know it is not
// being used as an extra general-purpose register, and it is safe
// dereference to get the PC and the next older frame pointer.
// The stack grows down, and therefore any frame pointer we are
// dealing with should be less than the stack pointer on entry
// to Wasm.
assert!(trampoline_sp >= fp, "{trampoline_sp:#x} >= {fp:#x}");

During the initial triage issue appeared to be due to the large number of registered syscall handlers. Reducing the number of registered syscalls prevented the panic, which initially suggested stack size exhaustion issue.

Further debugging resulted that the root cause of the panics are syscalls that requires multi-threading: exec , exit, fork and clone. They can be interposed but forwarding them causes an unexpected behavior.

Building lind with the latest PR (that enables wasmtime backtrace) throws completely different errors and panics at:

thread 'lind-fork-2' (505124) panicked at /home/lind/lind-wasm/src/wasmtime/crates/fdtables/src/dashmaparrayglobal.rs:86:5:
Unknown cageid in fdtable access
thread 'lind-fork-2' (505124) panicked at /rustc/8387095803f21a256a9a772ac1f9b41ed4d5aa0a/library/core/src/panicking.rs:225:5:
panic in a function that cannot unwind

The syscall invoked immediately before the panic is exit and associated cageid is 777777 which corresponds to RawPOSIX.

Additionally, the output produced by the grate is non-deterministic and might be due #774.

This issue can be reproduced by executing strace-grate with any test in our test suite.

@Yaxuan-w

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions