Skip to content

unotify: resolve empty paths to the object dirfd refers to - #393

Open
0z5a wants to merge 1 commit into
google:masterfrom
0z5a:fix/unotify-empty-path
Open

0z5a wants to merge 1 commit into
google:masterfrom
0z5a:fix/unotify-empty-path

Conversation

@0z5a

@0z5a 0z5a commented Nov 16, 2026

Copy link
Copy Markdown

With --execute_fd, nsjail starts the sandboxee with execveat(fd, "", argv, envp, AT_EMPTY_PATH). When --seccomp_unotify is also set, that call is traced, but the report records it under an empty path with contradictory types:

fs_access {
  path: ""
  jail_type: LINK
  main_type: NONEXISTENT
  syscall {
    name: "execveat"
    args: "dirfd=4"
    args: "argv[0]=/usr/bin/true"
  }
  exists_in_jail: true
  exists_in_main: false
}

getAbsPath() returns an empty path unchanged, so populatePathInfo() runs lstat("/proc/<pid>/root") (the magic link itself, hence LINK) and lstat("") (hence NONEXISTENT). The executed binary never shows up in the report, which is the one path a --execute_fd user most needs to see, since it is usually not mounted inside the jail.

An empty path only names a file through its dirfd (AT_EMPTY_PATH, see execveat(2) and openat(2)), so this change resolves it to the object dirfd refers to, using the same /proc/<pid>/fd/<n> lookup already used for relative paths, without appending a /. The same record now reads path: "/usr/bin/true", jail_type: REGULAR, main_type: REGULAR.

An empty path with AT_FDCWD is left empty, because whether it means the working directory depends on the syscall and its flags (readlink("") fails with ENOENT). Such a record is now reported as NONEXISTENT on both sides instead of getting the types of /proc/<pid>/root itself.

Testing:

  • New tests/unotify_execute_fd.sh, run by make test (target test-unotify-execute-fd). It runs /bin/true with --execute_fd --seccomp_unotify and all namespaces disabled, so it also works without root, and checks the path of the execveat record. On Linux aarch64 (kernel 6.8) it fails on master (execveat record has path "", expected "/usr/bin/true") and passes with this change. It exits 77 (skip) where seccomp user notifications are unavailable.
  • make test-cmdline (7 checks) and the four nstun unit tests pass with this change.
  • A python3 -c pass run under --seccomp_unotify gives the same report (101 records) before and after.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

With --execute_fd the sandboxee is started with execveat(fd, "", ...,
AT_EMPTY_PATH). getAbsPath() returned the empty path unchanged, so the
unotify report recorded the execveat under path "" with the types of
/proc/<pid>/root itself instead of the executed binary.

Resolve an empty path to the object dirfd refers to. With AT_FDCWD it
stays empty and is reported as NONEXISTENT. Add a test run by
`make test`.

This branch has not been deployed

No deployments
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.

1 participant