6.4medium
Use After Free in Wasmtime
- Severity
- 6.4medium CVSS:3.1 by GitHub_M
- Exploit likelihood
- 1.28% (higher than 70% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-5fhj-g3p3-pq9gRUSTSEC-2022-0100
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.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| bytecodealliance wasmtime | >= 0.37.0, < 0.38.2, >= 0.84.0, < 0.85.2, from 0.37.0 before 0.38.2 | CVE List, NVD |
| wasmtime (crates.io) | from 0.37.0 before 0.38.2, from 0.0.0-0 before 0.38.2 | GitHub Advisory Database, RustSec Advisory Database |
| cranelift-codegen (crates.io) | from 0.84.0 before 0.85.2 | GitHub Advisory Database |
| bytecodealliance cranelift-codegen | from 0.84.0 before 0.85.2 | NVD |
All scores
| GitHub_M | 6.4medium CVSS:3.1 | CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:L |
| GitHub | 6.4medium CVSS:3.1 | CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:L |
| NVD | 8.8high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.
What each source says
CVE List
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.
GitHub Advisory Database
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
falsetowasmtime::Config::wasm_reference_types. - Downgrading to Wasmtime 0.36.0 or prior.
RustSec Advisory Database
This is an entry in the RustSec database for the Wasmtime security advisory located at https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-5fhj-g3p3-pq9g. For more information see the GitHub-hosted security advisory.
NVD (es)
Se presenta un error en el generador de código de Wasmtime, Cranelift, en el que las funciones que usan tipos de referencia pueden carecer incorrectamente de los metadatos necesarios para la recolección de basura en tiempo de ejecución. Esto significa que si es producida una GC en tiempo de ejecución, el pase de GC pensará erróneamente que estas funciones no presentan referencias vivas a los valores de la GC, reclamándolos y reasignándolos. La función continuará entonces usando los valores asumiendo que no han sido GC'd, conllevando más tarde a un uso de memoria previamente liberada. Este bug fue introducido en la migración al asignador de registros "regalloc2" que ocurrió en Wasmtime versión 0.37.0 del 20-05-2022. Este bug ha sido parcheado y los usuarios deberían actualizar a Wasmtime versión 0.38.2. La mitigación de este problema puede lograrse al hacer una de las siguientes cosas: * Deshabilitar la propuesta de tipos de referencia pasando "false" a ["wasmtime::Config::wasm_reference_types"](https://docs.rs/wasmtime/0.38.0/wasmtime/struct.Config.html#method.wasm_reference_types). * Desactualizar a Wasmtime versión 0.36.0 o anterior
References
| https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-5fhj-g3p3-pq9g | mitigation, third-party-advisory, web | |
| https://github.com/WebAssembly/reference-types | third-party-advisory, web | |
| https://github.com/bytecodealliance/wasmtime/ | product, third-party-advisory | |
| https://nvd.nist.gov/vuln/detail/CVE-2022-31146 | advisory | |
| https://github.com/bytecodealliance/wasmtime/commit/2ba4bce5cc719e5a74e571a534424614e62ecc41 | web | |
| https://github.com/bytecodealliance/wasmtime | package | |
| https://rustsec.org/advisories/RUSTSEC-2022-0100.html | advisory, web | |
| https://crates.io/crates/wasmtime | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2022-31146 changed 2025-04-23 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-5fhj-g3p3-pq9g changed 2025-05-02 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2022-0100 changed 2026-10-12 | CC0-1.0 |
| NVD | CVE-2022-31146 changed 2026-06-17 | Public domain |