Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS04OHhxLXc4Y3EteGZnN80sbg

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

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, 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) is required to be impacted by this bug:

A module must be instantiated with all the following characteristics:

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

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

We have reason to believe that the effective impact of this bug is relatively small because the usage of externref is still uncommon and without a resource limiter configured on the Store, which is not the default configuration, it is only possible to trigger the bug from an error returned by mprotect or VirtualAlloc.

Note that on Linux with the uffd feature enabled, it is only possible to trigger the bug from a resource limiter as the call to mprotect is skipped; if no resource limiter is used, then this configuration is not vulnerable.

Patches

The bug has been fixed in 0.34.1 and 0.33.1; users are encouraged to upgrade as soon as possible.

Workarounds

If it is not possible to upgrade to 0.34.1 or 0.33.1 of the wasmtime crate, it is recommend that support for the reference types proposal be disabled by passing false to Config::wasm_reference_types.

Doing so will prevent modules that use externref from being loaded entirely.

For more information

If you have any questions or comments about this advisory:

Permalink: https://github.com/advisories/GHSA-88xq-w8cq-xfg7
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS04OHhxLXc4Y3EteGZnN80sbg
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: about 2 years ago
Updated: about 1 year ago


CVSS Score: 5.1
CVSS vector: CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H

Identifiers: GHSA-88xq-w8cq-xfg7, CVE-2022-23636
References: Repository: https://github.com/bytecodealliance/wasmtime

Affected Packages

cargo:wasmtime
Dependent packages: 126
Dependent repositories: 2,459
Downloads: 6,282,542 total
Affected Version Ranges: < 0.33.1, = 0.34.0
Fixed in: 0.33.1, 0.34.1
All affected versions: 0.0.0, 0.3.0, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.15.0, 0.16.0, 0.17.0, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.26.1, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.32.1, 0.33.0, 0.34.0
All unaffected versions: 0.33.1, 0.34.1, 0.34.2, 0.35.0, 0.35.1, 0.35.2, 0.35.3, 0.36.0, 0.37.0, 0.38.0, 0.38.1, 0.38.2, 0.38.3, 0.39.0, 0.39.1, 0.40.0, 0.40.1, 1.0.0, 1.0.1, 1.0.2, 2.0.0, 2.0.1, 2.0.2, 3.0.0, 3.0.1, 4.0.0, 4.0.1, 5.0.0, 5.0.1, 6.0.0, 6.0.1, 6.0.2, 7.0.0, 7.0.1, 8.0.0, 8.0.1, 9.0.0, 9.0.1, 9.0.2, 9.0.3, 9.0.4, 10.0.0, 10.0.1, 10.0.2, 11.0.0, 11.0.1, 11.0.2, 12.0.0, 12.0.1, 12.0.2, 13.0.0, 13.0.1, 14.0.0, 14.0.1, 14.0.2, 14.0.3, 14.0.4, 15.0.0, 15.0.1, 16.0.0, 17.0.0, 17.0.1, 17.0.2, 18.0.0, 18.0.1, 18.0.2, 18.0.3