Summary
Workarounds
If you cannot upgrade Wasmtime yet, you can avoid the bug by disabling reference types support in Wasmtime by passing false to wasmtime::Config::wasm_reference_types.
References
For more information
If you have any questions or comments about this advisory:
- Reach out to us on the Bytecode Alliance Zulip chat
- Open an issue in the
bytecodealliance/wasmtimerepository
Impact
There was a use-after-free bug when passing externrefs from the host to guest Wasm content.
To trigger the bug, you have to explicitly pass multiple externrefs from the host to a Wasm instance at the same time, either by
- passing multiple
externrefs as arguments from host code to a Wasm function, - or returning multiple
externrefs to Wasm from a multi-value return function defined in the host.
If you do not have host code that matches one of these shapes, then you are not impacted.
If Wasmtime's VMExternRefActivationsTable became filled to capacity after passing the first externref in, then passing in the second externref could trigger a garbage collection. However the first externref is not rooted until we pass control to Wasm, and therefore could be reclaimed by the collector if nothing else was holding a reference to it or otherwise keeping it alive. Then, when control was passed to Wasm after the garbage collection, Wasm could use the first externref, which at this point has already been freed.
We have reason to believe that the effective impact of this bug is relatively small because usage of externref is currently quite rare.
Memory is accessed after it has been freed, leading to undefined behavior in native code. Typical impact: memory corruption, crash, or potential code execution.
CVE-2021-39216 has a CVSS score of 6.3 (Medium). The vector is requires local access, low privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (0.30.0); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Remediation advice
The bug has been fixed, and users should upgrade to Wasmtime 0.30.0.
Additionally, we have updated our primary externref fuzz target such that it better exercises these code paths and we can have greater confidence in their correctness going forward.
Frequently Asked Questions
- What is CVE-2021-39216? CVE-2021-39216 is a medium-severity use after free vulnerability in wasmtime (rust), affecting versions < 0.30.0. It is fixed in 0.30.0. Memory is accessed after it has been freed, leading to undefined behavior in native code.
- How severe is CVE-2021-39216? CVE-2021-39216 has a CVSS score of 6.3 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of wasmtime are affected by CVE-2021-39216? wasmtime (rust) versions < 0.30.0 is affected.
- Is there a fix for CVE-2021-39216? Yes. CVE-2021-39216 is fixed in 0.30.0. Upgrade to this version or later.
- Is CVE-2021-39216 exploitable, and should I be worried? Whether CVE-2021-39216 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2021-39216 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2021-39216?
- Upgrade
wasmtimeto 0.30.0 or later - Upgrade
wasmtimeto 0.30.0 or later
- Upgrade