2.9low
Wasmtime race condition could lead to WebAssembly control-flow integrity and type safety violations
- Severity
- 2.9low CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.15% (higher than 4% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-7qmx-3fpx-r45mPYSEC-2024-311RUSTSEC-2024-0439
Description
Wasmtime is an open source runtime for WebAssembly. Under certain concurrent event orderings, a `wasmtime::Engine`'s internal type registry was susceptible to double-unregistration bugs due to a race condition, leading to panics and potentially type registry corruption. That registry corruption could, following an additional and particular sequence of concurrent events, lead to violations of WebAssembly's control-flow integrity (CFI) and type safety. Users that do not use `wasmtime::Engine` across multiple threads are not affected. Users that only create new modules across threads over time are additionally not affected. Reproducing this bug requires creating and dropping multiple type instances (such as `wasmtime::FuncType` or `wasmtime::ArrayType`) concurrently on multiple threads, where all types are associated with the same `wasmtime::Engine`. **Wasm guests cannot trigger this bug.** See the "References" section below for a list of Wasmtime types-related APIs that are affected. Wasmtime maintains an internal registry of types within a `wasmtime::Engine` and an engine is shareable across threads. Types can be created and referenced through creation of a `wasmtime::Module`, creation of `wasmtime::FuncType`, or a number of other APIs where the host creates a function (see "References" below). Each of these cases interacts with an engine to deduplicate type information and manage type indices that are used to implement type checks in WebAssembly's `call_indirect` function, for example. This bug is a race condition in this management where the internal type registry could be corrupted to trigger an assert or contain invalid state. Wasmtime's internal representation of a type has individual types (e.g. one-per-host-function) maintain a registration count of how many time it's been used. Types additionally have state within an engine behind a read-write lock such as lookup/deduplication information. The race here is a time-of-check versus time-of-use (TOCTOU) bug where one thread atomically decrements a type entry's registration count, observes zero registrations, and then acquires a lock in order to unregister that entry. However, between when this first thread observed the zero-registration count and when it acquires that lock, another thread could perform the following sequence of events: re-register another copy of the type, which deduplicates to that same entry, resurrecting it and incrementing its registration count; then drop the type and decrement its registration count; observe that the registration count is now zero; acquire the type registry lock; and finally unregister the type. Now, when the original thread finally acquires the lock and unregisters the entry, it is the second time this entry has been unregistered. This bug was originally introduced in Wasmtime 19's development of the WebAssembly GC proposal. This bug affects users who are not using the GC proposal, however, and affects Wasmtime in its default configuration even when the GC proposal is disabled. Wasmtime users using 19.0.0 and after are all affected by this issue. We have released the following Wasmtime versions, all of which have a fix for this bug: * 21.0.2 * 22.0.1 * 23.0.3 * 24.0.1 * 25.0.2. If your application creates and drops Wasmtime types on multiple threads concurrently, there are no known workarounds. Users are encouraged to upgrade to a patched release.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| bytecodealliance wasmtime | >= 19.0.0, < 21.0.2, >= 22.0.0, < 22.0.1, >= 23.0.0, < 23.0.3, >= 24.0.0, < 24.0.1, >= 25.0.0, < 25.0.2, 19.0.0, 19.0.1, 19.0.2 and 12 more | CVE List, NVD |
| wasmtime (crates.io) | from 19.0.0 before 21.0.2, from 22.0.0 before 22.0.1, from 23.0.0 before 23.0.3, from 24.0.0 before 24.0.1, from 25.0.0 before 25.0.2 | GitHub Advisory Database, RustSec Advisory Database |
| wasmtime (PyPI) | up to 19.0.0, up to 19.0.1, up to 19.0.2, up to 20.0.0, up to 20.0.1, up to 20.0.2, up to 21.0.0, up to 21.0.1 and 7 more | PyPA Advisory Database |
All scores
| GitHub_M | 2.9low CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:N/I:L/A:L |
| GitHub | 2.9low CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:N/I:L/A:L |
| GitHub | low CVSS:4.0 | CVSS:4.0/AV:L/AC:L/AT:P/PR:H/UI:A/VC:N/VI:L/VA:L/SC:N/SI:N/SA:N |
| RustSec Advisory Database | 2.9low CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:N/I:L/A:L |
| PyPA Advisory Database | 2.9low CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:N/I:L/A:L |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.
What each source says
CVE List
Wasmtime is an open source runtime for WebAssembly. Under certain concurrent event orderings, a `wasmtime::Engine`'s internal type registry was susceptible to double-unregistration bugs due to a race condition, leading to panics and potentially type registry corruption. That registry corruption could, following an additional and particular sequence of concurrent events, lead to violations of WebAssembly's control-flow integrity (CFI) and type safety. Users that do not use `wasmtime::Engine` across multiple threads are not affected. Users that only create new modules across threads over time are additionally not affected. Reproducing this bug requires creating and dropping multiple type instances (such as `wasmtime::FuncType` or `wasmtime::ArrayType`) concurrently on multiple threads, where all types are associated with the same `wasmtime::Engine`. **Wasm guests cannot trigger this bug.** See the "References" section below for a list of Wasmtime types-related APIs that are affected. Wasmtime maintains an internal registry of types within a `wasmtime::Engine` and an engine is shareable across threads. Types can be created and referenced through creation of a `wasmtime::Module`, creation of `wasmtime::FuncType`, or a number of other APIs where the host creates a function (see "References" below). Each of these cases interacts with an engine to deduplicate type information and manage type indices that are used to implement type checks in WebAssembly's `call_indirect` function, for example. This bug is a race condition in this management where the internal type registry could be corrupted to trigger an assert or contain invalid state. Wasmtime's internal representation of a type has individual types (e.g. one-per-host-function) maintain a registration count of how many time it's been used. Types additionally have state within an engine behind a read-write lock such as lookup/deduplication information. The race here is a time-of-check versus time-of-use (TOCTOU) bug where one thread atomically decrements a type entry's registration count, observes zero registrations, and then acquires a lock in order to unregister that entry. However, between when this first thread observed the zero-registration count and when it acquires that lock, another thread could perform the following sequence of events: re-register another copy of the type, which deduplicates to that same entry, resurrecting it and incrementing its registration count; then drop the type and decrement its registration count; observe that the registration count is now zero; acquire the type registry lock; and finally unregister the type. Now, when the original thread finally acquires the lock and unregisters the entry, it is the second time this entry has been unregistered. This bug was originally introduced in Wasmtime 19's development of the WebAssembly GC proposal. This bug affects users who are not using the GC proposal, however, and affects Wasmtime in its default configuration even when the GC proposal is disabled. Wasmtime users using 19.0.0 and after are all affected by this issue. We have released the following Wasmtime versions, all of which have a fix for this bug: * 21.0.2 * 22.0.1 * 23.0.3 * 24.0.1 * 25.0.2. If your application creates and drops Wasmtime types on multiple threads concurrently, there are no known workarounds. Users are encouraged to upgrade to a patched release.
GitHub Advisory Database
Impact
Under certain concurrent event orderings, a wasmtime::Engine's internal type registry was susceptible to double-unregistration bugs due to a race condition, leading to panics and potentially type registry corruption. That registry corruption could, following an additional and particular sequence of concurrent events, lead to violations of WebAssembly's control-flow integrity (CFI) and type safety. Users that do not use wasmtime::Engine across multiple threads are not affected. Users that only create new modules across threads over time are additionally not affected.
Reproducing this bug requires creating and dropping multiple type instances (such as wasmtime::FuncType or wasmtime::ArrayType) concurrently on multiple threads, where all types are associated with the same wasmtime::Engine. Wasm guests cannot trigger this bug. See the "References" section below for a list of Wasmtime types-related APIs that are affected.
Wasmtime maintains an internal registry of types within a wasmtime::Engine and an engine is shareable across threads. Types can be created and referenced through creation of a wasmtime::Module, creation of wasmtime::FuncType, or a number of other APIs where the host creates a function (see "References" below). Each of these cases interacts with an engine to deduplicate type information and manage type indices that are used to implement type checks in WebAssembly's call_indirect function, for example. This bug is a race condition in this management where the internal type registry could be corrupted to trigger an assert or contain invalid state.
Wasmtime's internal representation of a type has individual types (e.g. one-per-host-function) maintain a registration count of how many time it's been used. Types additionally have state within an engine behind a read-write lock such as lookup/deduplication information. The race here is a time-of-check versus time-of-use (TOCTOU) bug where one thread atomically decrements a type entry's registration count, observes zero registrations, and then acquires a lock in order to unregister that entry. However, between when this first thread observed the zero-registration count and when it acquires that lock, another thread could perform the following sequence of events: re-register another copy of the type, which deduplicates to that same entry, resurrecting it and incrementing its registration count; then drop the type and decrement its registration count; observe that the registration count is now zero; acquire the type registry lock; and finally unregister the type. Now, when the original thread finally acquires the lock and unregisters the entry, it is the second time this entry has been unregistered.
| Thread A | Thread B |
|---|---|
acquire(type registry lock) | |
decref(E) --> 0 | |
block_on(type registry lock) | |
register(E') == incref(E) --> 1 | |
release(type registry lock) | |
decref(E) --> 0 | |
acquire(type registry lock) | |
unregister(E) | |
release(type registry lock) | |
acquire(type registry lock) | |
unregister(E) |
This double-unregistration could then lead to a WebAssembly CFI violation under the following conditions: a new WebAssembly module X was loaded into the engine before the second, buggy unregistration occurs; X defined a function type F that was allocated in the same type registry slot where the original entry was allocated; the second, buggy unregistration incorrectly unregistered F; another new WebAssembly module Y was loaded into the engine; Y defined a function type G, different from F, but which is also allocated in the same type registry slot; a funcref of type G is created, either by the host or by Wasm; that funcref is passed to a WebAssembly instance of module X; that instance performs a call_indirect to that funcref; the call_indirect's dynamic type check, which preserves CFI, could incorrectly pass in this case, because F and G were assigned the same type registry slot. This would, ultimately, allow calling a function with too many, too few, or wrongly-typed arguments, violating CFI and type safety.
We were not able to reproduce this CFI violation in a vanilla Wasmtime build, although it remains theoretically possible. However, by modifying Wasmtime's source code to make losing the races described above more likely (by disabling certain assertions, inserting panic catches, and adding retry loops in a few places if we did not lose the race) we were able to incorrectly get a funcref to pass a type check that it should have failed, which would allow the CFI violation.
Patches
This bug was originally introduced in Wasmtime 19's development of the WebAssembly GC proposal. This bug affects users who are not using the GC proposal, however, and affects Wasmtime in its default configuration even when the GC proposal is disabled. Wasmtime users using 19.0.0 and after are all affected by this issue. We have released the following Wasmtime versions, all of which have a fix for this bug:
- 21.0.2
- 22.0.1
- 23.0.3
- 24.0.1
- 25.0.2
Workarounds
If your application creates and drops Wasmtime types on multiple threads concurrently, there are no known workarounds. Users are encouraged to upgrade to a patched release.
References
The following APIs create or drop types, and therefore are affected by this race condition if performed on multiple threads concurrently and are all associated with the same wasmtime::Engine:
wasmtime::FuncType::new- Also reachable from creation of
wasmtime::Func - Also reachable from
wasmtime::Linker::func_*
- Also reachable from creation of
wasmtime::ArrayType::newwasmtime::StructType::newwasmtime::Func::tywasmtime::Global::tywasmtime::Table::tywasmtime::Extern::tywasmtime::Export::tywasmtime::UnknownImportError::tywasmtime::ImportType::tywasmtime::ExportType::tywasmtime::Val::tywasmtime::Ref::tywasmtime::AnyRef::tywasmtime::EqRef::tywasmtime::ArrayRef::tywasmtime::StructRef::ty- Dropping a
wasmtime::FuncType - Dropping a
wasmtime::ArrayType - Dropping a
wasmtime::StructType - Dropping a
wasmtime::ExternType - Dropping a
wasmtime::GlobalType - Dropping a
wasmtime::TableType - Dropping a
wasmtime::ValType - Dropping a
wasmtime::RefType - Dropping a
wasmtime::HeapType - Dropping a
wasmtime::UnknownImportError - Dropping a
wasmtime::Linker
The change which introduced this bug was #7969
RustSec Advisory Database
This is an entry in the RustSec database for the Wasmtime security advisory located at https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-7qmx-3fpx-r45m. For more information see the GitHub-hosted security advisory.
NVD (es)
Wasmtime es un entorno de ejecución de código abierto para WebAssembly. Bajo ciertas órdenes de eventos concurrentes, el registro de tipos interno de `wasmtime::Engine` era susceptible a errores de doble anulación de registro debido a una condición de ejecución, lo que provocaba pánicos y, potencialmente, corrupción del registro de tipos. Esa corrupción del registro podría, después de una secuencia adicional y particular de eventos concurrentes, provocar violaciones de la integridad del flujo de control (CFI) y la seguridad de tipos de WebAssembly. Los usuarios que no usan `wasmtime::Engine` en varios subprocesos no se ven afectados. Los usuarios que solo crean nuevos módulos en varios subprocesos a lo largo del tiempo tampoco se ven afectados. Para reproducir este error es necesario crear y eliminar varias instancias de tipo (como `wasmtime::FuncType` o `wasmtime::ArrayType`) simultáneamente en varios subprocesos, donde todos los tipos están asociados con el mismo `wasmtime::Engine`. **Los invitados de Wasm no pueden activar este error.** Consulte la sección "Referencias" a continuación para obtener una lista de las API relacionadas con los tipos de Wasmtime que se ven afectadas. Wasmtime mantiene un registro interno de tipos dentro de un `wasmtime::Engine` y un motor se puede compartir entre subprocesos. Los tipos se pueden crear y referenciar mediante la creación de un `wasmtime::Module`, la creación de `wasmtime::FuncType` o una serie de otras API donde el host crea una función (consulte "Referencias" a continuación). Cada uno de estos casos interactúa con un motor para deduplicar la información de tipo y administrar los índices de tipo que se utilizan para implementar las comprobaciones de tipo en la función `call_indirect` de WebAssembly, por ejemplo. Este error es una condición de ejecución en esta gestión donde el registro de tipo interno podría estar dañado para activar una aserción o contener un estado no válido. La representación interna de Wasmtime de un tipo tiene tipos individuales (por ejemplo, uno por función de host) que mantienen un recuento de registro de cuántas veces se ha utilizado. Los tipos también tienen un estado dentro de un motor detrás de un bloqueo de lectura y escritura, como información de búsqueda o deduplicación. La ejecución aquí es un error de tiempo de verificación versus tiempo de uso (TOCTOU) donde un hilo disminuye atómicamente el recuento de registros de una entrada de tipo, observa cero registros y luego adquiere un bloqueo para anular el registro de esa entrada. Sin embargo, entre el momento en que este primer hilo observó el recuento de registros cero y el momento en que adquiere ese bloqueo, otro hilo podría realizar la siguiente secuencia de eventos: volver a registrar otra copia del tipo, que deduplica esa misma entrada, resucitándola e incrementando su recuento de registros; luego, descartar el tipo y disminuir su recuento de registros; observar que el recuento de registros ahora es cero; adquirir el bloqueo de registro de tipo; y finalmente anular el registro del tipo. Ahora, cuando el hilo original finalmente adquiere el bloqueo y anula el registro de la entrada, es la segunda vez que se anula el registro de esta entrada. Este error se introdujo originalmente en el desarrollo de la propuesta de recolección de elementos no utilizados de WebAssembly en Wasmtime 19. Sin embargo, este error afecta a los usuarios que no utilizan la propuesta de recolección de elementos no utilizados y afecta a Wasmtime en su configuración predeterminada incluso cuando la propuesta de recolección de elementos no utilizados está deshabilitada. Los usuarios de Wasmtime que utilizan la versión 19.0.0 y posteriores se ven afectados por este problema. Hemos publicado las siguientes versiones de Wasmtime, todas las cuales tienen una solución para este error: * 21.0.2 * 22.0.1 * 23.0.3 * 24.0.1 * 25.0.2. --- truncada ---
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2024-47813 changed 2024-10-09 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-7qmx-3fpx-r45m changed 2026-09-10 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2024-0439 changed 2026-10-12 | CC0-1.0 |
| NVD | CVE-2024-47813 changed 2026-06-17 | Public domain |
| PyPA Advisory Database | PYSEC-2024-311 changed 2026-05-21 | CC-BY-4.0 |