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 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
41 changes: 29 additions & 12 deletions rs/execution_environment/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::os::raw::c_char;
#[cfg(target_os = "linux")]
use {
nix::{
sys::ptrace, sys::ptrace::Options, sys::wait::waitpid, sys::wait::WaitStatus, unistd::fork,
unistd::ForkResult, unistd::Pid,
sys::ptrace, sys::ptrace::Options, sys::wait::waitpid, sys::wait::WaitPidFlag,
sys::wait::WaitStatus, unistd::fork, unistd::ForkResult, unistd::Pid,
},
procfs::process::Process,
std::collections::BTreeSet,
Expand Down Expand Up @@ -90,8 +90,16 @@ where
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 +110,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 let Ok(WaitStatus::StillAlive) = waitpid(child, Some(WaitPidFlag::WNOHANG)) {
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