CVE-2022-31146: Wasmtime Wasmtime Vulnerable To Use After Vulnerability
MODERATECVE-2022-31146 is a MODERATE (CVSS 6.4) wasmtime vulnerable to use after vulnerability (CWE-416: Use After Free) affecting Wasmtime libraries in the crates.io ecosystem. The issue involves wasmtime vulnerable to use after free with `externref`s. Remediation is available by upgrading affected packages to version 0.38.2, 0.85.2.
CVE-2022-31146 at a Glance
Security Impact
CVSS: 6.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:L).
How to Fix CVE-2022-31146
To remediate this vulnerability, upgrade all affected Wasmtime dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade wasmtime to 0.38.2
Upgrade cranelift-codegen to 0.85.2
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for wasmtime
How to Check if You Are Affected
To determine whether your application is affected by CVE-2022-31146, inspect your project dependencies for Wasmtime:
inspect dependencies for wasmtime
Analyze the terminal output to locate any version of Wasmtime in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.38.2), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-416: Use After Free, where the product reuses or references memory after it has been freed. at some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer. In Wasmtime, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2022-31146 Affected Wasmtime Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
wasmtime
|
crates.io |
≥ 0.37.0
< 0.38.2
|
0.38.2
|
|
cranelift-codegen
|
crates.io |
≥ 0.84.0
< 0.85.2
|
0.85.2
|
References
Frequently Asked Questions
What is CVE-2022-31146?
Which Wasmtime versions are affected?
What version fixes CVE-2022-31146?
Is wasmtime affected?
Is cranelift-codegen affected?
What is the CVSS score of CVE-2022-31146?
What CWE is associated with CVE-2022-31146?
How can I check crates.io dependencies for CVE-2022-31146?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-5fhj-g3p3-pq9g",
"modified" : "2025-05-02T12:48:59Z",
"published" : "2022-07-20T22:47:13Z",
"aliases" : [ "CVE-2022-31146" ],
"summary" : "Wasmtime vulnerable to Use After Free with `externref`s",
"details" : "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.\n\nMitigations for this issue can be achieved by doing one of:\n\n* Disabling the reference types proposal by passing `false` to [`wasmtime::Config::wasm_reference_types`](https://docs.rs/wasmtime/0.38.0/wasmtime/struct.Config.html#method.wasm_reference_types).\n* Downgrading to Wasmtime 0.36.0 or prior.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "wasmtime"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.37.0"
}, {
"fixed" : "0.38.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "crates.io",
"name" : "cranelift-codegen"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.84.0"
}, {
"fixed" : "0.85.2"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-5fhj-g3p3-pq9g"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31146"
}, {
"type" : "WEB",
"url" : "https://github.com/bytecodealliance/wasmtime/commit/2ba4bce5cc719e5a74e571a534424614e62ecc41"
}, {
"type" : "WEB",
"url" : "https://github.com/WebAssembly/reference-types"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/bytecodealliance/wasmtime"
}, {
"type" : "WEB",
"url" : "https://rustsec.org/advisories/RUSTSEC-2022-0100.html"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-416" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2022-07-20T22:47:13Z",
"nvd_published_at" : "2022-07-21T04:15:00Z"
}
}