Skip to content

Commit e77078e

Browse files
Al Virogregkh
authored andcommitted
clone_private_mnt(): make sure that caller has CAP_SYS_ADMIN in the right userns
commit c28f922 upstream. 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 <[email protected]> Reported-by: "Orlando, Noah" <[email protected]> Fixes: 427215d ("ovl: prevent private clone if bind mount is not allowed") Signed-off-by: Al Viro <[email protected]> [ merge conflict resolution: clone_private_mount() was reworked in db04662 ("fs: allow detached mounts in clone_private_mount()"). Tweak the relevant ns_capable check so that it works on older kernels ] Signed-off-by: Noah Orlando <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7fc808d commit e77078e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/namespace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,11 @@ struct vfsmount *clone_private_mount(const struct path *path)
22632263
if (!check_mnt(old_mnt))
22642264
goto invalid;
22652265

2266+
if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN)) {
2267+
up_read(&namespace_sem);
2268+
return ERR_PTR(-EPERM);
2269+
}
2270+
22662271
if (has_locked_children(old_mnt, path->dentry))
22672272
goto invalid;
22682273

0 commit comments

Comments
 (0)