Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH 0/2] ns: don't call the namespace LSM hooks for kernel-internal namespaces
@ 2026-11-20 12:29 Christian Brauner
  2026-11-20 12:29 ` [PATCH 1/2] mount: pass flags to alloc_mnt_ns() Christian Brauner
  2026-11-20 12:29 ` [PATCH 2/2] ns: don't call the namespace LSM hooks for kernel-internal namespaces Christian Brauner
  0 siblings, 2 replies; 7+ messages in thread
From: Christian Brauner @ 2026-11-20 12:29 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-security-module, Alexander Viro, Jan Kara, bpf, Zhiqi Zhang,
	Christian Brauner (Amutable)

mount_subtree() allocates a private anonymous mount namespace so that
automounts during the path lookup have somewhere to go. btrfs goes
through it on every mount and NFS on every NFSv4 mount and whenever it
follows a referral.

Since the namespace LSM hooks went in that namespace goes through
security_namespace_init() like any other. Landlock enforces
LANDLOCK_PERMISSION_NAMESPACE_USE in its namespace_init hook. So a
sandbox that handles that permission without allowing CLONE_NEWNS can't
mount btrfs or NFSv4 anymore. mount(2) fails with EPERM even though
nobody asked for a mount namespace. Zhiqi reported that and sent a fix
that skips namespace_init for this namespace (cf. [1]).

But namespace_free needs to be skipped as well. Otherwise a bpf program
attached to namespace_free would see these namespaces go away without
ever having seen them being created. Right now that can't happen but
only because security_namespace_free() skips the hook if no LSM
requested a namespace blob. So mark such namespaces as kernel-internal
and keep them away from both hooks. The first patch turns the anon
argument of alloc_mnt_ns() into flags so we don't end up with two
booleans.

The anonymous mount namespaces created by open_tree(OPEN_TREE_CLONE)
and fsmount() are handed to userspace and keep going through the hooks.
Landlock covers them on purpose.

I tested this on v7.4-rc3 with a btrfs loop mount and an NFSv4 mount
in a Landlock domain that handles LANDLOCK_PERMISSION_NAMESPACE_USE but
doesn't allow CLONE_NEWNS. Both fail with EPERM without this series and
work with it. unshare(CLONE_NEWNS), clone(CLONE_NEWNS),
open_tree(OPEN_TREE_CLONE), fsmount() and setns() are still denied and
the Landlock namespace selftests pass.

[1]: https://lore.kernel.org/20261114141323.19029-1-zhiqizhangg@gmail.com

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (2):
      mount: pass flags to alloc_mnt_ns()
      ns: don't call the namespace LSM hooks for kernel-internal namespaces

 fs/namespace.c                     | 31 +++++++++++++++++++++----------
 include/linux/ns/ns_common_types.h |  2 ++
 include/linux/ns_common.h          | 20 +++++++++++++-------
 kernel/nscommon.c                  |  9 ++++++---
 4 files changed, 42 insertions(+), 20 deletions(-)
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261120-work-ns-mount_subtree-d429ad72f8ac


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

end of thread, other threads:[~2026-11-20 14:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 12:29 [PATCH 0/2] ns: don't call the namespace LSM hooks for kernel-internal namespaces Christian Brauner
2026-11-20 12:29 ` [PATCH 1/2] mount: pass flags to alloc_mnt_ns() Christian Brauner
2026-11-20 12:32   ` sashiko-bot
2026-11-20 14:02   ` Alexander Mikhalitsyn
2026-11-20 12:29 ` [PATCH 2/2] ns: don't call the namespace LSM hooks for kernel-internal namespaces Christian Brauner
2026-11-20 12:33   ` sashiko-bot
2026-11-20 14:03   ` Alexander Mikhalitsyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox