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

feat(fuzzing): Add syscall monitoring to canister sandbox #3420

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

venkkatesh-sekar
Copy link
Member

@venkkatesh-sekar venkkatesh-sekar commented Jan 13, 2025

In #2513, we introduced the target //rs/execution_environment/fuzz:fuzzer_sandbox that allows fuzzers to use cansiter sandbox. In this PR, we improve the library to add syscall monitoring over the sandbox to mimic a pseudo SELinux setting in a test environment.

The current approach is simple as in the sandbox panics if it performs a syscall not present in a static list. But the functionality can be further improved in future PRs.

@venkkatesh-sekar venkkatesh-sekar changed the title monitor syscalls of sandbox feat(fuzzing): Add syscall monitoring to canister sandbox Jan 17, 2025
@github-actions github-actions bot added the feat label Jan 17, 2025
@venkkatesh-sekar venkkatesh-sekar marked this pull request as ready for review January 17, 2025 08:08
@venkkatesh-sekar venkkatesh-sekar requested review from a team as code owners January 17, 2025 08:08
Copy link
Contributor

@berestovskyy berestovskyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo a few comments, thanks!

// and the tid are stored in a BTreeSet, they are ordered based on their creation sequence.
//
// By tracing all PIDs and analyzing the associated syscalls, we observe that the critical
// threads to attach to are typically among the last few, specifically [n-2] and [n-1].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should trace all of them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to trace only the wasm execution but it makes sense to trace all the threads. However, there was an issue with tracer getting stuck on some PIDs. I have spawned the tracers into their own thread pool which should solve this problem

rs/execution_environment/fuzz/src/lib.rs Outdated Show resolved Hide resolved
WaitStatus::PtraceSyscall(_) => {
if let Ok(regs) = ptrace::getregs(child) {
let sysno = Sysno::from(regs.orig_rax as u32);
if !allowed_syscalls.contains(&sysno) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should likely track entries to and exits from system calls. On syscall exit, RAX contains the return value...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and with PTRACE_O_TRACESYSGOOD set via Options:all, it should be easy as flipping a boolean in the while loop. However, I did notice the rax being the same on both entry and exit so maybe I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants