Skip to main content
Menu
Advisories

wasmtime-wasi: Unbounded host memory growth via empty writes to AsyncWriteStream

GHSA-5M8G-XHQ4-4H93Published Updated GitHub

Description

wasmtime-wasi provides the type wasmtime_wasi::p2::pipe::AsyncWriteStream, which takes ownership of the list<u8> argument passed to wasi:io/streams.output-stream.write, including zero-length ones. There is a write budget tracked to limit resource consumption in this buffer, but a zero-length write does not consume any of this budget. A guest which repeatedly calls write with an empty argument can consume a small amount of host memory per call, potentially leading to host memory exhaustion.

Details

A guest can trigger this when an output stream it can reach is an AsyncWriteStream. The primary use of this comes through AsyncStdoutStream; there are a few other paths to this including wasi_config_set_stdout_custom in the C API. Embedders may also be using the aforementioned types in their own hostcall implementations. Not all embeddings with wasip2 support include the vulnerable code; notably, the Wasmtime CLI itself does not use AsyncWriteStream.

The vulnerable code pushes an empty Bytes to the back of a VecDeque owned by AsyncWriteStream. Each empty Bytes consumes 32 bytes of memory on x86_64 and aarch64.

Impact

This vulnerability gives guests a fairly direct way to cause unbounded host heap usage, leading to memory exhaustion on the host (CWE-770) which could be used as part of a DoS attack. The vulnerable code may be used by many embedders supporting wasip2.

Affected versions

References

GitHub · bytecodealliance/wasmtime