Repository navigation
fix(sandbox): allow file watching under Linux MXC - #100
Conversation
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 ROCm#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.
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.
# Conflicts: # crates/axis-sandbox/src/linux/seccomp.rs
johayang-amd
left a comment
There was a problem hiding this comment.
Thanks Luka, this fixes it. I reproduced #96 on main with OpenCode 2.3.0 under MXC (stuck at "Starting background server..."), and with this PR the TUI comes up and Ctrl-C exits cleanly. Allowing epoll_pwait2 as well made no difference, so inotify was the real blocker.
Two things before merge:
- Conflict with main. #110 touched
seccomp.rs, so this needs a rebase (keeping both sets of tests works), and CI hasn't run yet. - Docs wording. In
docs/axis-isolation-contract.md, "any other path shows only what a directory listing already shows" isn't quite accurate: a watch also reports opens, reads and changes in real time, including activity from processes outside the sandbox on shared read-only mounts such as/usr. That seems acceptable for MXC, but could the doc and the security impact line say so?
Tested: MXC on a shared Linux test host (kernel 6.18), OpenCode 2.3.0, the policy from #96. main hangs; this PR (merged onto current main) shows the TUI and exits on Ctrl-C; no leftover bwrap or opencode processes.
johayang-amd
left a comment
There was a problem hiding this comment.
Thanks for the rebase, CI is green. Approving. One small follow-up when you get a chance: the isolation contract still says MXC watches show "only what a directory listing already shows". Could you reword that to mention real-time open/read/modify events on visible paths? A follow-up PR is fine.
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.
Motivation
OpenCode doesn't start under
axis runon Linux. It watches its config folder for changes, and our seccomp filter blocks the Linux file-watching calls (inotify), so it fails withEPERM. Fixes #96.Technical Details
We can't just allow inotify everywhere. On the native backend, Landlock doesn't check file watches, so a sandboxed process could watch a folder it isn't allowed to read and see the names of new files in it.
MXC doesn't have this problem. It builds the sandbox's view of the filesystem with mounts, and a denied folder is replaced by an empty one, so there's nothing to watch.
So this PR:
blocked_syscallsdocs/axis-isolation-contract.mdon what works whereWhat this means for users:
Security impact: Under MXC, a process can watch only paths it can already see. Denied paths are empty, so a watch on them reports nothing. A watch on a visible path does report opens, reads and changes as they happen, including by processes outside the sandbox on shared read-only mounts such as
/usr. Native is unchanged.Test Plan
scripts/test_security_tier0.shon Linux x86_64blocked_syscallsstill wins, MXC switches it onTest Result