CVE-2022-31146 Use After Free in Wasmtime
A use-after-free vulnerability in Wasmtime's Cranelift code generator allows attackers to execute arbitrary code or cause denial of service via crafted WebAssembly modules.
- Exploited in the wild
- Not known
- Login needed
- Any signed-in user
- Attackable
- Over the internet
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2022-31146?
CVE-2022-31146 is a medium-severity use after free vulnerability in bytecodealliance wasmtime, published on 20 Jul 2022. Any signed-in user can exploit it over the network, with no action from the victim.
Official description
Wasmtime is a standalone runtime for WebAssembly. There is a bug in the Wasmtime's code generator, Cranelift, where functions using reference types may be incorrectly missing metadata required for runtime garbage collection. This means that if a GC happens at runtime then the GC pass will mistakenly think these functions do not have live references to GC'd values, reclaiming them and deallocating them. The function will then subsequently continue to use the values assuming they had not been GC'd, leading later to a use-after-free. This bug was introduced in the migration to the `regalloc2` register allocator that occurred in the Wasmtime 0.37.0 release on 2022-05-20. This bug has been patched and users should upgrade to Wasmtime version 0.38.2. Mitigations for this issue can be achieved by disabling the reference types proposal by passing `false` to `wasmtime::Config::wasm_reference_types` or downgrading to Wasmtime 0.36.0 or prior.
Weakness: CWE-416
Which versions are affected by CVE-2022-31146?
5 open source packages ship an affected version, including wasmtime and cranelift-codegen. It affects 2 products.
| Package | Affected | Fixed in |
|---|---|---|
wasmtime crates.io | From 0.0.0-0 | 0.38.2 |
wasmtime crates.io | From 0.37.0 | 0.38.2 |
wasmtime crates.io | From 0.37.0 | 0.38.2 |
cranelift-codegen crates.io | From 0.84.0 | 0.85.2 |
cranelift-codegen crates.io | From 0.84.0 | 0.85.2 |
Products include Bytecodealliance Cranelift-Codegen, Bytecodealliance Wasmtime.
How do I fix CVE-2022-31146?
Upgrade wasmtime to 0.38.2 or later.
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-31146 being exploited?
There is no known exploitation of CVE-2022-31146 in the wild and no public exploit code.
Other vulnerabilities in bytecodealliance wasmtime
- CVE-2023-26489 Guest-controlled out-of-bounds read/write on x86_64 in wasmtime
- CVE-2021-32629 Memory access due to code generation flaw in Cranelift module
- CVE-2022-31169 Cranelift vulnerable to miscompilation of constant values in division on AArch64
- CVE-2022-31104 Miscompilation of `i8x16.swizzle` and `select` with v128 inputs in Wasmtime
- CVE-2023-27477 wasmtime vulnerable to miscompilation of `i8x16.select` with the same inputs on x86_64
Sources
Also known as GHSA-5fhj-g3p3-pq9g, RUSTSEC-2022-0100, UBUNTU-CVE-2022-31146.