Skip to main content

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

Medium
VulnerabilityCVE-2022-24791cvecve-2022-24791cwe-416-use-after-free
Published: Thu Mar 31 2022 (03/31/2022, 23:00:15 UTC)
Source: CVE
Vendor/Project: bytecodealliance
Product: wasmtime

Description

Wasmtime is a standalone JIT-style runtime for WebAssembly, using Cranelift. There is a use after free vulnerability in Wasmtime when both running Wasm that uses externrefs and enabling epoch interruption in Wasmtime. If you are not explicitly enabling epoch interruption (it is disabled by default) then you are not affected. If you are explicitly disabling the Wasm reference types proposal (it is enabled by default) then you are also not affected. The use after free is caused by Cranelift failing to emit stack maps when there are safepoints inside cold blocks. Cold blocks occur when epoch interruption is enabled. Cold blocks are emitted at the end of compiled functions, and change the order blocks are emitted versus defined. This reordering accidentally caused Cranelift to skip emitting some stack maps because it expected to emit the stack maps in block definition order, rather than block emission order. When Wasmtime would eventually collect garbage, it would fail to find live references on the stack because of the missing stack maps, think that they were unreferenced garbage, and therefore reclaim them. Then after the collection ended, the Wasm code could use the reclaimed-too-early references, which is a use after free. Patches have been released in versions 0.34.2 and 0.35.2, which fix the vulnerability. All Wasmtime users are recommended to upgrade to these patched versions. If upgrading is not an option for you at this time, you can avoid the vulnerability by either: disabling the Wasm reference types proposal, config.wasm_reference_types(false); or by disabling epoch interruption if you were previously enabling it. config.epoch_interruption(false).

AI-Powered Analysis

AILast updated: 06/23/2025, 11:37:14 UTC

Technical Analysis

CVE-2022-24791 is a use-after-free vulnerability (CWE-416) found in Wasmtime, a standalone Just-In-Time (JIT) runtime for WebAssembly (Wasm) developed by the Bytecode Alliance. Wasmtime leverages Cranelift as its code generator. The vulnerability arises specifically when Wasmtime is configured to run Wasm modules that utilize externrefs (external references) and have epoch interruption enabled. Epoch interruption is a feature designed to allow preemption of long-running Wasm code, but it is disabled by default. Similarly, the Wasm reference types proposal, which enables externrefs, is enabled by default but can be explicitly disabled to avoid this issue. The root cause lies in Cranelift's failure to emit stack maps correctly when safepoints occur inside "cold blocks"—blocks of code emitted at the end of compiled functions when epoch interruption is enabled. Cranelift expects to emit stack maps in the order blocks are defined, but cold blocks reorder emission, causing some stack maps to be skipped. Stack maps are essential for the garbage collector to identify live references on the stack. Missing stack maps lead Wasmtime's garbage collector to mistakenly reclaim live externrefs prematurely. After this erroneous reclamation, the Wasm code may continue to use these freed references, resulting in a use-after-free condition. This vulnerability affects Wasmtime versions prior to 0.34.2 and versions from 0.35.0 up to but not including 0.35.2. Patches addressing this issue have been released in versions 0.34.2 and 0.35.2. Users are strongly advised to upgrade to these versions. If upgrading is not feasible, mitigating the vulnerability is possible by disabling either the Wasm reference types proposal (config.wasm_reference_types(false)) or epoch interruption (config.epoch_interruption(false)). No known exploits have been reported in the wild, but the vulnerability poses a risk of memory corruption, which could lead to arbitrary code execution or denial of service depending on the context in which Wasmtime is used.

Potential Impact

The use-after-free vulnerability in Wasmtime can have significant security implications for European organizations that rely on Wasmtime for running WebAssembly workloads, especially those enabling epoch interruption and using externrefs. Exploitation could lead to memory corruption, potentially allowing attackers to execute arbitrary code, escalate privileges, or cause denial of service by crashing the runtime. This is particularly critical in environments where Wasmtime is embedded in cloud services, edge computing platforms, or serverless architectures, which are increasingly adopted across Europe. Given the growing adoption of WebAssembly for secure, portable code execution in web applications, IoT devices, and cloud-native environments, the vulnerability could affect a wide range of sectors including finance, telecommunications, manufacturing, and government services. The ability to exploit this flaw depends on specific configuration settings, which may limit exposure but also means that organizations unaware of these settings might be vulnerable. Furthermore, the vulnerability's impact on confidentiality and integrity is notable because use-after-free bugs can be leveraged to bypass memory safety guarantees, potentially exposing sensitive data or allowing unauthorized code execution. Availability could also be affected if exploitation leads to crashes or resource exhaustion. Although no active exploits are known, the potential for targeted attacks exists, especially against high-value targets using Wasmtime in critical infrastructure or sensitive data processing.

Mitigation Recommendations

1. Immediate Upgrade: Organizations using Wasmtime should upgrade to patched versions 0.34.2 or 0.35.2 as soon as possible to eliminate the vulnerability. 2. Configuration Hardening: If upgrading is not immediately possible, disable epoch interruption (config.epoch_interruption(false)) or disable the Wasm reference types proposal (config.wasm_reference_types(false)) to mitigate the vulnerability. 3. Audit Usage: Conduct an audit of all Wasmtime deployments to identify configurations enabling epoch interruption and externrefs, as these are prerequisites for exploitation. 4. Monitoring and Detection: Implement runtime monitoring to detect abnormal Wasmtime crashes or memory corruption symptoms that could indicate exploitation attempts. 5. Supply Chain Controls: Verify the integrity of Wasmtime binaries and dependencies to prevent introduction of maliciously modified versions. 6. Developer Awareness: Educate developers and DevOps teams about the risks associated with enabling epoch interruption and externrefs, encouraging secure configuration practices. 7. Incident Response Preparedness: Prepare incident response plans specifically addressing potential exploitation of memory corruption vulnerabilities in WebAssembly runtimes. 8. Limit Exposure: Where possible, isolate Wasmtime workloads in sandboxed or containerized environments with strict access controls to limit the impact of any successful exploitation.

Need more detailed analysis?Get Pro

Technical Details

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

Threat ID: 682d9843c4522896dcbf2b9b

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

Last enriched: 6/23/2025, 11:37:14 AM

Last updated: 8/12/2025, 10:30:19 PM

Views: 15

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