Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reject untrusted pre-existing work directories before nsjail uses them as mount-tree staging roots.
findWorkDir()tries predictable paths in shared locations such as/tmp/nsjail.<uid>.root.tryCreateDir()previously treatedmkdir(...)=EEXISTas success and then usedaccess(R_OK), which follows symlinks and does not establish that the existing object is a directory owned by the invoking user.These paths are subsequently used as mount targets and, for the root staging tree, as the path passed into the mount/pivot-root setup.
This change requires a work directory to be:
If a predictable candidate is untrusted, nsjail skips it and continues through the existing fallback candidates.
Security rationale
A different local user can pre-create a predictable shared-location candidate as a symlink or foreign-owned directory. The old
EEXIST+access()check accepted that object. On Linux, a mount using a symlink path as the target resolves the symlink and operates on its target, so this allowed another local user to influence which filesystem object nsjail selected for staging.The patch removes that precreation primitive at the point where the staging path enters the mount setup. This is a trust-boundary hardening change; I am not claiming a demonstrated sandbox escape.
Validation
make -j2: PASS.make test-cmdline: PASS.tests/path_containment_test: PASS with new cases for an owned directory, a symlink, and a group/world-writable directory.git diff --check: PASS./tmp/nsjail.<uid>.rootpre-planted as a symlink logsRefusing untrusted work directory, falls back to another candidate, executes/bin/true, and exits 0.