CVE-2023-41880: Off-by-one Error (CWE-193)
value: Wasmtime is a standalone runtime for WebAssembly. Wasmtime versions from 10.0.0 to versions 10.02, 11.0.2, and 12.0.1 contain a miscompilation of the WebAssembly `i64x2.shr_s` instruction on x86_64 platforms when the shift amount is a constant value that is larger than 32. Only x86_64 is affected so all other targets are not affected by this. The miscompilation results in the instruction producing an incorrect result, namely the low 32-bits of the second lane of the vector are derived from the low 32-bits of the second lane of the input vector instead of the high 32-bits. The primary impact of this issue is that any WebAssembly program using the `i64x2.shr_s` with a constant shift amount larger than 32 may produce an incorrect result.

This issue is not an escape from the WebAssembly sandbox. Execution of WebAssembly guest programs will still behave correctly with respect to memory sandboxing and isolation from the host. Wasmtime considers non-spec-compliant behavior as a security issue nonetheless.

This issue was discovered through fuzzing of Wasmtime's code generator Cranelift.

Wasmtime versions 10.0.2, 11.0.2, and 12.0.2 are all patched to no longer have this miscompilation. This issue only affects x86_64 hosts and the only workaround is to either scan for this pattern in wasm modules which is nontrivial or to disable the SIMD proposal for WebAssembly. Users prior to 10.0.0 are unaffected by this vulnerability.
CWE description: A product calculates or uses an incorrect maximum or minimum value that is 1 more, or 1 less, than the correct value.
CVSS v3 base score: 5.3
Published: 2023-09-15T20:15Z
Repository: https://github.com/bytecodealliance/wasmtime
Language: Other
Files changed: RELEASES.md, cranelift/codegen/src/isa/x64/lower.isle, cranelift/filetests/filetests/runtests/simd-sshr.clif
Commit date: 2023-09-14 13:27:58 -0500
Commit message: Merge pull request from GHSA-gw5p-q8mj-p7gh

* x64: Fix an off-by-one in in `i64x2.shr_s`

This commit fixes a mistake from #6372 where one of the immediates to a
`pshufd` instruction was off-by-one in terms of bits. This fixes the
behavior of the wasm `i64x2.shr_s` instruction with constant shift
amounts larger than 32.

