// For flags

CVE-2021-32629

Memory access due to code generation flaw in Cranelift module

Severity Score

8.8
*CVSS v3.1

Exploit Likelihood

*EPSS

Affected Versions

*CPE

Public Exploits

1
*Multiple Sources

Exploited in Wild

-
*KEV

Decision

-
*SSVC
Descriptions

Cranelift is an open-source code generator maintained by Bytecode Alliance. It translates a target-independent intermediate representation into executable machine code. There is a bug in 0.73 of the Cranelift x64 backend that can create a scenario that could result in a potential sandbox escape in a Wasm program. This bug was introduced in the new backend on 2020-09-08 and first included in a release on 2020-09-30, but the new backend was not the default prior to 0.73. The recently-released version 0.73 with default settings, and prior versions with an explicit build flag to select the new backend, are vulnerable. The bug in question performs a sign-extend instead of a zero-extend on a value loaded from the stack, under a specific set of circumstances. If those circumstances occur, the bug could allow access to memory addresses upto 2GiB before the start of the Wasm program heap. If the heap bound is larger than 2GiB, then it would be possible to read memory from a computable range dependent on the size of the heaps bound. The impact of this bug is highly dependent on heap implementation, specifically: * if the heap has bounds checks, and * does not rely exclusively on guard pages, and * the heap bound is 2GiB or smaller * then this bug cannot be used to reach memory from another Wasm program heap. The impact of the vulnerability is mitigated if there is no memory mapped in the range accessible using this bug, for example, if there is a 2 GiB guard region before the Wasm program heap. The bug in question performs a sign-extend instead of a zero-extend on a value loaded from the stack, when the register allocator reloads a spilled integer value narrower than 64 bits. This interacts poorly with another optimization: the instruction selector elides a 32-to-64-bit zero-extend operator when we know that an instruction producing a 32-bit value actually zeros the upper 32 bits of its destination register. Hence, we rely on these zeroed bits, but the type of the value is still i32, and the spill/reload reconstitutes those bits as the sign extension of the i32’s MSB. The issue would thus occur when: * An i32 value in a Wasm program is greater than or equal to 0x8000_0000; * The value is spilled and reloaded by the register allocator due to high register pressure in the program between the value’s definition and its use; * The value is produced by an instruction that we know to be “special” in that it zeroes the upper 32 bits of its destination: add, sub, mul, and, or; * The value is then zero-extended to 64 bits in the Wasm program; * The resulting 64-bit value is used. Under these circumstances there is a potential sandbox escape when the i32 value is a pointer. The usual code emitted for heap accesses zero-extends the Wasm heap address, adds it to a 64-bit heap base, and accesses the resulting address. If the zero-extend becomes a sign-extend, the program could reach backward and access memory up to 2GiB before the start of its heap. In addition to assessing the nature of the code generation bug in Cranelift, we have also determined that under specific circumstances, both Lucet and Wasmtime using this version of Cranelift may be exploitable. See referenced GitHub Advisory for more details.

Cranelift es un generador de código abierto mantenido por Bytecode Alliance. Traduce una representación intermedia independiente del objetivo en código máquina ejecutable. Hay un error en la versión 0.73 del backend de Cranelift x64 que puede crear un escenario que podría dar lugar a una potencial fuga de la caja de arena en un programa Wasm. Este error se introdujo en el nuevo backend el 2020-09-08 y se incluyó por primera vez en una versión el 2020-09-30, pero el nuevo backend no era el predeterminado antes de 0.73. La versión 0.73 recientemente lanzada con la configuración por defecto, y las versiones anteriores con una bandera de construcción explícita para seleccionar el nuevo backend, son vulnerables. El fallo en cuestión realiza un signo-extensión en lugar de un cero-extensión en un valor cargado desde la pila, bajo un conjunto específico de circunstancias. Si se dan esas circunstancias, el fallo podría permitir el acceso a direcciones de memoria de hasta 2GiB antes del inicio de la pila del programa Wasm. Si el límite del heap es mayor que 2GiB, entonces sería posible leer memoria de un rango computable dependiente del tamaño del límite del heaps. El impacto de este error depende en gran medida de la implementación de la pila, específicamente: * si el heap tiene comprobaciones de límites, y * no depende exclusivamente de páginas de guardia, y * el límite del heap es de 2GiB o menor * entonces este fallo no puede ser usado para alcanzar memoria desde otro heap del programa Wasm. El impacto de la vulnerabilidad se mitiga si no hay memoria mapeada en el rango accesible usando este bug, por ejemplo, si hay una región de guardia de 2 GiB antes del heap del programa Wasm. El fallo en cuestión realiza un signo-extensión en lugar de un cero-extensión en un valor cargado desde la pila, cuando el asignador de registros recarga un valor entero derramado más estrecho que 64 bits. Esto interactúa mal con otra optimización: el selector de instrucciones elude un operador de extensión a cero de 32 a 64 bits cuando sabemos que una instrucción que produce un valor de 32 bits realmente pone a cero los 32 bits superiores de su registro de destino. Por lo tanto, nos basamos en estos bits a cero, pero el tipo del valor sigue siendo i32, y el derrame/recarga reconstituye esos bits como la extensión del signo del MSB de i32. Por lo tanto, el problema ocurriría cuando: * Un valor i32 en un programa Wasm es mayor o igual a 0x8000_0000; * El valor es derramado y recargado por el asignador de registros debido a la alta presión de registros en el programa entre la definición del valor y su uso; * El valor es producido por una instrucción que sabemos que es "especial" en el sentido de que pone a cero los 32 bits superiores de su destino: add, sub, mul, and, or; * El valor es entonces extendido a cero a 64 bits en el programa Wasm; * El valor de 64 bits resultante es utilizado. Bajo estas circunstancias hay un potencial escape de la caja de arena cuando el valor i32 es un puntero. El código habitual emitido para los accesos al heap extiende a cero la dirección del heap de Wasm, la añade a una base del heap de 64 bits, y accede a la dirección resultante. Si el zero-extend se convierte en un sign-extend, el programa podría llegar hacia atrás y acceder a la memoria hasta 2GiB antes del inicio de su heap. Además de evaluar la naturaleza del fallo de generación de código en Cranelift, también hemos determinado que, en circunstancias específicas, tanto Lucet como Wasmtime que utilizan esta versión de Cranelift pueden ser explotables. Consulte el aviso de GitHub mencionado para obtener más detalles

*Credits: N/A
CVSS Scores
Attack Vector
Local
Attack Complexity
Low
Privileges Required
Low
User Interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High
Attack Vector
Local
Attack Complexity
High
Privileges Required
Low
User Interaction
Required
Scope
Changed
Confidentiality
High
Integrity
High
Availability
None
Attack Vector
Local
Attack Complexity
Low
Authentication
None
Confidentiality
Partial
Integrity
Partial
Availability
Partial
* Common Vulnerability Scoring System
SSVC
  • Decision:-
Exploitation
-
Automatable
-
Tech. Impact
-
* Organization's Worst-case Scenario
Timeline
  • 2021-05-12 CVE Reserved
  • 2021-05-24 CVE Published
  • 2023-08-16 EPSS Updated
  • 2024-08-03 CVE Updated
  • 2024-08-03 First Exploit
  • ---------- Exploited in Wild
  • ---------- KEV Due Date
CWE
  • CWE-125: Out-of-bounds Read
  • CWE-681: Incorrect Conversion between Numeric Types
  • CWE-788: Access of Memory Location After End of Buffer
CAPEC
Affected Vendors, Products, and Versions
Vendor Product Version Other Status
Vendor Product Version Other Status <-- --> Vendor Product Version Other Status
Bytecodealliance
Search vendor "Bytecodealliance"
Cranelift-codegen
Search vendor "Bytecodealliance" for product "Cranelift-codegen"
< 0.73.1
Search vendor "Bytecodealliance" for product "Cranelift-codegen" and version " < 0.73.1"
rust
Affected