[PATCH 0/2] ns: don't call the namespace LSM hooks for kernel-internal namespaces

Serge E. Hallyn serge at hallyn.com
Fri Nov 20 16:04:35 UTC 2026


On Fri, Nov 20, 2026 at 01:29:57PM +0100, Christian Brauner wrote:
> 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

Thanks, both look good to me.

Acked-by: Serge Hallyn <serge at hallyn.com>

> 
> Signed-off-by: Christian Brauner (Amutable) <brauner at 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
> 



More information about the Linux-security-module-archive mailing list