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

Medium 4.8 Published Updated

Miscompilation in Wasmtime's SIMD implementation on x86_64 can cause incorrect values or unintended branches in guest programs, potentially leading to secondary vulnerabilities.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2022-31104?

CVE-2022-31104 is a medium-severity vulnerability in bytecodealliance wasmtime, published on 27 Jun 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

Wasmtime is a standalone runtime for WebAssembly. In affected versions 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. We 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. If upgrading is not an option for you at this time, you can avoid the vulnerability by disabling the Wasm simd proposal. Additionally 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.

Weakness: CWE-682

Which versions are affected by CVE-2022-31104?

5 open source packages ship an affected version, including wasmtime and cranelift-codegen. It affects 2 products.

PackageAffectedFixed in
wasmtime crates.ioAll versions0.38.1
wasmtime crates.ioAll versions0.38.1
wasmtime crates.ioFrom 0.0.0-00.38.1
cranelift-codegen crates.ioAll versions0.85.1
cranelift-codegen crates.ioAll versions0.85.1

Products include Bytecodealliance Cranelift-Codegen, Bytecodealliance Wasmtime.

How do I fix CVE-2022-31104?

Upgrade wasmtime to 0.38.1 or later.

Is CVE-2022-31104 being exploited?

There is no known exploitation of CVE-2022-31104 in the wild and no public exploit code.

Sources

Also known as GHSA-jqwc-c49r-4w2x, RUSTSEC-2022-0095.

Is CVE-2022-31104 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free