Skip to content

fix(sandbox): allow file watching under Linux MXC - #100

Merged
ltsabadz merged 6 commits into
ROCm:mainfrom
ltsabadz:fix/seccomp-inotify
Nov 16, 2026
Merged

ltsabadz merged 6 commits into
ROCm:mainfrom
ltsabadz:fix/seccomp-inotify

Conversation

@ltsabadz

@ltsabadz ltsabadz commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

OpenCode doesn't start under axis run on Linux. It watches its config folder for changes, and our seccomp filter blocks the Linux file-watching calls (inotify), so it fails with EPERM. 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:

  • moves the inotify calls out of the shared allow list into a separate switch, off by default
  • turns the switch on only for MXC
  • leaves native as it was (blocked)
  • still lets a policy block these calls with blocked_syscalls
  • adds a short note to docs/axis-isolation-contract.md on what works where

What this means for users:

  • Linux with MXC (the default): OpenCode and other file watchers work
  • Linux native: file watchers still fail, on purpose
  • macOS, Windows and vxn: no change, they don't use this filter

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

  • fmt, clippy, the full test suite and scripts/test_security_tier0.sh on Linux x86_64
  • New unit tests: inotify blocked by default, allowed when switched on, blocked_syscalls still wins, MXC switches it on
  • By hand: ran OpenCode under MXC, and ran a small program that watches a denied folder while a file is created in it, on native and MXC

Test Result

  • All checks pass
  • OpenCode starts under MXC
  • Native: the watch is refused, nothing leaks
  • MXC: a watch on a denied folder sees nothing
  • Not tested: Windows, macOS.

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.
@ltsabadz
ltsabadz marked this pull request as ready for review November 16, 2026 09:53

@johayang-amd johayang-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

  1. Conflict with main. #110 touched seccomp.rs, so this needs a rebase (keeping both sets of tests works), and CI hasn't run yet.
  2. 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
johayang-amd previously approved these changes Nov 16, 2026

@johayang-amd johayang-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
@ltsabadz
ltsabadz merged commit 9d442a5 into ROCm:main Nov 16, 2026
34 of 59 checks passed
@ltsabadz
ltsabadz deleted the fix/seccomp-inotify branch November 19, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: OpenCode TUI never starts under Axis: its background server accepts connections but never reads them

2 participants