O_PATH opens fail with EACCES in chroot mode (fd delivery, not grants)
Summary
In chroot mode (sandlock run --chroot /), every O_PATH open fails with EACCES — even on files the policy grants read+write on, where O_RDONLY and O_RDWR succeed. This is not a grant problem: path resolution, access vetting, and the supervisor's on-behalf open all succeed. The failure happens one step later, at fd delivery: the kernel's SECCOMP_IOCTL_NOTIF_ADDFD will not install an O_PATH fd into another process, and Sandlock reports that mechanism failure as a permission denial on a fully authorized open.
Under Landlock semantics that verdict is impossible from the ruleset (a domain permitting read+write necessarily permits the lesser O_PATH, which needs no file rights at all) — so the denial comes from the delivery pipeline, and the current EACCES sends every investigation down the policy path first.
Repro
$ mkdir -p /tmp/opath-test && echo hi > /tmp/opath-test/f.txt
$ sandlock run --chroot / -r /nix/store -w /tmp/opath-test -- \
python3 -c "
import os
for name, flags in [('O_RDONLY', os.O_RDONLY), ('O_RDWR', os.O_RDWR), ('O_PATH', os.O_PATH)]:
try:
fd = os.open('/tmp/opath-test/f.txt', flags); os.close(fd); print(name, '=> OK')
except OSError as e:
print(name, '=> ERR', e.errno)"
O_RDONLY => OK
O_RDWR => OK
O_PATH => ERR 13
Same file, same policy: read+write allowed, O_PATH denied. Strace of the supervisor shows both on-behalf openat2s returning a valid fd; only the ADDFD injection fails.
Mode comparison (identical grants in all cases):
| mode | O_RDONLY |
O_PATH |
glibc realpath() |
|---|---|---|---|
chroot-identity (--chroot /) |
OK | EACCES | NULL |
| supervised, no chroot | OK | OK | valid pointer |
COW workdir (--workdir) |
OK | OK | OK |
So this is specific to chroot mode, where opens are served via supervisor re-issue + ADDFD inject. In the other modes the open is executed by the kernel itself or never needs cross-process fd injection of an O_PATH handle.
Impact
Anything built on O_PATH breaks in chroot mode. Most notably glibc realpath(), which opens each path component O_PATH and reads back /proc/self/fd. Through it:
- libgit2 repository opening fails (e.g.
nix flake metadata/nix build .#…on any git repo), buncannot read/parsepackage.json(fails with an internalStackOverflowon trivially valid files, for bothbun addandbun install).
Disclaimer, this is an AI assisted review.
Thanks for the report, the analysis is right: this is fd delivery, not grants. SECCOMP_IOCTL_NOTIF_ADDFD takes its source with fget(), which refuses an O_PATH descriptor.
We had worked around this for COW branch entries (#325, #342), which is why --workdir works in your table, but the plain chroot open path never got the same treatment. #348 extends it: an O_PATH open of a regular file or a directory is now served with a descriptor reopened O_RDONLY. The chroot handler already requires read access for such an open, so nothing extra is granted.
Known limits after the fix:
- The fd reports
O_RDONLYthroughF_GETFL, notO_PATH. O_PATHon a symlink itself (O_NOFOLLOW), a FIFO, a socket or a device still fails, withEOPNOTSUPP.- So does a file the supervisor cannot read by its mode bits.
On the errno: since v0.9.1 this case is reported as EOPNOTSUPP (95), not EACCES. If you see 13 on v0.9.1 or later, please tell us which version and kernel you are on.
If you can, please try the chroot-o-path-open branch against your nix and bun cases and report back.