CVE-2022-24791 Use after free in Wasmtime

High 8.1 Published Updated

Attackers can trigger a use-after-free in Wasmtime by exploiting missing stack maps during garbage collection, potentially leading to code execution or crashes.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2022-24791?

CVE-2022-24791 is a high-severity use after free vulnerability in bytecodealliance wasmtime, published on 31 Mar 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

Wasmtime is a standalone JIT-style runtime for WebAssembly, using Cranelift. There is a use after free vulnerability in Wasmtime when both running Wasm that uses externrefs and enabling epoch interruption in Wasmtime. If you are not explicitly enabling epoch interruption (it is disabled by default) then you are not affected. If you are explicitly disabling the Wasm reference types proposal (it is enabled by default) then you are also not affected. The use after free is caused by Cranelift failing to emit stack maps when there are safepoints inside cold blocks. Cold blocks occur when epoch interruption is enabled. Cold blocks are emitted at the end of compiled functions, and change the order blocks are emitted versus defined. This reordering accidentally caused Cranelift to skip emitting some stack maps because it expected to emit the stack maps in block definition order, rather than block emission order. When Wasmtime would eventually collect garbage, it would fail to find live references on the stack because of the missing stack maps, think that they were unreferenced garbage, and therefore reclaim them. Then after the collection ended, the Wasm code could use the reclaimed-too-early references, which is a use after free. Patches have been released in versions 0.34.2 and 0.35.2, which fix the vulnerability. All Wasmtime users are recommended to upgrade to these patched versions. If upgrading is not an option for you at this time, you can avoid the vulnerability by either: disabling the Wasm reference types proposal, config.wasm_reference_types(false); or by disabling epoch interruption if you were previously enabling it. config.epoch_interruption(false).

Weakness: CWE-416

Which versions are affected by CVE-2022-24791?

6 open source packages ship an affected version, including wasmtime. It affects 1 product.

PackageAffectedFixed in
wasmtime crates.ioAll versions0.34.2
wasmtime crates.ioAll versions0.34.2
wasmtime crates.ioFrom 0.0.0-00.34.2, 0.35.2
wasmtime crates.ioFrom 0.34.00.34.2, 0.35.2
wasmtime crates.ioFrom 0.35.00.35.2
wasmtime crates.ioFrom 0.35.00.35.2
Linux distribution packages (1)
cargo-audit-advisory-db openSUSE:TumbleweedAll versions20220420-1.1

Products include Bytecodealliance Wasmtime.

How do I fix CVE-2022-24791?

Upgrade wasmtime to a fixed version for your release line: 0.34.2 or 0.35.2.

Upgrade to the fixed version. These bugs are found with fuzzing and sanitisers and avoided by memory-safe languages. More about Use after free.

Is CVE-2022-24791 being exploited?

There is no known exploitation of CVE-2022-24791 in the wild and no public exploit code.

Sources

Also known as GHSA-gwc9-348x-qwv2, RUSTSEC-2022-0016, RUSTSEC-2022-0099, UBUNTU-CVE-2022-24791, openSUSE-SU-2024:12009-1.

Is CVE-2022-24791 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free