From 067519265012cae19b5b8366364bbef8688e982f Mon Sep 17 00:00:00 2001 From: ltsabadz Date: Fri, 6 Nov 2026 13:49:02 +0000 Subject: [PATCH 1/4] fix(sandbox): allow inotify syscalls in the Linux seccomp filter The default-deny seccomp allow list did not include inotify, so programs that watch files got EPERM inside the sandbox. OpenCode 2.0.29 crashes at startup under `axis run` with "EPERM: operation not permitted, watch '~/.config/opencode'". Related to #96. Allow inotify_init, inotify_init1, inotify_add_watch and inotify_rm_watch. Adding a watch requires read permission on the path, and inotify reports event names, not file contents, so the filesystem policy still bounds what a sandboxed process can observe. Add filter-decision, generated-BPF and runtime probe tests. --- crates/axis-sandbox/src/linux/seccomp.rs | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/crates/axis-sandbox/src/linux/seccomp.rs b/crates/axis-sandbox/src/linux/seccomp.rs index bd1783e6..d3d9d407 100644 --- a/crates/axis-sandbox/src/linux/seccomp.rs +++ b/crates/axis-sandbox/src/linux/seccomp.rs @@ -47,11 +47,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; @@ -180,6 +184,9 @@ const WHITELIST: &[(u32, &str)] = &[ (231, "exit_group"), (232, "epoll_wait"), (233, "epoll_ctl"), + (SYS_INOTIFY_INIT, "inotify_init"), + (SYS_INOTIFY_ADD_WATCH, "inotify_add_watch"), + (SYS_INOTIFY_RM_WATCH, "inotify_rm_watch"), (257, "openat"), (258, "mkdirat"), (260, "fchownat"), @@ -202,6 +209,7 @@ const WHITELIST: &[(u32, &str)] = &[ (291, "epoll_create1"), (292, "dup3"), (293, "pipe2"), + (SYS_INOTIFY_INIT1, "inotify_init1"), (302, "prlimit64"), (309, "getcpu"), (316, "renameat2"), @@ -1299,6 +1307,26 @@ mod tests { } } + #[test] + fn decision_allows_inotify_file_watching() { + let spec = + SeccompFilterSpec::from_policy(&ProcessPolicy::default(), SeccompOptions::default()) + .unwrap(); + + for syscall in [ + SYS_INOTIFY_INIT, + SYS_INOTIFY_ADD_WATCH, + SYS_INOTIFY_RM_WATCH, + SYS_INOTIFY_INIT1, + ] { + assert_eq!( + spec.decision_for(AUDIT_ARCH_X86_64, syscall, [0; 6]), + FilterDecision::Allow, + "inotify syscall {syscall} should be allowed" + ); + } + } + #[test] fn socket_domain_policy_denies_network_domains_but_allows_unix() { let spec = SeccompFilterSpec::from_policy( @@ -1546,6 +1574,26 @@ mod tests { } } + #[test] + fn generated_bpf_allows_inotify_file_watching() { + let spec = + SeccompFilterSpec::from_policy(&ProcessPolicy::default(), SeccompOptions::default()) + .unwrap(); + + for syscall in [ + SYS_INOTIFY_INIT, + SYS_INOTIFY_ADD_WATCH, + SYS_INOTIFY_RM_WATCH, + SYS_INOTIFY_INIT1, + ] { + assert_eq!( + bpf_decision_for(&spec, AUDIT_ARCH_X86_64, syscall, [0; 6]), + FilterDecision::Allow, + "inotify syscall {syscall} should be allowed by generated BPF" + ); + } + } + #[test] fn generated_bpf_applies_conditional_flag_rules() { let mut spec = @@ -1792,6 +1840,18 @@ mod tests { ); } + #[test] + fn runtime_inotify_watch_is_allowed() { + assert_eq!( + run_seccomp_probe( + &ProcessPolicy::default(), + SeccompOptions::default(), + probe_inotify_watch, + ), + PROBE_ALLOWED + ); + } + #[test] fn runtime_socket_domain_filter_denies_ip_sockets_and_preserves_unix() { let options = SeccompOptions::deny_network_socket_domains(); @@ -2195,6 +2255,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( From 14cd1be6bac68ab342cce550446e096105958780 Mon Sep 17 00:00:00 2001 From: ltsabadz Date: Mon, 9 Nov 2026 04:00:12 -0600 Subject: [PATCH 2/4] fix(sandbox): allow inotify only on the Linux MXC path Landlock does not check inotify watches, so on native a watch on a denied directory leaks file names. Allow inotify only for MXC, where denied paths are hidden by mounts. Native keeps returning EPERM. --- crates/axis-sandbox/src/linux/mxc.rs | 9 ++ crates/axis-sandbox/src/linux/seccomp.rs | 128 +++++++++++++++++------ docs/axis-isolation-contract.md | 10 ++ 3 files changed, 113 insertions(+), 34 deletions(-) diff --git a/crates/axis-sandbox/src/linux/mxc.rs b/crates/axis-sandbox/src/linux/mxc.rs index e9509030..17293ef2 100644 --- a/crates/axis-sandbox/src/linux/mxc.rs +++ b/crates/axis-sandbox/src/linux/mxc.rs @@ -3256,9 +3256,11 @@ fn mxc_seccomp_options_for_policy(policy: &Policy) -> super::seccomp::SeccompOpt // 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) } @@ -4087,6 +4089,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 d3d9d407..cd6e3ba5 100644 --- a/crates/axis-sandbox/src/linux/seccomp.rs +++ b/crates/axis-sandbox/src/linux/seccomp.rs @@ -184,9 +184,6 @@ const WHITELIST: &[(u32, &str)] = &[ (231, "exit_group"), (232, "epoll_wait"), (233, "epoll_ctl"), - (SYS_INOTIFY_INIT, "inotify_init"), - (SYS_INOTIFY_ADD_WATCH, "inotify_add_watch"), - (SYS_INOTIFY_RM_WATCH, "inotify_rm_watch"), (257, "openat"), (258, "mkdirat"), (260, "fchownat"), @@ -209,7 +206,6 @@ const WHITELIST: &[(u32, &str)] = &[ (291, "epoll_create1"), (292, "dup3"), (293, "pipe2"), - (SYS_INOTIFY_INIT1, "inotify_init1"), (302, "prlimit64"), (309, "getcpu"), (316, "renameat2"), @@ -229,6 +225,17 @@ const WHITELIST: &[(u32, &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)] @@ -380,6 +387,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 { @@ -390,6 +398,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, } } } @@ -408,6 +417,7 @@ impl SeccompOptions { allow_process_group_syscalls: false, allow_thread_signal_syscalls: false, allow_gpu_runtime_syscalls: false, + allow_file_watch_syscalls: false, } } @@ -431,6 +441,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) { @@ -463,6 +478,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)] @@ -488,6 +508,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 { let nr = syscall_number(name) @@ -851,6 +874,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({ @@ -1308,25 +1332,69 @@ mod tests { } #[test] - fn decision_allows_inotify_file_watching() { + fn file_watch_syscalls_are_denied_by_default() { let spec = SeccompFilterSpec::from_policy(&ProcessPolicy::default(), SeccompOptions::default()) .unwrap(); - for syscall in [ - SYS_INOTIFY_INIT, - SYS_INOTIFY_ADD_WATCH, - SYS_INOTIFY_RM_WATCH, - SYS_INOTIFY_INIT1, - ] { + for (nr, name) in FILE_WATCH_SYSCALLS { assert_eq!( - spec.decision_for(AUDIT_ARCH_X86_64, syscall, [0; 6]), + 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, - "inotify syscall {syscall} should be allowed" + "{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( @@ -1574,26 +1642,6 @@ mod tests { } } - #[test] - fn generated_bpf_allows_inotify_file_watching() { - let spec = - SeccompFilterSpec::from_policy(&ProcessPolicy::default(), SeccompOptions::default()) - .unwrap(); - - for syscall in [ - SYS_INOTIFY_INIT, - SYS_INOTIFY_ADD_WATCH, - SYS_INOTIFY_RM_WATCH, - SYS_INOTIFY_INIT1, - ] { - assert_eq!( - bpf_decision_for(&spec, AUDIT_ARCH_X86_64, syscall, [0; 6]), - FilterDecision::Allow, - "inotify syscall {syscall} should be allowed by generated BPF" - ); - } - } - #[test] fn generated_bpf_applies_conditional_flag_rules() { let mut spec = @@ -1841,13 +1889,25 @@ mod tests { } #[test] - fn runtime_inotify_watch_is_allowed() { + 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 ); } diff --git a/docs/axis-isolation-contract.md b/docs/axis-isolation-contract.md index 7984558a..520ba40d 100644 --- a/docs/axis-isolation-contract.md +++ b/docs/axis-isolation-contract.md @@ -68,6 +68,16 @@ Required behavior: Landlock domain remain allowed. Landlock ABI < 9 cannot enforce this; the native backend logs a warning under `compatibility: best_effort` and continues. - 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, and any other path shows only what a directory listing already + shows. 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 From 7ddf4658fa95fc1437ce54f3aa8123a83b19f1b3 Mon Sep 17 00:00:00 2001 From: ltsabadz Date: Mon, 16 Nov 2026 04:03:37 -0600 Subject: [PATCH 3/4] docs(linux): list inotify among the syscalls MXC allows --- docs/linux-setup.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 From 7a1277ab2c920eabbc4f7222ecbb03a4cd6decdb Mon Sep 17 00:00:00 2001 From: ltsabadz Date: Mon, 16 Nov 2026 05:21:03 -0600 Subject: [PATCH 4/4] docs(linux): say what an inotify watch reports under MXC A watch on a visible path reports opens, reads and changes as they happen, including by processes outside the sandbox on shared mounts such as /usr. It does not only show what a directory listing shows. --- docs/axis-isolation-contract.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/axis-isolation-contract.md b/docs/axis-isolation-contract.md index 2d39c11f..83ae3dca 100644 --- a/docs/axis-isolation-contract.md +++ b/docs/axis-isolation-contract.md @@ -101,8 +101,10 @@ Required behavior: - 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, and any other path shows only what a directory listing already - shows. Linux + 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,