From: "Serge E. Hallyn" <serge@hallyn.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, "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>,
stable@vger.kernel.org,
"Ozan Ağdepe (NullSecurityX)" <agdepeozan@gmail.com>,
"Forest Huang" <foresthuang3@gmail.com>
Subject: Re: [PATCH 0/4] namespaces: close two ways out of a chroot
Date: Tue, 1 Dec 2026 09:24:31 -0600 [thread overview]
Message-ID: <aw7mr86BeyAbq64P@hallyn.com> (raw)
In-Reply-To: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org>
On Tue, Dec 01, 2026 at 01:37:24PM +0100, Christian Brauner wrote:
> 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
>
Looks good, thanks.
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Only thing I noticed is it might be nice if enter_jail() didn't need to be
duplicated in both tools/testing/selftests/namespaces/userns_chroot_test.c
and tools/testing/selftests/filesystems/empty_mntns/empty_mntns.h .
> 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
prev parent reply other threads:[~2026-12-01 15:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:37 [PATCH 0/4] namespaces: close two ways out of a chroot Christian Brauner
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 15:24 ` Serge E. Hallyn [this message]
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=aw7mr86BeyAbq64P@hallyn.com \
--to=serge@hallyn.com \
--cc=agdepeozan@gmail.com \
--cc=brauner@kernel.org \
--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