CVE-2022-31146: Wasmtime Wasmtime Vulnerable To Use After Vulnerability

MODERATE
Advisory Identifier: GHSA-5fhj-g3p3-pq9g
CVSS 6.4
CWE-416
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2022-31146
GHSA Identifier GHSA-5fhj-g3p3-pq9g
Severity MODERATE
CVSS v3.1 Base Score 6.4
CWE Classification CWE-416: Use After Free
Affected Product Wasmtime
Package Ecosystem crates.io
Published Date
Last Updated

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

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability Low (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.

wasmtime fixed: 0.38.2
Upgrade wasmtime to 0.38.2
cranelift-codegen fixed: 0.85.2
Upgrade cranelift-codegen to 0.85.2
Verify Direct and Transitive Dependencies

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

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. Mitigations for this issue can be achieved by doing one of: * 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). * Downgrading to Wasmtime 0.36.0 or prior.

CVE-2022-31146 Affected Wasmtime Versions

2 component(s)
Fixed Versions:
0.38.20.85.2
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?
CVE-2022-31146 is a security vulnerability in Wasmtime involving Wasmtime vulnerable to Use After Free with `externref`s under CWE-416: Use After Free.
Which Wasmtime versions are affected?
Affected versions include releases prior to 0.38.2, 0.85.2 across affected packages: wasmtime, cranelift-codegen.
What version fixes CVE-2022-31146?
Upgrading to 0.38.2, 0.85.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is wasmtime affected?
Yes, wasmtime is affected in releases prior to 0.38.2. Upgrade your dependency to 0.38.2 or later.
Is cranelift-codegen affected?
Yes, cranelift-codegen is affected in releases prior to 0.85.2. Upgrade your dependency to 0.85.2 or later.
What is the CVSS score of CVE-2022-31146?
CVE-2022-31146 has a CVSS v3.1 base score of 6.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:L.
What CWE is associated with CVE-2022-31146?
CVE-2022-31146 is classified under CWE-416: Use After Free (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.).
How can I check crates.io dependencies for CVE-2022-31146?
Run the dependency tree command: 'inspect dependencies for wasmtime'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}