# CVE-2023-27477: wasmtime vulnerable to miscompilation of `i8x16.select` with the same inputs on x86_64

> An off-by-one error in Wasmtime's Cranelift backend causes incorrect results for specific SIMD instructions on x86_64 platforms.

- **Severity:** Low 3.1 (`CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Mar 2023
- **Updated:** 25 Feb 2025
- **Also known as:** AZL-25857, GHSA-xm67-587q-r2vw, RUSTSEC-2023-0093

## What is CVE-2023-27477?

CVE-2023-27477 is a low-severity vulnerability in bytecodealliance wasmtime, published on 8 Mar 2023. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

wasmtime is a fast and secure runtime for WebAssembly. Wasmtime's code generation backend, Cranelift, has a bug on x86_64 platforms for the WebAssembly `i8x16.select` instruction which will produce the wrong results when the same operand is provided to the instruction and some of the selected indices are greater than 16. There is an off-by-one error in the calculation of the mask to the `pshufb` instruction which causes incorrect results to be returned if lanes are selected from the second vector. This codegen bug has been fixed in Wasmtiem 6.0.1, 5.0.1, and 4.0.1. Users are recommended to upgrade to these updated versions. If upgrading is not an option for you at this time, you can avoid this miscompilation by disabling the Wasm simd proposal. Additionally the bug is only present on x86_64 hosts. Other platforms such as AArch64 and s390x are not affected.

Weakness: CWE-193 (Off-by-one Error)

## Which versions are affected by CVE-2023-27477?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `wasmtime` | crates.io | From 0.0.0-0 | 4.0.1, 5.0.1, 6.0.1 |
| `wasmtime` | crates.io | From 1.0.0 | 4.0.1 |
| `wasmtime` | crates.io | From 1.0.0 | 4.0.1 |
| `wasmtime` | crates.io | From 5.0.0 | 5.0.1 |
| `wasmtime` | crates.io | From 5.0.0 | 5.0.1 |
| `wasmtime` | crates.io | From 6.0.0 | 6.0.1 |
| `wasmtime` | crates.io | From 6.0.0 | 6.0.1 |
| `cranelift-codegen` | crates.io | From 0.88.0 | 0.91.1 |
| `cranelift-codegen` | crates.io | From 0.88.0 | 0.91.1 |
| `cranelift-codegen` | crates.io | From 0.92.0 | 0.92.1 |
| `cranelift-codegen` | crates.io | From 0.92.0 | 0.92.1 |
| `cranelift-codegen` | crates.io | From 0.93.0 | 0.93.1 |
| `cranelift-codegen` | crates.io | From 0.93.0 | 0.93.1 |

Products: Bytecodealliance Cranelift-Codegen, Bytecodealliance Wasmtime.

## How do I fix CVE-2023-27477?

Upgrade wasmtime to a fixed version for your release line: 4.0.1, 5.0.1 or 6.0.1.

## Is CVE-2023-27477 being exploited?

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

## Other vulnerabilities in bytecodealliance wasmtime

- [CVE-2023-26489](https://insights.sbomify.com/CVE-2023-26489/): Guest-controlled out-of-bounds read/write on x86_64 in wasmtime (critical 10.0)
- [CVE-2021-32629](https://insights.sbomify.com/CVE-2021-32629/): Memory access due to code generation flaw in Cranelift module (high 7.2)
- [CVE-2022-31146](https://insights.sbomify.com/CVE-2022-31146/): Use After Free in Wasmtime (medium 6.4)
- [CVE-2022-31169](https://insights.sbomify.com/CVE-2022-31169/): Cranelift vulnerable to miscompilation of constant values in division on AArch64 (medium 5.9)
- [CVE-2022-31104](https://insights.sbomify.com/CVE-2022-31104/): Miscompilation of `i8x16.swizzle` and `select` with v128 inputs in Wasmtime (medium 4.8)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-27477 and fix it if it is affected.

What it is: CVE-2023-27477 is a low-severity vulnerability in bytecodealliance wasmtime, published on 8 Mar 2023. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-27477 in the wild and no public exploit code.

Affected packages and fixed versions:
- wasmtime (crates.io): affected from 0.0.0-0; fixed in 4.0.1, 5.0.1, 6.0.1
- wasmtime (crates.io): affected from 1.0.0; fixed in 4.0.1
- wasmtime (crates.io): affected from 1.0.0; fixed in 4.0.1
- wasmtime (crates.io): affected from 5.0.0; fixed in 5.0.1
- wasmtime (crates.io): affected from 5.0.0; fixed in 5.0.1
- wasmtime (crates.io): affected from 6.0.0; fixed in 6.0.1
- wasmtime (crates.io): affected from 6.0.0; fixed in 6.0.1
- cranelift-codegen (crates.io): affected from 0.88.0; fixed in 0.91.1
- cranelift-codegen (crates.io): affected from 0.88.0; fixed in 0.91.1
- cranelift-codegen (crates.io): affected from 0.92.0; fixed in 0.92.1
- cranelift-codegen (crates.io): affected from 0.92.0; fixed in 0.92.1
- cranelift-codegen (crates.io): affected from 0.93.0; fixed in 0.93.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2023-27477/ (Markdown: https://insights.sbomify.com/CVE-2023-27477/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2023-27477
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2023-27477
- OSV: https://osv.dev/vulnerability/CVE-2023-27477

---
From sbomify Insights: https://insights.sbomify.com/CVE-2023-27477/
Summaries are generated and may contain mistakes; the official description above is the record.
