Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault with custom page sizes on aarch64 #8918

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/environ/src/compile/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,20 @@ impl ModuleTranslation<'_> {

// Validate that the memory information collected is indeed valid for
// static memory initialization.
for info in info.values().filter(|i| i.data_size > 0) {
for (i, info) in info.iter().filter(|(_, info)| info.data_size > 0) {
let image_size = info.max_addr - info.min_addr;

// Simplify things for now by bailing out entirely if any memory has
// a page size smaller than the host's page size. This fixes a case
// where currently initializers are created in host-page-size units
// of length which means that a larger-than-the-entire-memory
// initializer can be created. This can be handled technically but
// would require some more changes to help fix the assert elsewhere
// that this protects against.
if self.module.memory_plans[i].memory.page_size() < page_size {
return;
}

// If the range of memory being initialized is less than twice the
// total size of the data itself then it's assumed that static
// initialization is ok. This means we'll at most double memory
Expand Down
6 changes: 5 additions & 1 deletion crates/wasmtime/src/runtime/vm/instance/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ fn initialize_memories(instance: &mut Instance, module: &Module) -> Result<()> {

unsafe {
let src = self.instance.wasm_data(init.data.clone());
let dst = memory.base.add(usize::try_from(init.offset).unwrap());
let offset = usize::try_from(init.offset).unwrap();
let dst = memory.base.add(offset);

assert!(offset + src.len() <= memory.current_length());

// FIXME audit whether this is safe in the presence of shared
// memory
// (https://github.com/bytecodealliance/wasmtime/issues/4203).
Expand Down
6 changes: 4 additions & 2 deletions tests/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ fn run_wast(wast: &Path, strategy: Strategy, pooling: bool) -> anyhow::Result<()
cfg.static_memory_maximum_size(0);
}
cfg.dynamic_memory_reserved_for_growth(0);
cfg.static_memory_guard_size(0);
cfg.dynamic_memory_guard_size(0);

let small_guard = 64 * 1024;
cfg.static_memory_guard_size(small_guard);
cfg.dynamic_memory_guard_size(small_guard);
}

let _pooling_lock = if pooling {
Expand Down