# CVE-2022-24791: Use after free in Wasmtime

> Attackers can trigger a use-after-free in Wasmtime by exploiting missing stack maps during garbage collection, potentially leading to code execution or crashes.

- **Severity:** High 8.1 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 31 Mar 2022
- **Updated:** 23 Apr 2025
- **Also known as:** GHSA-gwc9-348x-qwv2, RUSTSEC-2022-0016, RUSTSEC-2022-0099, UBUNTU-CVE-2022-24791, openSUSE-SU-2024:12009-1

## What is CVE-2022-24791?

CVE-2022-24791 is a high-severity use after free vulnerability in bytecodealliance wasmtime, published on 31 Mar 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official 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).

Weakness: CWE-416 (Use After Free)

## Which versions are affected by CVE-2022-24791?

6 open source packages ship an affected version, including wasmtime. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `wasmtime` | crates.io | All versions | 0.34.2 |
| `wasmtime` | crates.io | All versions | 0.34.2 |
| `wasmtime` | crates.io | From 0.0.0-0 | 0.34.2, 0.35.2 |
| `wasmtime` | crates.io | From 0.34.0 | 0.34.2, 0.35.2 |
| `wasmtime` | crates.io | From 0.35.0 | 0.35.2 |
| `wasmtime` | crates.io | From 0.35.0 | 0.35.2 |
| `cargo-audit-advisory-db` | openSUSE:Tumbleweed | All versions | 20220420-1.1 |

Products: Bytecodealliance Wasmtime.

## How do I fix CVE-2022-24791?

Upgrade wasmtime to a fixed version for your release line: 0.34.2 or 0.35.2.

## Is CVE-2022-24791 being exploited?

There is no known exploitation of CVE-2022-24791 in the wild and no public exploit code.

## Other vulnerabilities in bytecodealliance wasmtime

- [CVE-2026-34971](https://insights.sbomify.com/CVE-2026-34971/): Wasmtime miscompiled guest heap access enables sandbox escape on aarch64 Cranelift (critical 9.0)
- [CVE-2026-34987](https://insights.sbomify.com/CVE-2026-34987/): Wasmtime with Winch compiler backend on aarch64 may allow a sandbox-escaping memory access (critical 9.0)
- [CVE-2022-39393](https://insights.sbomify.com/CVE-2022-39393/): Wasmtime vulnerable to data leakage between instances in the pooling allocator (high 8.6)
- [CVE-2026-47261](https://insights.sbomify.com/CVE-2026-47261/): Wasmtime: WASI path_open(TRUNCATE) bypasses `FilePerms::WRITE` host restriction (high 7.5)
- [CVE-2026-34941](https://insights.sbomify.com/CVE-2026-34941/): Wasmtime has a Heap OOB read in component model UTF-16 to latin1+utf16 string transcoding (medium 6.9)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-24791 and fix it if it is affected.

What it is: CVE-2022-24791 is a high-severity use after free vulnerability in bytecodealliance wasmtime, published on 31 Mar 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2022-24791 in the wild and no public exploit code.

Affected packages and fixed versions:
- wasmtime (crates.io): affected all versions; fixed in 0.34.2
- wasmtime (crates.io): affected all versions; fixed in 0.34.2
- wasmtime (crates.io): affected from 0.0.0-0; fixed in 0.34.2, 0.35.2
- wasmtime (crates.io): affected from 0.34.0; fixed in 0.34.2, 0.35.2
- wasmtime (crates.io): affected from 0.35.0; fixed in 0.35.2
- wasmtime (crates.io): affected from 0.35.0; fixed in 0.35.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-24791/ (Markdown: https://insights.sbomify.com/CVE-2022-24791/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-24791
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-24791
- OSV: https://osv.dev/vulnerability/CVE-2022-24791

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-24791/
Summaries are generated and may contain mistakes; the official description above is the record.
