mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] namespaces: close two ways out of a chroot
@ 2026-12-01 12:37 Christian Brauner
  2026-12-01 12:37 ` [PATCH 1/4] user: don't let a chrooted task join a user namespace Christian Brauner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christian Brauner @ 2026-12-01 12:37 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jann Horn, Josef Bacik, Serge Hallyn, linux-kernel,
	Alexander Viro, Jan Kara, Christian Brauner (Amutable),
	stable, Ozan Ağdepe (NullSecurityX),
	Forest Huang

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 12:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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

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®