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

chore(fuzzing): extend syscall whitelist in sandbox fuzzers #3659

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from 2 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
43 changes: 33 additions & 10 deletions rs/execution_environment/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,27 @@ fn syscall_monitor<F>(name: &str, sandbox: F)
where
F: Fn(),
{
// The number of sandbox threads must be known in advance because:
// 1. We need to call `ptrace::attach` immediately after the thread is spawned.
// 2. Detached threads interfere with libfuzzer's cleanup process.
adambratschikaye marked this conversation as resolved.
Show resolved Hide resolved

const SANDBOX_THREADS: usize = 14;

match unsafe { fork() } {
Ok(ForkResult::Child) => {
sandbox();
}
Ok(ForkResult::Parent { child }) => {
std::thread::sleep(std::time::Duration::from_secs(1));
let allowed_syscalls: BTreeSet<Sysno> = BTreeSet::from([
// Init
Sysno::gettid,
Sysno::rt_sigprocmask,
Sysno::clone,
Sysno::sched_yield,
Sysno::sched_getaffinity,
Sysno::prctl,
Sysno::getrandom, // probably due to hashbrown dependency
// Execution
Sysno::mmap,
Sysno::mprotect,
Sysno::munmap,
Expand All @@ -102,20 +116,29 @@ where
Sysno::close,
Sysno::restart_syscall,
]);
let children = get_children(child.into());
let threads: Vec<_> = children
.iter()
.map(|child| {
std::thread::spawn({

let mut threads: Vec<_> = vec![];
let mut visited = BTreeSet::new();
while visited.len() < SANDBOX_THREADS {
let children = get_children(child.into());

for pid in children {
if visited.contains(&pid) {
continue;
}

visited.insert(pid);

threads.push(std::thread::spawn({
let allowed_syscalls = allowed_syscalls.clone();
let child = *child;
let child = pid;
let name = name.to_string();
move || {
trace(name, Pid::from_raw(child), allowed_syscalls);
}
})
})
.collect();
}));
}
}

for handle in threads {
handle.join().unwrap();
Expand Down