Linux 7.3 PAGEMAP_SCAN leaves pooled linear memory uncleared between Wasmtime instances
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 18/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- linux, rust, wasm
- Lĩnh vực
- operating-systems, security
Hướng nghiên cứu
Start in crates/wasmtime/src/runtime/vm/sys/unix/pagemap.rs: reset_with_pagemap() around lines 318-321 asks for WRITTEN, and PageMap::new() only validates an empty range, so Enabled::Auto can pick this path too. Build the PoC crate and run cargo run --release -- no then -- yes on Linux 7.3 to reproduce the stale 0x5a, then trace how the pooling allocator calls the reset path. Done means the scan-enabled probe reports 0x00, by registering ranges for userfaultfd write-protect or correctly falling back to reset_manually/decommit for unmatched pages.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
On Linux 7.3.4, Wasmtime 50.0.2 leaves a previous instance's contents in a reused pooled linear-memory slot. The PoC observes this through Wasmtime's host memory API. This requires an application to opt into PoolingAllocationConfig::pagemap_scan(Enabled::Yes) (or Auto) and set linear_memory_keep_resident above zero. A fresh instance of the test module should start with zeroed memory, yet the one-slot probe reads the previous instance's value at byte zero. In the recorded 50.0.2 runs, scan enabled reports that stale value three times out of three; scan disabled reports zero three times out of three. The pooling configuration defaults to scan disabled and both keep-resident values set to zero.
Details
On Linux 7.3, reporting PAGE_IS_WRITTEN requires explicit userfaultfd write tracking: a program must register the memory range with UFFDIO_REGISTER_MODE_WP and write-protect its pages before subsequent writes receive that flag. See the Linux PAGEMAP_SCAN documentation, userfaultfd guide, and kernel change. Wasmtime does not register its pooled memory for this tracking mode.
In Wasmtime 50.0.2, crates/wasmtime/src/runtime/vm/sys/unix/pagemap.rs, reset_with_pagemap() asks for pages matching WRITTEN while excluding zero and file-backed pages:
.category_inverted(Categories::PFNZERO | Categories::FILE)
.category_mask(Categories::WRITTEN | Categories::PFNZERO | Categories::FILE)
Under the changed kernel semantics, this written anonymous page cannot match the WRITTEN filter. On a successful scan that reaches the end without reporting it, the function returns without calling reset_manually or decommit for that page. The next instance receives the slot with its old contents. The probe directly observes that stale byte; it does not trace the ioctl's returned regions, so the omitted-region explanation is inferred from the kernel and Wasmtime source. PageMap::new() only checks that the ioctl accepts an empty range; that check does not test the semantics of WRITTEN, so Enabled::Auto can also select this path.
The earliest released Wasmtime version I verified with this scan logic is 37.0.0; 36.0.20 does not contain the scanner. I checked available release tags through 50.0.2 for the WRITTEN requirement. The 50.0.2 scan filter and main at 3ce2209, inspected November 19, still require WRITTEN. I ran the reproducer against 50.0.2.
Proof of concept
Run this standalone crate on Linux 7.3 with the changed PAGE_IS_WRITTEN semantics. The recorded run used Ubuntu 7.3.4-070304-generic on ARM64 with 4096-byte pages; x86-64 was not tested. The test creates one memory slot, writes 0x5a in a first Store, drops that store, then reads byte zero from a second Store. 0x5a is an arbitrary test marker; the issue is that previous contents remain in the reused memory instead of its required initial contents. This test exercises byte zero with that marker.
# Cargo.toml
[package]
name = "pagemap-linux73-repro"
version = "0.1.0"
edition = "2024"
[workspace]
[dependencies]
wasmtime = { version = "=50.0.2", default-features = false, features = ["cranelift", "pooling-allocator", "wat"] }
// src/main.rs
use std::error::Error;
use std::process::ExitCode;
use wasmtime::{Config, Enabled, Engine, Instance, Module, PoolingAllocationConfig, Store};
fn run(scan: Enabled) -> Result<u8, Box<dyn Error>> {
let mut pool = PoolingAllocationConfig::new();
pool.total_memories(1)
.total_core_instances(1)
.total_tables(1)
.linear_memory_keep_resident(65_536)
.pagemap_scan(scan);
let mut config = Config::new();
config.allocation_strategy(pool);
let engine = Engine::new(&config)?;
let module = Module::new(&engine, r#"(module (memory (export "m") 1))"#)?;
{
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
let memory = instance.get_memory(&mut store, "m").unwrap();
memory.data_mut(&mut store)[0] = 0x5a;
}
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
let memory = instance.get_memory(&mut store, "m").unwrap();
Ok(memory.data(&store)[0])
}
fn main() -> Result<ExitCode, Box<dyn Error>> {
let mode = std::env::args().nth(1).ok_or("usage: probe yes|no")?;
let scan = match mode.as_str() {
"yes" => Enabled::Yes,
"no" => Enabled::No,
_ => return Err("usage: probe yes|no".into()),
};
let observed = run(scan)?;
println!("pagemap_scan={mode} observed=0x{observed:02x} expected=0x00");
Ok(if observed == 0 {
ExitCode::SUCCESS
} else {
ExitCode::FAILURE
})
}
uname -r
cargo run --release -- no
cargo run --release -- yes
Representative output from the Wasmtime 50.0.2 run on Linux 7.3.4:
7.3.4-070304-generic
pagemap_scan=no observed=0x00 expected=0x00
pagemap_scan=yes observed=0x5a expected=0x00
Impact
The demonstrated failure is a prior instance's linear-memory byte remaining visible through the host memory API in a later instance using the same pool slot. It also breaks the expected fresh-memory state. In a service that shares a pooling allocator between distinct tenants, the same mechanism could expose one tenant's guest-memory contents to another.
- Ngôn ngữ chính
- Rust
- Star
- 18.9k
- Fork
- 2k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 238
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/wasmtime
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15536 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15455 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsCó thể đã có người làm @dpfens đã nhận 13 ngày trước. Đang mởwasi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bytecodealliance/wasmtime#15296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug wasm-proposal:exceptions wasmtime:debugging
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bytecodealliance/wasmtime#14102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasm-proposal:gc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bytecodealliance/wasmtime#13808 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wasmtime
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: plugins bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
clipy-recorder/clipy#1039 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
valkey-io/valkey-glide#7975 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gofractally/psibase#2379 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Qwen stream parser: a chunk with "error": null is treated as a stream errorCó thể đã có người làm @Beehtrix đã nhận hôm nay. Đang mởarea:models bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
brekkylab/ailoy#681 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày