From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Jann Horn" <jannh@google.com>,
"Josef Bacik" <josef@toxicpanda.com>,
"Serge Hallyn" <sergeh@kernel.org>,
linux-kernel@vger.kernel.org,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>,
"Christian Brauner (Amutable)" <brauner@kernel.org>,
stable@vger.kernel.org,
"Ozan Ağdepe (NullSecurityX)" <agdepeozan@gmail.com>,
"Forest Huang" <foresthuang3@gmail.com>
Subject: [PATCH 0/4] namespaces: close two ways out of a chroot
Date: Tue, 01 Dec 2026 13:37:24 +0100 [thread overview]
Message-ID: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> (raw)
CLONE_EMPTY_MNTNS lets a chrooted caller with only CAP_SYS_ADMIN reset
its root to the empty root of a new mount namespace. That doesn't make
any files reachable but afterwards the caller isn't chrooted anymore and
can create user namespaces again. setns() requires CAP_SYS_CHROOT for
the same thing. So require it here as well if the caller is chrooted.
Ozan pointed out that joining a user namespace never got the chroot
restriction that creating one has. A chrooted task without any
capabilities can setns() into a user namespace owned by its uid that
some unchrooted process created and chroot() its way out. That one is a
lot older. Refuse it unless the caller has CAP_SYS_CHROOT in its current
user namespace, i.e., unless it could chroot() its way out anyway.
A task without CAP_SYS_CHROOT that setns()es into a user namespace from
inside a chroot gets EPERM now. Creating one there already fails so I
don't expect anyone to rely on that.
Both come with selftests.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (4):
user: don't let a chrooted task join a user namespace
mount: don't let an empty mount namespace undo a chroot
selftests/namespaces: test joining a user namespace from a chroot
selftests/filesystems: test empty mount namespaces from a chroot
fs/namespace.c | 9 ++
kernel/user_namespace.c | 9 ++
.../empty_mntns/clone3_empty_mntns_test.c | 36 ++++++
.../filesystems/empty_mntns/empty_mntns.h | 18 +++
.../filesystems/empty_mntns/empty_mntns_test.c | 85 ++++++++++++++
.../selftests/filesystems/failfs/failfs_test.c | 38 +++++++
tools/testing/selftests/namespaces/.gitignore | 1 +
tools/testing/selftests/namespaces/Makefile | 4 +-
.../selftests/namespaces/userns_chroot_test.c | 124 +++++++++++++++++++++
9 files changed, 323 insertions(+), 1 deletion(-)
---
base-commit: a63f17c4cacafcc9ff8c88651b42cd62b936d729
change-id: 20261201-work-mount-empty_mntns_chroot-7372785b88f6
next reply other threads:[~2026-12-01 12:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:37 Christian Brauner [this message]
2026-12-01 12:37 ` [PATCH 1/4] user: don't let a chrooted task join a user namespace Christian Brauner
2026-12-01 12:37 ` [PATCH 2/4] mount: don't let an empty mount namespace undo a chroot Christian Brauner
2026-12-01 12:37 ` [PATCH 3/4] selftests/namespaces: test joining a user namespace from " Christian Brauner
2026-12-01 12:37 ` [PATCH 4/4] selftests/filesystems: test empty mount namespaces " Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org \
--to=brauner@kernel.org \
--cc=agdepeozan@gmail.com \
--cc=foresthuang3@gmail.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sergeh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®