CVE-2022-31146 Use After Free in Wasmtime

Medium 6.4 Published Updated

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.

PackageAffectedFixed in
wasmtime crates.ioFrom 0.0.0-00.38.2
wasmtime crates.ioFrom 0.37.00.38.2
wasmtime crates.ioFrom 0.37.00.38.2
cranelift-codegen crates.ioFrom 0.84.00.85.2
cranelift-codegen crates.ioFrom 0.84.00.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.

Sources

Also known as GHSA-5fhj-g3p3-pq9g, RUSTSEC-2022-0100, UBUNTU-CVE-2022-31146.

Is CVE-2022-31146 in your software?

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

Check your SBOMs for free