Get a Demo

Let's Patch It!

Book a short call with one our specialists, we'll walk you through how Endor Patches work, and ask you a few questions about your environment (like your primary programming languages and repository management). We'll also send you an email right after you fill out the form, feel free to reply with any questions you have in advance!

CVE

CVE-2023-26489

Guest-controlled out-of-bounds read/write on x86_64 in wasmtime
Back to all
CVE

CVE-2023-26489

Guest-controlled out-of-bounds read/write on x86_64 in wasmtime

wasmtime is a fast and secure runtime for WebAssembly. In affected versions wasmtime's code generator, Cranelift, has a bug on x8664 targets where address-mode computation mistakenly would calculate a 35-bit effective address instead of WebAssembly's defined 33-bit effective address. This bug means that, with default codegen settings, a wasm-controlled load/store operation could read/write addresses up to 35 bits away from the base of linear memory. Due to this bug, however, addresses up to 0xffffffff * 8 + 0x7ffffffc = 36507222004 = ~34G bytes away from the base of linear memory are possible from guest code. This means that the virtual memory 6G away from the base of linear memory up to ~34G away can be read/written by a malicious module. A guest module can, without the knowledge of the embedder, read/write memory in this region. The memory may belong to other WebAssembly instances when using the pooling allocator, for example. Affected embedders are recommended to analyze preexisting wasm modules to see if they're affected by the incorrect codegen rules and possibly correlate that with an anomalous number of traps during historical execution to locate possibly suspicious modules. The specific bug in Cranelift's x8664 backend is that a WebAssembly address which is left-shifted by a constant amount from 1 to 3 will get folded into x8664's addressing modes which perform shifts. For example (i32.load (i32.shl (local.get 0) (i32.const 3))) loads from the WebAssembly address $local0 << 3. When translated to Cranelift the $local0 << 3 computation, a 32-bit value, is zero-extended to a 64-bit value and then added to the base address of linear memory. Cranelift would generate an instruction of the form movl (%base, %local0, 8), %dst which calculates %base + %local0 << 3. The bug here, however, is that the address computation happens with 64-bit values, where the $local0 << 3 computation was supposed to be truncated to a a 32-bit value. This means that %local0, which can use up to 32-bits for an address, gets 3 extra bits of address space to be accessible via this movl instruction. The fix in Cranelift is to remove the erroneous lowering rules in the backend which handle these zero-extended expression. The above example is then translated to movl %local0, %temp; shl $3, %temp; movl (%base, %temp), %dst which correctly truncates the intermediate computation of %local0 << 3 to 32-bits inside the %temp register which is then added to the %base value. Wasmtime version 4.0.1, 5.0.1, and 6.0.1 have been released and have all been patched to no longer contain the erroneous lowering rules. While updating Wasmtime is recommended, there are a number of possible workarounds that embedders can employ to mitigate this issue if updating is not possible. Note that none of these workarounds are on-by-default and require explicit configuration: 1. The `Config::staticmemorymaximumsize(0) option can be used to force all accesses to linear memory to be explicitly bounds-checked. This will perform a bounds check separately from the address-mode computation which correctly calculates the effective address of a load/store. Note that this can have a large impact on the execution performance of WebAssembly modules. 2. The Config::staticmemoryguardsize(1 << 36)` option can be used to greatly increase the guard pages placed after linear memory. This will guarantee that memory accesses up-to-34G away are guaranteed to be semantically correct by reserving unmapped memory for the instance. Note that this reserves a very large amount of virtual memory per-instances and can greatly reduce the maximum number of concurrent instances being run. 3. If using a non-x8664 host is possible, then that will also work around this bug. This bug does not affect Wasmtime's or Cranelift's AArch64 backend, for example.

Package Versions Affected

Package Version
patch Availability
No items found.

Automatically patch vulnerabilities without upgrading

Fix Without Upgrading
Detect compatible fix
Apply safe remediation
Fix with a single pull request

CVSS Version

Severity
Base Score
CVSS Version
Score Vector
C
H
U
9.9
-
3.1
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
C
H
U
0
-
3.1
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
C
H
U
-

Related Resources

No items found.

References

https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.staticmemoryguardsize, https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.staticmemorymaximumsize, https://github.com/CVEProject/cvelistV5/tree/main/cves/2023/26xxx/CVE-2023-26489.json, https://github.com/bytecodealliance/wasmtime/commit/63fb30e4b4415455d47b3da5a19d79c12f4f2d1f, https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-ff4p-7xrq-q5r8, https://groups.google.com/a/bytecodealliance.org/g/sec-announce/c/Mov-ItrNJsQ, https://nvd.nist.gov/vuln/detail/CVE-2023-26489

Severity

9.9

CVSS Score
0
10

Basic Information

Ecosystem
Base CVSS
9.9
EPSS Probability
0.02286%
EPSS Percentile
0.84277%
Introduced Version
0
Fix Available
63fb30e4b4415455d47b3da5a19d79c12f4f2d1f

Fix Critical Vulnerabilities Instantly

Secure your app without upgrading.
Fix Without Upgrading