* Update release notes
Diff: diff --git a/RELEASES.md b/RELEASES.md
index 2ada87ca8e..de377e1243 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -135,10 +135,23 @@ Unreleased.
 * Support for `union` types in the component model has been removed.
   [#6913](https://github.com/bytecodealliance/wasmtime/pull/6913)
 
 --------------------------------------------------------------------------------
 
+## 12.0.2
+
+Released 2023-09-14.
+
+### Fixed
+
+* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
+  constant input on x86\_64
+
+[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh
+
+--------------------------------------------------------------------------------
+
 ## 12.0.1
 
 Released 2023-08-24
 
 ### Fixed
@@ -209,10 +222,35 @@ Released 2023-08-21
 * Empty types are no longer allowed in the component model.
   [#6777](https://github.com/bytecodealliance/wasmtime/pull/6777)
 
 --------------------------------------------------------------------------------
 
+## 11.0.2
+
+Released 2023-09-14.
+
+### Fixed
+
+* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
+  constant input on x86\_64
+
+[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh
+
+--------------------------------------------------------------------------------
+
+## 11.0.1
+
+Released 2023-07-24.
+
+### Fixed
+
+* Update some minimum version requirements for Wasmtime's dependencies to fix
+  building Wasmtime with historical versions of these dependencies.
+  [#6758](https://github.com/bytecodealliance/wasmtime/pull/6758)
+
+--------------------------------------------------------------------------------
+
 ## 11.0.0
 
 Released 2023-07-20
 
 ### Changed
@@ -269,10 +307,23 @@ Released 2023-07-20
   `fcvt_from_sint`
   [#6565](https://github.com/bytecodealliance/wasmtime/pull/6565)
 
 --------------------------------------------------------------------------------
 
+## 10.0.2
+
+Released 2023-09-14.
+
+### Fixed
+
+* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
+  constant input on x86\_64
+
+[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh
+
+--------------------------------------------------------------------------------
+
 ## 10.0.1
 
 Released 2023-06-21
 
 ### Fixed
diff --git a/cranelift/codegen/src/isa/x64/lower.isle b/cranelift/codegen/src/isa/x64/lower.isle
index 76a97eb8e2..69e9f229f1 100644
--- a/cranelift/codegen/src/isa/x64/lower.isle
+++ b/cranelift/codegen/src/isa/x64/lower.isle
@@ -858,11 +858,11 @@
       (if-let $true (u64_lt 32 imm))
       (let (
           (high32 Xmm (x64_psrad vec (xmi_imm 31)))
           (high32 Xmm (x64_pshufd high32 0b11_10_11_01))
           (low32  Xmm (x64_psrad vec (xmi_imm (u32_sub imm 32))))
-          (low32  Xmm (x64_pshufd low32 0b11_10_10_01))
+          (low32  Xmm (x64_pshufd low32 0b11_10_11_01))
         )
         (x64_punpckldq low32 high32)))
 
 ;; A variable shift amount is slightly more complicated than the immediate
 ;; shift amounts from above. The `Gpr` argument is guaranteed to be <= 63 by
diff --git a/cranelift/filetests/filetests/runtests/simd-sshr.clif b/cranelift/filetests/filetests/runtests/simd-sshr.clif
index 29d3a8c51c..8f2781dfe6 100644
--- a/cranelift/filetests/filetests/runtests/simd-sshr.clif
+++ b/cranelift/filetests/filetests/runtests/simd-sshr.clif
@@ -119,6 +119,8 @@ block0(v0: i64x2):
 }
 ; run: %i64x2_sshr_const3([0x1 0xf]) == [0 0]
 ; run: %i64x2_sshr_const3([0x10000000000 0]) == [1 0]
 ; run: %i64x2_sshr_const3([-1 -1]) == [-1 -1]
 ; run: %i64x2_sshr_const3([0x8000000080000000 0x8000000080000000]) == [0xffffffffff800000 0xffffffffff800000]
+; run: %i64x2_sshr_const3([0x2424242424244424 0x8b1b1b1bffffff24]) == [0x242424 0xffffffffff8b1b1b]
+; run: %i64x2_sshr_const3([0x2424242424244424 0x1b1b1b1bffffff24]) == [0x242424 0x1b1b1b]
 

Vulnerable code:           (low32  Xmm (x64_pshufd low32 0b11_10_10_01))
Fixed code: ## 12.0.2

Released 2023-09-14.

### Fixed

* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
  constant input on x86\_64

[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh

--------------------------------------------------------------------------------

## 11.0.2

Released 2023-09-14.

### Fixed

* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
  constant input on x86\_64

[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh

--------------------------------------------------------------------------------

## 11.0.1

Released 2023-07-24.

### Fixed

* Update some minimum version requirements for Wasmtime's dependencies to fix
  building Wasmtime with historical versions of these dependencies.
  [#6758](https://github.com/bytecodealliance/wasmtime/pull/6758)

--------------------------------------------------------------------------------

## 10.0.2

Released 2023-09-14.

### Fixed

* [CVE-2023-41880] - Miscompilation of wasm `i64x2.shr_s` instruction with
  constant input on x86\_64

[CVE-2023-41880]: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-gw5p-q8mj-p7gh

--------------------------------------------------------------------------------

          (low32  Xmm (x64_pshufd low32 0b11_10_11_01))
; run: %i64x2_sshr_const3([0x2424242424244424 0x8b1b1b1bffffff24]) == [0x242424 0xffffffffff8b1b1b]
; run: %i64x2_sshr_const3([0x2424242424244424 0x1b1b1b1bffffff24]) == [0x242424 0x1b1b1b]