setns: support user namespaces#13323
Open
shayonj wants to merge 1 commit into
Open
Conversation
User namespace entries under /proc/[pid]/ns currently render as fake namespace symlinks. They look like the other namespace files, but opening them does not produce an nsfs file that setns(2) can use. Rootless container tools such as buildah and podman rely on that file when they re-enter the pause process user namespace, so the second lifecycle command fails with EINVAL. Make UserNamespace implement vfs.Namespace and give each user namespace an nsfs inode when it is created. /proc/[pid]/ns/user now uses the regular namespace symlink path, so opening it returns a joinable namespace file instead of a fake link target. Setns now accepts CLONE_NEWUSER from both nsfds and pidfds. It follows the Linux restrictions for user namespace joins by rejecting the caller's current user namespace, requiring CAP_SYS_ADMIN in the target user namespace, rejecting multithreaded callers, and rejecting callers with fs state shared outside the thread group. The capability checks for any other namespaces in the same setns call use the credentials the caller would have after joining the user namespace. Add a syscall regression test that creates a child user namespace, opens /proc/<pid>/ns/user, and verifies that setns(CLONE_NEWUSER) succeeds.
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.
User namespace entries under
/proc/[pid]/nscurrently render as fakenamespace symlinks. They look like the other namespace files, but opening
them does not produce an
nsfsfile thatsetns(2)can use. Rootlesscontainer tools such as
buildahandpodmanrely on that file when theyre-enter the pause process user namespace, so the second lifecycle command
fails with
EINVAL.Make
UserNamespaceimplementvfs.Namespaceand give each user namespacean
nsfsinode when it is created./proc/[pid]/ns/usernow uses theregular namespace symlink path, so opening it returns a joinable namespace
file instead of a fake link target.
Setnsnow acceptsCLONE_NEWUSERfrom bothnsfds andpidfds. Itfollows the Linux restrictions for user namespace joins by rejecting the
caller's current user namespace, requiring
CAP_SYS_ADMINin the targetuser namespace, rejecting multithreaded callers, and rejecting callers with
fsstate shared outside the thread group. The capability checks for anyother namespaces in the same
setnscall use the credentials the callerwould have after joining the user namespace.
Add a syscall regression test that creates a child user namespace, opens
/proc/<pid>/ns/user, and verifies thatsetns(CLONE_NEWUSER)succeeds.Fixes #13314