GitHub Security Advisory: GHSA-88xq-w8cq-xfg7
Package: wasmtime (RUST)
Severity: MODERATE (CVSS 5.1)
CWE: CWE-824: Access of Uninitialized Pointer
Vulnerable versions: = 0.34.0
Patched in: 0.34.1

Summary: Invalid drop of partially-initialized instances in the pooling instance allocator for modules with defined `externref` globals 

Details:
### Impact

There exists a bug in the pooling instance allocator in Wasmtime's runtime where a failure to instantiate an instance for a module that defines an `externref` global will result in an invalid drop of a `VMExternRef` via an uninitialized pointer.

As instance slots may be reused between consecutive instantiations, the value of the uninitialized pointer may be from a previous instantiation and therefore under the control of an attacker via a module's initial values for its globals. If the attacker can somehow determine an address under their control inside the mapped memory representing the instance pool, it is possible to trick the runtime to call `drop_in_place` on a trait object under the attacker's control and therefore cause remote code execution.

Exploiting the bug to cause remote code execution would be very difficult as attackers cannot determine the addresses of globals from code executing within the WebAssembly VM and the memory space for the instance pool cannot be statically determined. Operating system mitigations, such as [address space layout randomization](https://en.wikipedia.org/wiki/Address_space_layout_randomization), would additionally increase the difficulty for attackers to determine useful executable code to target with an exploit. It is also very unlikely that attackers will be able to directly influence the conditions that trigger the bug as described below.

When the conditions to trigger the bug are met, however, it is much easier to exploit this bug to cause a denial of service by crashing the host with an invalid memory read.

The following engine configuration (via [Config](https://docs.rs/wasmtime/0.34.0/wasmtime/struct.Config.html)) is required to be impacted by this bug:

* support for the reference types proposal must be enabled (this is the default for `Config`).
* a pooling allocation strategy must be configured via [Config::allocation_strategy](https://docs.rs/wasmtime/0.34.0/wasmtime/struct.Config.html#method.allocation_strategy), which is **not the default allocation strategy**.

A module must be instantiated with **all the following characteristics**:

* The module defines at least one table or memory.
* The module defines at least one `externref` global.

During instantiation, **one of the following** must occur to cause the instantiation to fail:

* a call to `mprotect` or `VirtualAlloc` fails (e.g. out-of-memory conditions).
* a resource limiter was configured in the associated `Store` (via [Store::limiter](https://docs.rs/wasmtime/0.34.0/wasmtime/struct.Store.html#method.limiter) or [Store::limiter_async](https://docs.rs/wasmtime/0.34.0/wasmtime/struct.Store.html#method.limiter_async)) and the limiter returns `false` from the initial call to `memory_growing` or `table_growing`. **Stores do not have a resource limiter set by default**.

This results in a partially-initialized instance being dropped and that attempts to drop the uninitialized `VMExternRef` representing the defined `externref`