CVE-2022-31104: Wasmtime Miscompilation Of `i8x16.swizzle` And `select` Vulnerability
MODERATECVE-2022-31104 is a MODERATE (CVSS 4.8) miscompilation of `i8x16.swizzle` and `select` vulnerability (CWE-682: Incorrect Calculation) affecting Wasmtime libraries in the crates.io ecosystem. The issue involves miscompilation of `i8x16.swizzle` and `select` with v128 inputs. Remediation is available by upgrading affected packages to version 0.38.1, 0.85.1.
CVE-2022-31104 at a Glance
Security Impact
CVSS: 4.8
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:L/A:L).
How to Fix CVE-2022-31104
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.1
Upgrade cranelift-codegen to 0.85.1
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-31104, 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.1), 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
CVE-2022-31104 Affected Wasmtime Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
wasmtime
|
crates.io |
< 0.38.1
|
0.38.1
|
|
cranelift-codegen
|
crates.io |
< 0.85.1
|
0.85.1
|
References
Frequently Asked Questions
What is CVE-2022-31104?
Which Wasmtime versions are affected?
What version fixes CVE-2022-31104?
Is wasmtime affected?
Is cranelift-codegen affected?
What is the CVSS score of CVE-2022-31104?
What CWE is associated with CVE-2022-31104?
How can I check crates.io dependencies for CVE-2022-31104?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-jqwc-c49r-4w2x",
"modified" : "2025-05-02T12:49:13Z",
"published" : "2022-06-29T22:08:25Z",
"aliases" : [ "CVE-2022-31104" ],
"summary" : "Miscompilation of `i8x16.swizzle` and `select` with v128 inputs",
"details" : "### Impact\n\nWasmtime's implementation of the [SIMD proposal for WebAssembly](https://github.com/webassembly/simd) on x86_64 contained two distinct bugs in the instruction lowerings implemented in Cranelift. The aarch64 implementation of the simd proposal is not affected. The bugs were presented in the `i8x16.swizzle` and `select` WebAssembly instructions. The `select` instruction is only affected when the inputs are of `v128` type. The correspondingly affected Cranelift instructions were `swizzle` and `select`.\n\nThe `swizzle` instruction lowering in Cranelift erroneously overwrote the mask input register which could corrupt a constant value, for example. This means that future uses of the same constant may see a different value than the constant itself.\n\nThe `select` instruction lowering in Cranelift wasn't correctly implemented for vector types that are 128-bits wide. When the condition was 0 the wrong instruction was used to move the correct input to the output of the instruction meaning that only the low 32 bits were moved and the upper 96 bits of the result were left as whatever the register previously contained (instead of the input being moved from). The `select` instruction worked correctly if the condition was nonzero, however.\n\nThis bug in Wasmtime's implementation of these instructions on x86_64 represents an incorrect implementation of the specified semantics of these instructions according to the [WebAssembly specification](https://webassembly.github.io/spec/). The impact of this is benign for hosts running WebAssembly but represents possible vulnerabilities within the execution of a guest program. For example a WebAssembly program could take unintended branches or materialize incorrect values internally which runs the risk of exposing the program itself to other related vulnerabilities which can occur from miscompilations.\n\n### Patches\n\nWe have released Wasmtime 0.38.1 and cranelift-codegen (and other associated cranelift crates) 0.85.1 which contain the corrected implementations of these two instructions in Cranelift.\n\n### Workarounds\n\nIf upgrading is not an option for you at this time, you can avoid the vulnerability by [disabling the Wasm simd proposal](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_simd)\n\n```rust\nconfig.wasm_simd(false);\n```\n\nAdditionally the bug is only present on x86_64 hosts. Other aarch64 hosts are not affected. Note that s390x hosts don't yet implement the simd proposal and are not affected.\n\n### References\n\n* [The WebAssembly simd proposal](https://github.com/webassembly/simd)\n* [Original test case showing the erroneous behavior](https://github.com/bytecodealliance/wasmtime/issues/4315)\n* [Fix for the `swizzle` instruction](https://github.com/bytecodealliance/wasmtime/pull/4318)\n* [Fix for the `select` instruction](https://github.com/bytecodealliance/wasmtime/pull/4317)\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:L/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "wasmtime"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.38.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "crates.io",
"name" : "cranelift-codegen"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.85.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-jqwc-c49r-4w2x"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31104"
}, {
"type" : "WEB",
"url" : "https://github.com/bytecodealliance/wasmtime/pull/4317"
}, {
"type" : "WEB",
"url" : "https://github.com/bytecodealliance/wasmtime/pull/4318"
}, {
"type" : "WEB",
"url" : "https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_simd"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/bytecodealliance/wasmtime"
}, {
"type" : "WEB",
"url" : "https://github.com/webassembly/simd"
}, {
"type" : "WEB",
"url" : "https://rustsec.org/advisories/RUSTSEC-2022-0095.html"
}, {
"type" : "WEB",
"url" : "https://webassembly.github.io/spec"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-682" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2022-06-29T22:08:25Z",
"nvd_published_at" : "2022-06-28T00:15:00Z"
}
}