diff --git a/crates/axis-sandbox/src/linux/mxc.rs b/crates/axis-sandbox/src/linux/mxc.rs index 1482440e..b61e652b 100644 --- a/crates/axis-sandbox/src/linux/mxc.rs +++ b/crates/axis-sandbox/src/linux/mxc.rs @@ -3120,9 +3120,11 @@ pub(super) fn mxc_seccomp_options_for_policy(policy: &Policy) -> super::seccomp: // MXC owns the containment lifecycle outside the payload's process group // and PID namespace, so agent CLIs may use process-group setup and // same-process thread signaling for tool execution/runtime support. + // MXC mounts decide what the payload can see, so it can watch files. options .allow_process_group_syscalls() .allow_thread_signal_syscalls() + .allow_file_watch_syscalls() .for_gpu_passthrough(policy) } @@ -3990,6 +3992,13 @@ mod tests { assert!(block_options.denies_non_unix_socket_domains()); } + #[test] + fn mxc_seccomp_allows_file_watching() { + for mode in [NetworkMode::Allow, NetworkMode::Block, NetworkMode::Proxy] { + assert!(mxc_seccomp_options_for_policy(&policy(mode)).allows_file_watch_syscalls()); + } + } + #[test] fn mxc_seccomp_allows_gpu_runtime_syscalls_only_with_gpu_passthrough() { let mut gpu_policy = policy(NetworkMode::Block); diff --git a/crates/axis-sandbox/src/linux/seccomp.rs b/crates/axis-sandbox/src/linux/seccomp.rs index 1f21decb..dd327823 100644 --- a/crates/axis-sandbox/src/linux/seccomp.rs +++ b/crates/axis-sandbox/src/linux/seccomp.rs @@ -51,11 +51,15 @@ const SYS_SETSID: u32 = 112; const SYS_TKILL: u32 = 200; const SYS_SCHED_SETAFFINITY: u32 = 203; const SYS_TGKILL: u32 = 234; +const SYS_INOTIFY_INIT: u32 = 253; +const SYS_INOTIFY_ADD_WATCH: u32 = 254; +const SYS_INOTIFY_RM_WATCH: u32 = 255; const SYS_UNSHARE: u32 = 272; const SYS_SET_ROBUST_LIST: u32 = 273; const SYS_TIMERFD_CREATE: u32 = 283; const SYS_TIMERFD_SETTIME: u32 = 286; const SYS_TIMERFD_GETTIME: u32 = 287; +const SYS_INOTIFY_INIT1: u32 = 294; const SYS_EXECVEAT: u32 = 322; const SYS_CLONE3: u32 = 435; @@ -266,6 +270,17 @@ const FD_AND_AT_VARIANTS: &[(&str, &str)] = &[ /// Docker's default profile) and skips binding when NUMA is unavailable. const GPU_RUNTIME_SYSCALLS: &[(u32, &str)] = &[(SYS_SCHED_SETAFFINITY, "sched_setaffinity")]; +/// Allowed only where mounts decide what the sandbox can see (MXC), so a denied +/// path is not there to watch. Landlock does not check `inotify_add_watch`: under +/// the native backend a watch on a denied directory would report the names of +/// files created in it. +const FILE_WATCH_SYSCALLS: &[(u32, &str)] = &[ + (SYS_INOTIFY_INIT, "inotify_init"), + (SYS_INOTIFY_ADD_WATCH, "inotify_add_watch"), + (SYS_INOTIFY_RM_WATCH, "inotify_rm_watch"), + (SYS_INOTIFY_INIT1, "inotify_init1"), +]; + /// BPF instruction. #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -418,6 +433,7 @@ pub(crate) struct SeccompOptions { allow_process_group_syscalls: bool, allow_thread_signal_syscalls: bool, allow_gpu_runtime_syscalls: bool, + allow_file_watch_syscalls: bool, } impl Default for SeccompOptions { @@ -429,6 +445,7 @@ impl Default for SeccompOptions { allow_process_group_syscalls: false, allow_thread_signal_syscalls: false, allow_gpu_runtime_syscalls: false, + allow_file_watch_syscalls: false, } } } @@ -448,6 +465,7 @@ impl SeccompOptions { allow_process_group_syscalls: false, allow_thread_signal_syscalls: false, allow_gpu_runtime_syscalls: false, + allow_file_watch_syscalls: false, } } @@ -479,6 +497,11 @@ impl SeccompOptions { self } + pub(crate) fn allow_file_watch_syscalls(mut self) -> Self { + self.allow_file_watch_syscalls = true; + self + } + /// The GPU runtime syscalls when the policy asks for GPU passthrough. pub(crate) fn for_gpu_passthrough(self, policy: &Policy) -> Self { if gpu_passthrough(policy) { @@ -511,6 +534,11 @@ impl SeccompOptions { pub(crate) fn allows_gpu_runtime_syscalls(&self) -> bool { self.allow_gpu_runtime_syscalls } + + #[cfg(test)] + pub(crate) fn allows_file_watch_syscalls(&self) -> bool { + self.allow_file_watch_syscalls + } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -537,6 +565,9 @@ impl SeccompFilterSpec { if options.allow_gpu_runtime_syscalls { allowed_syscalls.extend(GPU_RUNTIME_SYSCALLS.iter().map(|(nr, _)| *nr)); } + if options.allow_file_watch_syscalls { + allowed_syscalls.extend(FILE_WATCH_SYSCALLS.iter().map(|(nr, _)| *nr)); + } for name in &policy.blocked_syscalls { if UNSUPPORTED_XATTR_SYSCALLS @@ -949,6 +980,7 @@ fn syscall_number(name: &str) -> Option { WHITELIST .iter() .chain(GPU_RUNTIME_SYSCALLS) + .chain(FILE_WATCH_SYSCALLS) .find(|(_, n)| *n == name) .map(|(nr, _)| *nr) .or({ @@ -1698,6 +1730,70 @@ mod tests { } } + #[test] + fn file_watch_syscalls_are_denied_by_default() { + let spec = + SeccompFilterSpec::from_policy(&ProcessPolicy::default(), SeccompOptions::default()) + .unwrap(); + + for (nr, name) in FILE_WATCH_SYSCALLS { + assert_eq!( + spec.decision_for(AUDIT_ARCH_X86_64, *nr, [0; 6]), + FilterDecision::Errno(libc::EPERM), + "{name} should be denied by default" + ); + assert_eq!( + bpf_decision_for(&spec, AUDIT_ARCH_X86_64, *nr, [0; 6]), + FilterDecision::Errno(libc::EPERM), + "{name} should be denied by generated BPF by default" + ); + } + } + + #[test] + fn file_watch_syscalls_are_allowed_when_requested() { + let spec = SeccompFilterSpec::from_policy( + &ProcessPolicy::default(), + SeccompOptions::default().allow_file_watch_syscalls(), + ) + .unwrap(); + + for (nr, name) in FILE_WATCH_SYSCALLS { + assert_eq!( + spec.decision_for(AUDIT_ARCH_X86_64, *nr, [0; 6]), + FilterDecision::Allow, + "{name} should be allowed when file watching is requested" + ); + assert_eq!( + bpf_decision_for(&spec, AUDIT_ARCH_X86_64, *nr, [0; 6]), + FilterDecision::Allow, + "{name} should be allowed by generated BPF when file watching is requested" + ); + } + } + + #[test] + fn policy_blocked_file_watch_syscall_overrides_option() { + let policy = ProcessPolicy { + blocked_syscalls: vec!["inotify_add_watch".into()], + ..Default::default() + }; + let spec = SeccompFilterSpec::from_policy( + &policy, + SeccompOptions::default().allow_file_watch_syscalls(), + ) + .unwrap(); + + assert_eq!( + bpf_decision_for(&spec, AUDIT_ARCH_X86_64, SYS_INOTIFY_ADD_WATCH, [0; 6]), + FilterDecision::Errno(libc::EPERM) + ); + assert_eq!( + bpf_decision_for(&spec, AUDIT_ARCH_X86_64, SYS_INOTIFY_INIT1, [0; 6]), + FilterDecision::Allow + ); + } + #[test] fn socket_domain_policy_denies_network_domains_but_allows_unix() { let spec = SeccompFilterSpec::from_policy( @@ -2171,6 +2267,30 @@ mod tests { ); } + #[test] + fn runtime_inotify_watch_is_denied_by_default() { + assert_eq!( + run_seccomp_probe( + &ProcessPolicy::default(), + SeccompOptions::default(), + probe_inotify_watch, + ), + PROBE_DENIED + ); + } + + #[test] + fn runtime_inotify_watch_is_allowed_when_requested() { + assert_eq!( + run_seccomp_probe( + &ProcessPolicy::default(), + SeccompOptions::default().allow_file_watch_syscalls(), + probe_inotify_watch, + ), + PROBE_ALLOWED + ); + } + #[test] fn runtime_fd_and_at_syscalls_reach_the_kernel() { for (name, probe) in [ @@ -2659,6 +2779,21 @@ mod tests { } } + unsafe fn probe_inotify_watch() -> libc::c_long { + let fd = unsafe { libc::syscall(SYS_INOTIFY_INIT1 as libc::c_long, libc::IN_CLOEXEC) }; + if fd < 0 { + return fd; + } + unsafe { + libc::syscall( + SYS_INOTIFY_ADD_WATCH as libc::c_long, + fd, + c"/".as_ptr(), + libc::IN_ATTRIB, + ) + } + } + unsafe fn probe_inet_socket() -> libc::c_long { unsafe { libc::syscall( diff --git a/docs/axis-isolation-contract.md b/docs/axis-isolation-contract.md index adc0415b..83ae3dca 100644 --- a/docs/axis-isolation-contract.md +++ b/docs/axis-isolation-contract.md @@ -99,6 +99,18 @@ Required behavior: the host network, including host loopback, and `network.mode: block` or `proxy`. - Denied paths take precedence over read-only and read-write grants. +- File watching must not reveal activity in a denied path. Linux MXC allows + inotify, because its mounts decide what a watch can see: a denied path is an + empty tmpfs, so a watch on it reports nothing. A watch on any other path the + sandbox can see reports, as they happen, when files in it are created, + deleted, opened, read or changed. This includes activity by processes outside + the sandbox on shared mounts, such as a read-only `/usr`. Linux + native denies inotify with `EPERM`: Landlock does not check + `inotify_add_watch`, so a watch on a denied directory would report the names + of files created in it. Programs that need file watching, such as OpenCode, + work under Linux MXC and fail under Linux native. macOS Seatbelt and Windows + MXC do not use the Linux seccomp filter and are not yet covered by a test + that watches a denied path. - Workspace and temporary directories must be scoped to the sandbox or policy and must not widen access to the caller's home directory. - Symlink, hardlink, path traversal, and canonicalization behavior must not diff --git a/docs/linux-setup.md b/docs/linux-setup.md index 0752ba65..3fdcecda 100644 --- a/docs/linux-setup.md +++ b/docs/linux-setup.md @@ -70,9 +70,10 @@ resource limits; those policies fail closed on hosts that cannot enforce them. Every Linux process backend builds its filter from the same AXIS seccomp allowlist: native Landlock, native Bubblewrap, the netns helper used for proxy -mode, and MXC. MXC also allows `setsid`, `setpgid` and `tgkill`, and policies -with AMD GPU passthrough also allow `sched_setaffinity`. Other syscalls fail -with `EPERM`, with these exceptions: `clone3` fails with `ENOSYS` so thread +mode, and MXC. MXC also allows `setsid`, `setpgid`, `tgkill` and the inotify +calls, and policies with AMD GPU passthrough also allow `sched_setaffinity`. +Other syscalls fail with `EPERM`, with these exceptions: `clone3` fails with +`ENOSYS` so thread runtimes fall back to `clone`, unless the policy blocks it; the extended attribute calls in the table below fail with `EOPNOTSUPP`; under connect supervision, `AF_UNIX` datagram sockets fail with `EACCES`; and a syscall made