CVE-2021-39219: Wrong type for `Linker`-define functions when used across two `Engine`s
Impact
As a Rust library the wasmtime crate clearly marks which functions are safe and which are unsafe, guaranteeing that if consumers never use unsafe then it should not be possible to have memory unsafety issues in their embeddings of Wasmtime. An issue was discovered in the safe API of Linker::func APIs. These APIs were previously not sound when one Engine was used to create the Linker and then a different Engine was used to create a Store and then the Linker was used to instantiate a module into that Store. Cross-Engine usage of functions is not supported in Wasmtime and this can result in type confusion of function pointers, resulting in being able to safely call a function with the wrong type.
Triggering this bug requires using at least two Engine values in an embedding and then additionally using two different values with a Linker (one at the creation time of the Linker and another when instantiating a module with the Linker).
It's expected that usage of more-than-one Engine in an embedding is relatively rare since an Engine is intended to be a globally shared resource, so the expectation is that the impact of this issue is relatively small.
The fix implemented is to change this behavior to panic!() in Rust instead of silently allowing it. Using different Engine instances with a Linker is a programmer bug that wasmtime catches at runtime.
Patches
This bug has been patched and users should upgrade to Wasmtime version 0.30.0.
Workarounds
If you cannot upgrade Wasmtime and are using more than one Engine in your embedding it's recommended to instead use only one Engine for the entire program if possible. An Engine is designed to be a globally shared resource that is suitable to have only one for the lifetime of an entire process. If using multiple Engines is required then code should be audited to ensure that Linker is only used with one Engine.
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/wasmtime repository
Other sources
Wasmtime is an open source runtime for WebAssembly & WASI. Wasmtime before version 0.30.0 is affected by a type confusion vulnerability. As a Rust library the wasmtime crate clearly marks which functions are safe and which are unsafe, guaranteeing that if consumers never use unsafe then it should not be possible to have memory unsafety issues in their embeddings of Wasmtime. An issue was discovered in the safe API of Linker::func APIs. These APIs were previously not sound when one Engine was used to create the Linker and then a different Engine was used to create a Store and then the Linker was used to instantiate a module into that Store. Cross-Engine usage of functions is not supported in Wasmtime and this can result in type confusion of function pointers, resulting in being able to safely call a function with the wrong type. Triggering this bug requires using at least two Engine values in an embedding and then additionally using two different values with a Linker (one at the creation time of the Linker and another when instantiating a module with the Linker). It's expected that usage of more-than-one Engine in an embedding is relatively rare since an Engine is intended to be a globally shared resource, so the expectation is that the impact of this issue is relatively small. The fix implemented is to change this behavior to panic!() in Rust instead of silently allowing it. Using different Engine instances with a Linker is a programmer bug that wasmtime catches at runtime. This bug has been patched and users should upgrade to Wasmtime version 0.30.0. If you cannot upgrade Wasmtime and are using more than one Engine in your embedding it's recommended to instead use only one Engine for the entire program if possible. An Engine is designed to be a globally shared resource that is suitable to have only one for the lifetime of an entire process. If using multiple Engines is required then code should be audited to ensure that Linker is only used with one Engine.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/wasmtimeto a version that resolves this vulnerability.Fixed in 0.30.0 - Upgrade
Upgrade
rust/wasmtimeto a version that resolves this vulnerability.Fixed in 0.30.0 - Upgrade
Upgrade
wasmtimeto a version that resolves this vulnerability.Fixed in 0.30.0 - Configuration
Ensure your embedding uses a single `Engine` for the lifetime of the process; audit code so `Linker::func_*` is only used with one `Engine` (avoid creating the `Linker` with one `Engine` and instantiating modules with a `Store` from a different `Engine`).
Wasmtime embedding (Linker::func_* safe APIs) cross-Engine usage of Linker = use only one Engine per process (and ensure Linker is used with that same Engine for Store/module instantiation) - Compensating control
If you cannot upgrade Wasmtime and must use multiple `Engine` values in your embedding, audit and ensure that `Linker` is only used with one `Engine` (avoid using two `Engine`s such that a `Linker` created with one is used with a `Store` from another).
Event History
Frequently Asked Questions
What is the vulnerability ID?
The vulnerability ID is CVE-2021-39219.
What is Wasmtime?
Wasmtime is an open source runtime for WebAssembly & WASI.
What version of Wasmtime is affected?
Version 0.30.0 and earlier versions of Wasmtime are affected.
What is the severity of CVE-2021-39219?
The severity of CVE-2021-39219 is medium, with a CVSS score of 6.3.
What is the impact of this vulnerability?
This vulnerability allows an attacker to exploit a type confusion vulnerability in Wasmtime.