Skip to content

Commit 9ff20b0

Browse files
authored
Fix OOM in fuzzing from using malloc memory (#10164)
Our `StoreLimits` implementation doesn't take into account the reservation of linear memory that it can grow into. This works fine for `mmap` since memory isn't committed, but it doesn't work in fuzzing for malloc-based memories because the fuzzing harness just thinks a huge allocation is being made and declares OOM. This is fixed in this commit by ensuring that the `memory-reservation-for-growth` parameter is tuned smaller-than-the-default-2G when malloc-based memories are used.
1 parent c59e0a3 commit 9ff20b0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/fuzzing/src/generators/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,25 @@ impl Config {
389389
None
390390
};
391391

392+
// If malloc-based memory is going to be used, which requires these four
393+
// options set to specific values (and Pulley auto-sets two of them)
394+
// then be sure to cap `memory_reservation_for_growth` at a smaller
395+
// value than the default. For malloc-based memory reservation beyond
396+
// the end of memory isn't captured by `StoreLimiter` so we need to be
397+
// sure it's small enough to not blow OOM limits while fuzzing.
398+
if ((cfg.opts.signals_based_traps == Some(true) && cfg.opts.memory_guard_size == Some(0))
399+
|| self.wasmtime.compiler_strategy == CompilerStrategy::CraneliftPulley)
400+
&& cfg.opts.memory_reservation == Some(0)
401+
&& cfg.opts.memory_init_cow == Some(false)
402+
{
403+
let growth = &mut cfg.opts.memory_reservation_for_growth;
404+
let max = 1 << 20;
405+
*growth = match *growth {
406+
Some(n) => Some(n.min(max)),
407+
None => Some(max),
408+
};
409+
}
410+
392411
log::debug!("creating wasmtime config with CLI options:\n{cfg}");
393412
let mut cfg = cfg.config(None).expect("failed to create wasmtime::Config");
394413

0 commit comments

Comments
 (0)