Skip to content

Commit bf1ac16

Browse files
sforsheebrauner
authored andcommitted
fs: require CAP_SYS_ADMIN in target namespace for idmapped mounts
Idmapped mounts should not allow a user to map file ownsership into a range of ids which is not under the control of that user. However, we currently don't check whether the mounter is privileged wrt to the target user namespace. Currently no FS_USERNS_MOUNT filesystems support idmapped mounts, thus this is not a problem as only CAP_SYS_ADMIN in init_user_ns is allowed to set up idmapped mounts. But this could change in the future, so add a check to refuse to create idmapped mounts when the mounter does not have CAP_SYS_ADMIN in the target user namespace. Fixes: bd30336 ("fs: support mapped mounts of mapped filesystems") Signed-off-by: Seth Forshee <[email protected]> Reviewed-by: Christian Brauner (Microsoft) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner (Microsoft) <[email protected]>
1 parent ddc84c9 commit bf1ac16

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/namespace.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,6 +4238,13 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
42384238
err = -EPERM;
42394239
goto out_fput;
42404240
}
4241+
4242+
/* We're not controlling the target namespace. */
4243+
if (!ns_capable(mnt_userns, CAP_SYS_ADMIN)) {
4244+
err = -EPERM;
4245+
goto out_fput;
4246+
}
4247+
42414248
kattr->mnt_userns = get_user_ns(mnt_userns);
42424249

42434250
out_fput:

0 commit comments

Comments
 (0)