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

CVE-2022-31104: Miscompilation of `i8x16.swizzle` and `select` with v128 inputs

June 29, 2022 (updated May 2, 2025)

Wasmtime’s implementation of the SIMD proposal for WebAssembly 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.

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

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

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

References

  • docs.rs/wasmtime/latest/wasmtime/struct.Config.html
  • github.com/advisories/GHSA-jqwc-c49r-4w2x
  • github.com/bytecodealliance/wasmtime
  • github.com/bytecodealliance/wasmtime/pull/4317
  • github.com/bytecodealliance/wasmtime/pull/4318
  • github.com/bytecodealliance/wasmtime/security/advisories/GHSA-jqwc-c49r-4w2x
  • github.com/webassembly/simd
  • nvd.nist.gov/vuln/detail/CVE-2022-31104
  • rustsec.org/advisories/RUSTSEC-2022-0095.html
  • webassembly.github.io/spec

Code Behaviors & Features

Detect and mitigate CVE-2022-31104 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.38.1

Fixed versions

  • 0.38.1

Solution

Upgrade to version 0.38.1 or above.

Impact 5.6 MEDIUM

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

Learn more about CVSS

Weakness

  • CWE-682: Incorrect Calculation

Source file

cargo/wasmtime/CVE-2022-31104.yml

Spotted a mistake? Edit the file on GitLab.

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

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