Skip to main content

CVE-2022-31146: CWE-416: Use After Free in bytecodealliance wasmtime

Medium
VulnerabilityCVE-2022-31146cvecve-2022-31146cwe-416-use-after-free
Published: Wed Jul 20 2022 (07/20/2022, 22:30:16 UTC)
Source: CVE
Vendor/Project: bytecodealliance
Product: wasmtime

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.

AI-Powered Analysis

AILast updated: 06/23/2025, 01:35:32 UTC

Technical Analysis

CVE-2022-31146 is a use-after-free vulnerability (CWE-416) found in Wasmtime, a standalone runtime for WebAssembly developed by the Bytecode Alliance. The vulnerability stems from a bug in Wasmtime's code generator, Cranelift, specifically related to the handling of reference types during garbage collection (GC). In versions of Wasmtime from 0.37.0 up to but not including 0.38.2, and from 0.84.0 up to but not including 0.85.2, functions that use WebAssembly reference types may lack the necessary metadata for the runtime GC to correctly identify live references. As a result, the GC may erroneously reclaim and deallocate memory that is still in use by these functions. When the function continues execution, it accesses memory that has already been freed, leading to a use-after-free condition. This can cause undefined behavior including crashes, memory corruption, or potentially arbitrary code execution depending on the context of the memory usage. The root cause was introduced during the migration to the regalloc2 register allocator in Wasmtime 0.37.0. The vulnerability has been patched in Wasmtime 0.38.2 and 0.85.2. Mitigations include disabling the reference types feature by setting `wasmtime::Config::wasm_reference_types` to false or downgrading to Wasmtime 0.36.0 or earlier. No known exploits in the wild have been reported to date. The vulnerability requires the use of WebAssembly modules that utilize reference types and the Wasmtime runtime configured to enable them. Exploitation does not require user interaction but does require the ability to execute or load crafted WebAssembly code within the vulnerable Wasmtime runtime environment.

Potential Impact

For European organizations, the impact of this vulnerability depends largely on the extent to which Wasmtime is used in their software stacks, particularly in environments running WebAssembly workloads. Wasmtime is increasingly adopted in cloud-native applications, edge computing, and serverless platforms due to its lightweight and secure runtime characteristics. A successful exploitation could lead to denial of service through crashes or memory corruption, potentially disrupting critical services. More severe impacts could include arbitrary code execution, which would compromise confidentiality and integrity of data and systems. This is particularly concerning for sectors relying on WebAssembly for sandboxed execution of untrusted code, such as financial services, telecommunications, and critical infrastructure. Given the vulnerability affects runtime garbage collection of reference types, applications using advanced WebAssembly features are more at risk. The absence of known exploits reduces immediate risk, but the medium severity rating and the potential for exploitation in multi-tenant or cloud environments warrant proactive mitigation. Organizations using Wasmtime in production should prioritize patching to avoid exposure to memory corruption vulnerabilities that can be leveraged for privilege escalation or persistent compromise.

Mitigation Recommendations

1. Upgrade Wasmtime to version 0.38.2 or later (for the 0.37.x branch) or 0.85.2 or later (for the 0.84.x branch) to apply the official patch addressing this vulnerability. 2. If immediate upgrading is not feasible, disable the WebAssembly reference types feature by setting `wasmtime::Config::wasm_reference_types` to false, effectively preventing the vulnerable code path from being exercised. 3. Consider downgrading to Wasmtime 0.36.0 or earlier as a temporary workaround, though this may impact functionality and compatibility with newer WebAssembly modules. 4. Audit and monitor WebAssembly workloads for unusual behavior or crashes that could indicate exploitation attempts. 5. Implement runtime memory protection and sandboxing measures around Wasmtime instances to limit the impact of potential memory corruption. 6. For organizations deploying Wasmtime in multi-tenant or cloud environments, enforce strict input validation and isolation to prevent untrusted WebAssembly modules from triggering the vulnerability. 7. Maintain an inventory of systems and applications using Wasmtime to ensure timely patching and configuration management. 8. Engage with Wasmtime and Bytecode Alliance community channels for updates and best practices related to WebAssembly security.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-05-18T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9844c4522896dcbf38a1

Added to database: 5/21/2025, 9:09:24 AM

Last enriched: 6/23/2025, 1:35:32 AM

Last updated: 8/12/2025, 8:10:06 PM

Views: 22

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats