There is a bug in Wasmtime’s code generator, Cranelift, where functions using reference types may be incorrectly missing metadata required for runtime garbage collection (GC). This means that if a GC happens at runtime then the collector will mistakenly think some Wasm stack frames do not have live references to garbage collected values and therefore reclaim and deallocate them. The function can then subsequently continue to use the values, leading later to use-after-free bugs. This bug was introduced in Cranelift’s migration to the regalloc2
register allocator 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 doing one of:
- Disabling the reference types proposal by passing
false
towasmtime::Config::wasm_reference_types
. - Downgrading to Wasmtime 0.36.0 or prior.
References
- https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-5fhj-g3p3-pq9g
- https://github.com/bytecodealliance/wasmtime/commit/2ba4bce5cc719e5a74e571a534424614e62ecc41
- https://nvd.nist.gov/vuln/detail/CVE-2022-31146
- https://github.com/WebAssembly/reference-types
- https://github.com/bytecodealliance/wasmtime/
- https://github.com/advisories/GHSA-5fhj-g3p3-pq9g