VYPR
Moderate severityNVD Advisory· Published Nov 10, 2022· Updated Apr 23, 2025

Wasmtime vulnerable to out of bounds read/write with zero-memory-pages configuration

CVE-2022-39392

Description

Wasmtime is a standalone runtime for WebAssembly. Prior to version 2.0.2, there is a bug in Wasmtime's implementation of its pooling instance allocator when the allocator is configured to give WebAssembly instances a maximum of zero pages of memory. In this configuration, the virtual memory mapping for WebAssembly memories did not meet the compiler-required configuration requirements for safely executing WebAssembly modules. Wasmtime's default settings require virtual memory page faults to indicate that wasm reads/writes are out-of-bounds, but the pooling allocator's configuration would not create an appropriate virtual memory mapping for this meaning out of bounds reads/writes can successfully read/write memory unrelated to the wasm sandbox within range of the base address of the memory mapping created by the pooling allocator. This bug is not applicable with the default settings of the wasmtime crate. This bug can only be triggered by setting InstanceLimits::memory_pages to zero. This is expected to be a very rare configuration since this means that wasm modules cannot allocate any pages of linear memory. All wasm modules produced by all current toolchains are highly likely to use linear memory, so it's expected to be unlikely that this configuration is set to zero by any production embedding of Wasmtime. This bug has been patched and users should upgrade to Wasmtime 2.0.2. This bug can be worked around by increasing the memory_pages allotment when configuring the pooling allocator to a value greater than zero. If an embedding wishes to still prevent memory from actually being used then the Store::limiter method can be used to dynamically disallow growth of memory beyond 0 bytes large. Note that the default memory_pages value is greater than zero.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
wasmtimecrates.io
>= 2.0.0, < 2.0.22.0.2
wasmtimecrates.io
< 1.0.21.0.2

Affected products

1

Patches

1
e60c3742904c

Merge pull request from GHSA-44mr-8vmm-wjhg

https://github.com/bytecodealliance/wasmtimeAlex CrichtonNov 10, 2022via ghsa
2 files changed · +64 11
  • crates/runtime/src/instance/allocator/pooling.rs+23 11 modified
    @@ -19,8 +19,8 @@ use std::convert::TryFrom;
     use std::mem;
     use std::sync::Mutex;
     use wasmtime_environ::{
    -    DefinedMemoryIndex, DefinedTableIndex, HostPtr, Module, PrimaryMap, Tunables, VMOffsets,
    -    WASM_PAGE_SIZE,
    +    DefinedMemoryIndex, DefinedTableIndex, HostPtr, MemoryStyle, Module, PrimaryMap, Tunables,
    +    VMOffsets, WASM_PAGE_SIZE,
     };
     
     mod index_allocator;
    @@ -386,6 +386,20 @@ impl InstancePool {
                     .defined_memory_index(memory_index)
                     .expect("should be a defined memory since we skipped imported ones");
     
    +            match plan.style {
    +                MemoryStyle::Static { bound } => {
    +                    let bound = bound * u64::from(WASM_PAGE_SIZE);
    +                    if bound < self.memories.static_memory_bound {
    +                        return Err(InstantiationError::Resource(anyhow!(
    +                            "static bound of {bound:x} bytes incompatible with \
    +                             reservation of {:x} bytes",
    +                            self.memories.static_memory_bound,
    +                        )));
    +                    }
    +                }
    +                MemoryStyle::Dynamic { .. } => {}
    +            }
    +
                 let memory = unsafe {
                     std::slice::from_raw_parts_mut(
                         self.memories.get_base(instance_index, defined_index),
    @@ -658,6 +672,7 @@ struct MemoryPool {
         initial_memory_offset: usize,
         max_memories: usize,
         max_instances: usize,
    +    static_memory_bound: u64,
     }
     
     impl MemoryPool {
    @@ -679,15 +694,11 @@ impl MemoryPool {
                 );
             }
     
    -        let memory_size = if instance_limits.memory_pages > 0 {
    -            usize::try_from(
    -                u64::from(tunables.static_memory_bound) * u64::from(WASM_PAGE_SIZE)
    -                    + tunables.static_memory_offset_guard_size,
    -            )
    -            .map_err(|_| anyhow!("memory reservation size exceeds addressable memory"))?
    -        } else {
    -            0
    -        };
    +        let static_memory_bound =
    +            u64::from(tunables.static_memory_bound) * u64::from(WASM_PAGE_SIZE);
    +        let memory_size =
    +            usize::try_from(static_memory_bound + tunables.static_memory_offset_guard_size)
    +                .map_err(|_| anyhow!("memory reservation size exceeds addressable memory"))?;
     
             assert!(
                 memory_size % crate::page_size() == 0,
    @@ -745,6 +756,7 @@ impl MemoryPool {
                 max_memories,
                 max_instances,
                 max_memory_size: (instance_limits.memory_pages as usize) * (WASM_PAGE_SIZE as usize),
    +            static_memory_bound,
             };
     
             Ok(pool)
    
  • tests/all/pooling_allocator.rs+41 0 modified
    @@ -721,3 +721,44 @@ configured maximum of 16 bytes; breakdown of allocation requirement:
     
         Ok(())
     }
    +
    +#[test]
    +fn zero_memory_pages_disallows_oob() -> Result<()> {
    +    let mut config = Config::new();
    +    config.allocation_strategy(InstanceAllocationStrategy::Pooling {
    +        strategy: PoolingAllocationStrategy::NextAvailable,
    +        instance_limits: InstanceLimits {
    +            count: 1,
    +            memory_pages: 0,
    +            ..Default::default()
    +        },
    +    });
    +
    +    let engine = Engine::new(&config)?;
    +    let module = Module::new(
    +        &engine,
    +        r#"
    +            (module
    +                (memory 0)
    +
    +                (func (export "load") (param i32) (result i32)
    +                    local.get 0
    +                    i32.load)
    +
    +                (func (export "store") (param i32 )
    +                    local.get 0
    +                    local.get 0
    +                    i32.store)
    +            )
    +        "#,
    +    )?;
    +    let mut store = Store::new(&engine, ());
    +    let instance = Instance::new(&mut store, &module, &[])?;
    +    let load32 = instance.get_typed_func::<i32, i32, _>(&mut store, "load")?;
    +    let store32 = instance.get_typed_func::<i32, (), _>(&mut store, "store")?;
    +    for i in 0..31 {
    +        assert!(load32.call(&mut store, 1 << i).is_err());
    +        assert!(store32.call(&mut store, 1 << i).is_err());
    +    }
    +    Ok(())
    +}
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

7

News mentions

0

No linked articles in our index yet.