CVE-2021-32629
📋 TL;DR
A code generation bug in Cranelift 0.73's x64 backend incorrectly sign-extends instead of zero-extends certain i32 values, potentially allowing WebAssembly programs to access memory up to 2GiB before their heap start. This could lead to sandbox escape in affected WebAssembly runtimes. Systems using Cranelift-based WebAssembly runtimes like Wasmtime or Lucet with vulnerable configurations are affected.
💻 Affected Systems
- Cranelift
- Wasmtime
- Lucet
📦 What is this software?
Cranelift Codegen by Bytecodealliance
⚠️ Risk & Real-World Impact
Worst Case
Full sandbox escape allowing WebAssembly programs to read sensitive memory from the host process, potentially leading to information disclosure or further exploitation.
Likely Case
Limited memory disclosure depending on heap implementation and guard page configuration, potentially exposing adjacent memory regions.
If Mitigated
No impact if heap has proper bounds checks, guard pages, or no memory is mapped in the accessible range before the heap.
🎯 Exploit Status
Exploitation requires crafting specific WebAssembly code that triggers the register allocation bug under precise conditions.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Cranelift 0.74 or later
Vendor Advisory: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-hpqh-2wqx-7qp5
Restart Required: Yes
Instructions:
1. Update Cranelift to version 0.74 or later. 2. Update dependent projects like Wasmtime to versions with the fix. 3. Recompile affected WebAssembly applications. 4. Restart services using the updated runtime.
🔧 Temporary Workarounds
Disable new x64 backend
allRevert to using the old backend in versions before 0.73 where it was not default
Set build configuration to use old backend instead of new x64 backend
Implement heap guard regions
allEnsure 2GiB unmapped memory region before WebAssembly heap to prevent memory access
🧯 If You Can't Patch
- Isolate WebAssembly runtime execution in containers or VMs with minimal host access
- Implement strict Wasm code validation and only allow trusted, verified WebAssembly modules
🔍 How to Verify
Check if Vulnerable:
Check Cranelift version in dependencies: cranelift-codegen = 0.73, or check Wasmtime/Lucet versions using vulnerable Cranelift.
Check Version:
cargo tree | grep cranelift-codegen or check package manifest for version
Verify Fix Applied:
Verify cranelift-codegen version is 0.74 or higher, or dependent runtime versions include the fix commit.
📡 Detection & Monitoring
Log Indicators:
- Unexpected memory access errors in WebAssembly runtime logs
- Sandbox violation alerts
Network Indicators:
- Unusual outbound data from WebAssembly processing services
SIEM Query:
Search for process crashes or memory access violations in WebAssembly runtime processes
🔗 References
- https://crates.io/crates/cranelift-codegen
- https://github.com/bytecodealliance/wasmtime/commit/95559c01aaa7c061088a433040f31e8291fb09d0
- https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-hpqh-2wqx-7qp5
- https://www.fastly.com/security-advisories/memory-access-due-to-code-generation-flaw-in-cranelift-module
- https://crates.io/crates/cranelift-codegen
- https://github.com/bytecodealliance/wasmtime/commit/95559c01aaa7c061088a433040f31e8291fb09d0
- https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-hpqh-2wqx-7qp5
- https://www.fastly.com/security-advisories/memory-access-due-to-code-generation-flaw-in-cranelift-module