[RFC PATCH v6 05/26] mount: Enforce mount_too_revealing() for foreign mntns

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Sun Nov 22 02:13:54 UTC 2026


> mount: Enforce mount_too_revealing() for foreign mntns

TL;DR: Nit only, not a bug: the CAP_SYS_ADMIN check on ns->user_ns in
mount_too_revealing() is repeated, up to three times, and could be computed
once and passed to mnt_already_visible().

> diff --git a/fs/namespace.c b/fs/namespace.c
> --- a/fs/namespace.c
> +++ b/fs/namespace.c

[ ... ]

> @@ -6582,6 +6582,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
>  				const struct super_block *sb,
>  				int *new_mnt_flags)
>  {
> +	bool foreign_ns = !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN);
>  	int new_flags = *new_mnt_flags;
>  	struct mount *mnt;

[ ... ]

> @@ -6650,13 +6656,18 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags
>  	struct mnt_namespace *ns = current->nsproxy->mnt_ns;
>  	unsigned long s_iflags;
>  
> -	if (ns->user_ns == &init_user_ns)
> -		return false;
> -
>  	/* Can this filesystem be too revealing? */
>  	if (!(sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED))
>  		return false;
>  
> +	if (ns->user_ns == &init_user_ns &&
> +	    ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN))
> +		return false;
> +
> +	if (!ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN) &&
> +	    current_chrooted())
> +		return true;
> +

This isn't a bug, but could the CAP_SYS_ADMIN-over-ns->user_ns result be
computed once in mount_too_revealing() and passed to mnt_already_visible(),
rather than calling ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN) again for
foreign_ns?

When ns->user_ns is &init_user_ns, the first check here is the same test as
the second, and mnt_already_visible() evaluates it a third time.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44972669664


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