Wasmtime's implementation of managing per-instance state contains LLVM-level undefined behavior, which can cause runtime-level issues when compiled with LLVM 16. This undefined behavior is due to the use of `unsafe` code to maintain the runtime state for an instance, which involves a Rust-defined structure called `Instance` with a trailing `VMContext` structure. The code has methods that take `&self` as an argument but modify data in the `VMContext` part of the allocation, which is typically not allowed in Rust.
The estimated number of potentially affected devices worldwide is not available.
There is no information about real-world incidents where this issue was exploited.
Technical details about exploitation include:
- The `VMContext` structure has a runtime-defined layout that is unique per-module.
- The code doing this has methods which take `&self` as an argument but modify data in the `VMContext` part of the allocation.
- This means that pointers derived from `&self` are mutated, which is typically not allowed, except in the presence of `UnsafeCell`, in Rust.
- When compiled to LLVM these functions have `noalias readonly` parameters which means it's undefined behavior to write through the pointers.