Out-of-bounds read/write and invalid free with `externref`s and GC safepoints in Wasmtime
Key facts
- Attack vector
- Local
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- High
- Impact type
- —
- Confidentiality · integrity · availability
- None · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · CNA. Fix status from CNA and GitHub.
Summary
Wasmtime is an open source runtime for WebAssembly & WASI. In Wasmtime from version 0.26.0 and before version 0.30.0 is affected by a memory unsoundness vulnerability. There was an invalid free and out-of-bounds read and write bug when running Wasm that uses `externref`s in Wasmtime. To trigger this bug, Wasmtime needs to be running Wasm that uses `externref`s, the host creates non-null `externrefs`, Wasmtime performs a garbage collection (GC), and there has to be a Wasm frame on the stack that is at a GC safepoint where there are no live references at this safepoint, and there is a safepoint with live references earlier in this frame's function. Under this scenario, Wasmtime would incorrectly use the GC stack map for the safepoint from earlier in the function instead of the empty safepoint. This would result in Wasmtime treating arbitrary stack slots as `externref`s that needed to be rooted for GC. At the *next* GC, it would be determined that nothing was referencing these bogus `externref`s (because nothing could ever reference them, because they are not really `externref`s) and then Wasmtime would deallocate them and run `<ExternRef as Drop>::drop` on them. This results in a free of memory that is not necessarily on the heap (and shouldn't be freed at this moment even if it was), as well as potential out-of-bounds reads and writes. Even though support for `externref`s (via the reference types proposal) is enabled by default, unless you are creating non-null `externref`s in your host code or explicitly triggering GCs, you cannot be affected by this bug. We have reason to believe that the effective impact of this bug is relatively small because usage of `externref` is currently quite rare. This bug has been patched and users should upgrade to Wasmtime version 0.30.0. If you cannot upgrade Wasmtime at this time, you can avoid this bug by disabling the reference types proposal by passing `false` to `wasmtime::Config::wasm_reference_types`.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| bytecodealliance | wasmtime | 0.26.0 – 0.29.0 | — | No fix listed | CNA |
| — | wasmtime (crates.io) | 0.26.0 to before 0.30.0 | 0.30.0 | Patch available | GHSA-4873-36h9-wv49 |
| — | wasmtime (PyPI) | 0.26.0 to before 0.30.0 | 0.30.0 | Patch available | GHSA-4873-36h9-wv49 |
- wasmtime Vendorbytecodealliance Affected 0.26.0 – 0.29.0 Fixed in — No fix listed CNA
- wasmtime (crates.io) Vendor— Affected 0.26.0 to before 0.30.0 Fixed in 0.30.0 Patch available GHSA-4873-36h9-wv49
- wasmtime (PyPI) Vendor— Affected 0.26.0 to before 0.30.0 Fixed in 0.30.0 Patch available GHSA-4873-36h9-wv49
CPE configurations NVD · 3
| CPE | Versions | Role | Vendor |
|---|---|---|---|
| cpe:2.3:a:bytecodealliance:wasmtime:*:*:*:*:*:rust:*:* | 0.26.0 to before 0.30.0 | Vulnerable | bytecodealliance |
| cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:* | 34 | Vulnerable | Fedoraproject |
| cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:* | 35 | Vulnerable | Fedoraproject |
- cpe:2.3:a:bytecodealliance:wasmtime:*:*:*:*:*:rust:*:* Versions 0.26.0 to before 0.30.0 Vulnerable ·bytecodealliance
- cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:* Versions 34 Vulnerable ·Fedoraproject
- cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:* Versions 35 Vulnerable ·Fedoraproject
Remediation
- Fix · GHSA-4873-36h9-wv49 wasmtime (crates.io) Fixed in 0.30.0 Advisory →
- Fix · GHSA-4873-36h9-wv49 wasmtime (PyPI) Fixed in 0.30.0 Advisory →
Fixed in the same release
Records fixed by the same vendor advisory or release, as the CNA lists them.
- Advisory ·
bytecodealliance wasmtime — FEDORA-2021-1805eacb48
3 records Highest priority Priority LOW 3 LOW
Other records, highest priority first
- TI-2021-16604 Wrong type for `Linker`-define functions when used across two `Engine`sPriority LOW 28
- TI-2021-16601 Use after free passing `externref`s to Wasm in WasmtimePriority LOW 28
- Advisory ·
bytecodealliance wasmtime — FEDORA-2021-68713440cb
3 records Highest priority Priority LOW 3 LOW
Other records, highest priority first
- TI-2021-16604 Wrong type for `Linker`-define functions when used across two `Engine`sPriority LOW 28
- TI-2021-16601 Use after free passing `externref`s to Wasm in WasmtimePriority LOW 28
Vendor assessments
Timeline
- 2026-10-02 Threatist record created from CVE-2021-39218
- 2026-10-03 Alias added: GHSA-4873-36h9-wv49
References
Advisory 5
Other 6
- https://github.com/bytecodealliance/wasmtime
- https://github.com/bytecodealliance/wasmtime-py/compare/0.29.0...0.30.0
- https://github.com/pypa/advisory-database/tree/main/vulns/wasmtime/PYSEC-2021-321.yaml
- https://lists.fedoraproject.org/archives/list/[email protected]/message/WAVBRYDDUIY2ZR3K3FO4BVYJKIMJ5TP7
- https://lists.fedoraproject.org/archives/list/[email protected]/message/Z2Z33FTXFQ6EOINVEQIP4DFBG53G5XIY
- https://rustsec.org/advisories/RUSTSEC-2021-0110.html
More bytecodealliance Wasmtime vulnerabilities
- TI-2026-21632 Wasmtime is vulnerable to panic when dropping a `[Typed]Func::call_async` future CVSS 4.0MEDIUM 6.9
- TI-2023-11636 Guest-controlled out-of-bounds read/write on x86_64 in wasmtime CVSS 3.1CRITICAL 10.0
- TI-2022-18765 Wasmtime vulnerable to data leakage between instances in the pooling allocator CVSS 3.1HIGH 8.6
- TI-2022-08604 Use after free in Wasmtime CVSS 3.1CRITICAL 9.8
- TI-2022-18766 wasmtime_trap_code C API function has out of bounds write vulnerability CVSS 3.1CRITICAL 9.8
- TI-2026-27209 Wasmtime with Winch compiler backend on aarch64 may allow a sandbox-escaping memory access CVSS 4.0CRITICAL 9.0
Sources
- CVE-2021-39218 · CVE Program
- CVE-2021-39218 · NVD
- FIRST EPSS
- GHSA-4873-36h9-wv49 · GitHub Advisory Database · CC BY 4.0
- CVE-2021-39218 · Red Hat security data · CC BY 4.0
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences