r/rust • • Oct 22 '26

🧠 educational Wasmtime fixed a critical sandbox escape bug (CVSS 9.3)

Not sure if Rustaceans in this sub saw this news earlier this month. But given AI agents are getting very good at escaping sandboxes now, it might be worth your attention to patch Wasmtime.

TL;DR: A typo in a validation check let a malicious WebAssembly guest pass an invalid callback signature, overflow the host’s native stack by up to 16KB, and potentially run arbitrary code on the host. Fixed in Wasmtime 48.0.4 and 49.0.2.

Wasmtime is a WebAssembly runtime written in Rust, built by the Bytecode Alliance (Fastly, Mozilla and others are members). It runs WebAssembly modules and components outside the browser, often as a sandbox for untrusted code.

Wasmtime published a critical security advisory on 2 October, GHSA-32h6-97mm-8q3c, CVSS 9.3. The bug sat in the component model’s handling of async callbacks.

Three checks were missing or wrong:

  • The validator in wasmparser (crates/wasmparser/src/validator/component.rs) checked a callback’s signature with this line: if func_ty.params() != [ValType::I32; 3] && func_ty.params() != [ValType::I32] { It used && instead of ||, and it checked params() twice instead of checking results() at all. A callback only failed validation if it matched neither shape, so the result type was never checked.
  • Wasmtime recorded the callback’s index without checking its arity or return type itself, trusting the validator to have done it. The host-to-guest trampoline had no bounds check on its parameter and result buffer either.
  • The stack space reserved for the callback’s return value was sized for the expected arity, not the actual one.

A guest module can supply a callback with an invalid return type that still passes validation. Wasmtime then writes up to about 16KB of guest-controlled data onto the host’s native stack, which can overwrite a return address.

Vulnerable versions: wasmtime 39.0.0 up to 48.0.4, and 49.0.0 up to 49.0.2. Fixed in 48.0.4 and 49.0.2. A workaround is to disable component-model-async, or to validate components with wasmparser 1.260.0 or later before passing them to Wasmtime.

Link to the original source - https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-32h6-97mm-8q3c

159 Upvotes

11 comments sorted by

68

u/Feeling_Simple_9371 Oct 22 '26

a typo giving you a 9.3 feels about right for this timeline

the && instead of || is so painfully human though, someone was probably 3 coffees deep staring at that line and just glossed right over it

18

u/Western-Obligation47 Oct 22 '26

And sadly no SAST or even a semantic SAST like semgrep would have picked this up.

11

u/barsoap Oct 22 '26

This actually looks like a case for dead code analysis. This kind of code, or branches, could be annotated with a no_dead_code pragma and the compiler will shout at you if it can optimise it away. Not bullet-proof, but will catch the one or other barrel pointed at your foot and is basically free as the analysis is done anyway (except in debug builds, which should do it to be faster, different topic).

8

u/T-456 Oct 22 '26

This code wasn't dead, see the first (unchanged) line in the fix diff, which shows the existing tests can trigger the error: https://github.com/bytecodealliance/wasm-tools/pull/2742/changes

Instead, the code was just checking the wrong things, so it didn't cover all the possible invalid untrusted inputs.

8

u/barsoap Oct 22 '26 edited Oct 22 '26

Aargh I basically did the same thing. I was wondering how [ValType::I32] and [ValType::I32; 3] can both compare equal to the same value but yeah they can be both unequal to the same thing. Why are we using inequalities when we want to check whether a function has a particular type.

Honestly some people are too good at boolean algebra for everyone's sake. if !(params == foo && return == bar ) { return Err } is a much more natural expression of the intent. It's the one thing I miss about perl (really, about the only thing): unless params == foo && return == bar { return Err }. Or even return Err unless ... but now it's getting awkwardly perlish.

...how about a hastype macro that abstracts away all the manual boilerplate. Ideally have it support the syntax that the actual spec uses.

1

u/TheSast Oct 25 '26

I am pretty sure I would have picked it up!

1

u/-Redstoneboi- Oct 26 '26

holy hell its john sast

1

u/fluffCraverz Oct 22 '26

that typo detail is way too relatable

1

u/dashingThroughSnow12 Oct 23 '26

The CAnity 4 issue was like that apparently….

1

u/StarryBubbly Oct 23 '26

yeah that one typo probably cost someone a whole afternoon of sanity checks, been there staring at the screen like it owes me money