Skip to content

Reject directory stdio fds unless explicitly passed#268

Open
Vincent550102 wants to merge 1 commit into
google:masterfrom
Vincent550102:reject-directory-stdio-fds
Open

Reject directory stdio fds unless explicitly passed#268
Vincent550102 wants to merge 1 commit into
google:masterfrom
Vincent550102:reject-directory-stdio-fds

Conversation

@Vincent550102
Copy link
Copy Markdown

Summary

Reject directory file descriptors on the default stdio fds before executing the jailed process.

nsjail keeps fd 0, 1, and 2 open by default. If one of those descriptors is a directory fd, the jailed process can still use it as a filesystem capability after execve with calls such as fchdir(2) or openat(2).

This change fails closed when a default stdio fd is a directory. Explicit --pass_fd / config pass_fd behavior is preserved, so users who intentionally pass a directory fd can still do so explicitly.

Changes

  • Track fds that were explicitly requested through --pass_fd or config pass_fd.
  • Reject directory fds on default stdio descriptors 0, 1, and 2 unless explicitly passed.
  • Document the stdio directory-fd behavior in the --pass_fd help text.
  • Add regression coverage for rejecting default directory stdin while allowing explicit --pass_fd 0.

Testing

make -j$(nproc)

Passed.

./nsjail -q -Mo --chroot / --user 99999 --group 99999 -- /bin/true < /tmp

Returned 255 as expected and rejected default directory stdin.

./nsjail -q -Mo --chroot / --user 99999 --group 99999 --pass_fd 0 -- /bin/true < /tmp

Returned 0 as expected and preserved explicit --pass_fd 0 behavior.

timeout 180 make test

The newly added stdio-fd regression tests passed. The full test run stopped later at the existing tests/pasta-nat.cfg case because ping inside the pasta NAT test returned 1 instead of the expected 77. I reproduced the same tests/pasta-nat.cfg failure on an unmodified HEAD worktree in this environment, so it is not introduced by this change.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 11, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Vincent550102 Vincent550102 force-pushed the reject-directory-stdio-fds branch from b130ec3 to 9d41a57 Compare May 11, 2026 12:05
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