CVE-2022-31169: Wasmtime Cranelift Vulnerable To Miscompilation Of Vulnerability

MODERATE
Advisory Identifier: GHSA-7f6x-jwh5-m9r4
CVSS 5.9
CWE-682
Published
Advisory Summary

CVE-2022-31169 is a MODERATE (CVSS 5.9) cranelift vulnerable to miscompilation of vulnerability (CWE-682: Incorrect Calculation) affecting Wasmtime libraries in the crates.io ecosystem. The issue involves cranelift vulnerable to miscompilation of constant values in division on aarch64. Remediation is available by upgrading affected packages to version 0.38.2, 0.85.2.

CVE-2022-31169 at a Glance

CVE Identifier CVE-2022-31169
GHSA Identifier GHSA-7f6x-jwh5-m9r4
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-682: Incorrect Calculation
Affected Product Wasmtime
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2022-31169

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-31169, 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-682: Incorrect Calculation, where the product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management. 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

### Impact There was a bug in Wasmtime's code generator, Cranelift, for AArch64 targets where constant divisors could result in incorrect division results at runtime. The translation rules for constants did not take into account whether sign- or zero-extension should happen, which resulted in an incorrect value being placed into a register when a division was encountered. For example, a constant 32-bit unsigned divisor of `0xfffffffe` would be incorrectly sign-extended to 64-bits to `0xfffffffffffffffe`. Any kind of division of operands smaller than 64 bits is implemented with a 64-bit division instruction which would then result in an incorrect result because the divisor was larger than expected. The impact of this bug is that programs executing within the WebAssembly sandbox would not behave according to the WebAssembly specification. This means that it is hypothetically possible for execution within the sandbox to go awry and WebAssembly programs could produce unexpected results. This should not impact hosts executing WebAssembly, but does affect the correctness of guest programs. This bug was found with differential fuzzing of Wasmtime against other engines on the AArch64 platform. Fuzzing on AArch64 is not regularly performed at this time and the Wasmtime team is investigating how best to continuously fuzz AArch64 in the same manner as x86_64. ### Patches This bug has been patched and users should upgrade to Wasmtime version 0.38.2. ### Workarounds If upgrading is not an option at this time, direct users of Cranelift that control the exact Cranelift instructions being compiled can avoid the vulnerability by explicitly extending constant divisors to 64 bits using either the `sextend.i64` or the `uextend.i64` operation. Note, though, that this issue only affects the AArch64 targets. Other platforms are not affected. ### For more information If you have any questions or comments about this advisory: * Reach out to us on [the Bytecode Alliance Zulip chat](https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime) * Open an issue in [the bytecodealliance/wasmtime repository](https://github.com/bytecodealliance/wasmtime/)

CVE-2022-31169 Affected Wasmtime Versions

2 component(s)
Fixed Versions:
0.38.20.85.2
Product / Package Ecosystem Affected Versions Fixed Version
wasmtime
crates.io
< 0.38.2
0.38.2
cranelift-codegen
crates.io
< 0.85.2
0.85.2

References

Frequently Asked Questions

What is CVE-2022-31169?
CVE-2022-31169 is a security vulnerability in Wasmtime involving Cranelift vulnerable to miscompilation of constant values in division on AArch64 under CWE-682: Incorrect Calculation.
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-31169?
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-31169?
CVE-2022-31169 has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2022-31169?
CVE-2022-31169 is classified under CWE-682: Incorrect Calculation (The product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management.).
How can I check crates.io dependencies for CVE-2022-31169?
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-7f6x-jwh5-m9r4",
  "modified" : "2025-05-02T12:49:25Z",
  "published" : "2022-07-21T22:34:38Z",
  "aliases" : [ "CVE-2022-31169" ],
  "summary" : "Cranelift vulnerable to miscompilation of constant values in division on AArch64",
  "details" : "### Impact\n\nThere was a bug in Wasmtime's code generator, Cranelift, for AArch64 targets where constant divisors could result in incorrect division results at runtime. The translation rules for constants did not take into account whether sign- or zero-extension should happen, which resulted in an incorrect value being placed into a register when a division was encountered. For example, a constant 32-bit unsigned divisor of `0xfffffffe` would be incorrectly sign-extended to 64-bits to `0xfffffffffffffffe`. Any kind of division of operands smaller than 64 bits is implemented with a 64-bit division instruction which would then result in an incorrect result because the divisor was larger than expected.\n\nThe impact of this bug is that programs executing within the WebAssembly sandbox would not behave according to the WebAssembly specification. This means that it is hypothetically possible for execution within the sandbox to go awry and WebAssembly programs could produce unexpected results. This should not impact hosts executing WebAssembly, but does affect the correctness of guest programs.\n\nThis bug was found with differential fuzzing of Wasmtime against other engines on the AArch64 platform. Fuzzing on AArch64 is not regularly performed at this time and the Wasmtime team is investigating how best to continuously fuzz AArch64 in the same manner as x86_64.\n\n### Patches\n\nThis bug has been patched and users should upgrade to Wasmtime version 0.38.2.\n\n### Workarounds\n\nIf upgrading is not an option at this time, direct users of Cranelift that control the exact Cranelift instructions being compiled can avoid the vulnerability by explicitly extending constant divisors to 64 bits using either the `sextend.i64` or the `uextend.i64` operation.\n\nNote, though, that this issue only affects the AArch64 targets. Other platforms are not affected.\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n\n* Reach out to us on [the Bytecode Alliance Zulip chat](https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime)\n* Open an issue in [the bytecodealliance/wasmtime repository](https://github.com/bytecodealliance/wasmtime/)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "wasmtime"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.38.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "cranelift-codegen"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.85.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-7f6x-jwh5-m9r4"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31169"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/bytecodealliance/wasmtime/commit/2ba4bce5cc719e5a74e571a534424614e62ecc41"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/bytecodealliance/wasmtime"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2022-0101.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-682" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-07-21T22:34:38Z",
    "nvd_published_at" : "2022-07-22T04:15:00Z"
  }
}