From: Al Viro Date: Mon, 2 Jun 2025 00:11:06 +0000 (-0400) Subject: clone_private_mnt(): make sure that caller has CAP_SYS_ADMIN in the right userns X-Git-Tag: v6.16-rc1~7^2~1 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=c28f922c9dcee0e4876a2c095939d77fe7e15116;p=linux-block.git clone_private_mnt(): make sure that caller has CAP_SYS_ADMIN in the right userns What we want is to verify there is that clone won't expose something hidden by a mount we wouldn't be able to undo. "Wouldn't be able to undo" may be a result of MNT_LOCKED on a child, but it may also come from lacking admin rights in the userns of the namespace mount belongs to. clone_private_mnt() checks the former, but not the latter. There's a number of rather confusing CAP_SYS_ADMIN checks in various userns during the mount, especially with the new mount API; they serve different purposes and in case of clone_private_mnt() they usually, but not always end up covering the missing check mentioned above. Reviewed-by: Christian Brauner Reported-by: "Orlando, Noah" Fixes: 427215d85e8d ("ovl: prevent private clone if bind mount is not allowed") Signed-off-by: Al Viro --- diff --git a/fs/namespace.c b/fs/namespace.c index 2e939b783618..1c54c16c7bab 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2510,6 +2510,9 @@ struct vfsmount *clone_private_mount(const struct path *path) return ERR_PTR(-EINVAL); } + if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN)) + return ERR_PTR(-EPERM); + if (__has_locked_children(old_mnt, path->dentry)) return ERR_PTR(-EINVAL);