Advisory Database
  • Advisories
  • Dependency Scanning
  1. cargo
  2. ›
  3. wasmtime
  4. ›
  5. CVE-2022-24791

CVE-2022-24791: Use after free in Wasmtime

April 1, 2022 (updated May 2, 2025)

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.

This bug was discovered while extending our fuzz targets for externrefs and GC in Wasmtime. The updated fuzz target thoroughly exercises these code paths and feature combinations now. We have also added a regression test for this bug. Released versions 0.34.2 and 0.35.2, which fix the vulnerability. We recommend all Wasmtime users 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 or by disabling epoch interruption if you were previously enabling it.

References

  • docs.rs/wasmtime/latest/wasmtime/struct.Config.html
  • github.com/WebAssembly/reference-types
  • github.com/advisories/GHSA-gwc9-348x-qwv2
  • github.com/bytecodealliance/wasmtime
  • github.com/bytecodealliance/wasmtime/commit/666c2554ea0e1728c35aa41178cf235920db888a
  • github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gwc9-348x-qwv2
  • nvd.nist.gov/vuln/detail/CVE-2022-24791
  • rustsec.org/advisories/RUSTSEC-2022-0016.html
  • rustsec.org/advisories/RUSTSEC-2022-0099.html

Code Behaviors & Features

Detect and mitigate CVE-2022-24791 with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →

Affected versions

All versions before 0.34.2, all versions starting from 0.35.0 before 0.35.2

Fixed versions

  • 0.34.2
  • 0.35.2

Solution

Upgrade to versions 0.34.2, 0.35.2 or above.

Impact 9.8 CRITICAL

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Learn more about CVSS

Weakness

  • CWE-416: Use After Free

Source file

cargo/wasmtime/CVE-2022-24791.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Wed, 14 May 2025 12:15:15 +0000.