fs: require CAP_SYS_ADMIN in target namespace for idmapped mounts
PATCH 1/1 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.
--- fs/namespace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/namespace.c +3 -2
@@ -4003,8 +4003,9 @@ static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt)if (!(m->mnt_sb->s_type->fs_flags &FS_ALLOW_IDMAP ))return -EINVAL ; -/* We're not controlling the superblock. */ -if (!ns_capable (fs_userns,CAP_SYS_ADMIN )) +/* Mounter doesn't control the source or target namespaces. */ +if (!ns_capable (fs_userns,CAP_SYS_ADMIN ) || + !ns_capable (kattr->mnt_userns,CAP_SYS_ADMIN ))return -EPERM ;/* Mount has already been visible in the filesystem hierarchy. */
Signature · 1 line
2.37.1
Quoted 11 lines · Seth Forshee
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_MOUNTfilesystems support idmapped mounts, thus this is not a problem as onlyCAP_SYS_ADMINininit_user_nsis 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 haveCAP_SYS_ADMINin the target user namespace.
Quoted 3 lines
Fixes bd303368b776 ("fs: support mapped mounts of mapped filesystems")Signed-off-by Seth Forshee <[email protected]>---
Fwiw, I think we can probably move the check into build_mount_idmapped() right before we setup kattr->mnt_userns so we don't end up calling this multiple times for each mount. But no need to resend for this. I can move this. In general that seems like a good idea and good future proofing,
Quoted 16 lines · Christian Brauner
Quoted 11 lines · Seth Forshee
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_MOUNTfilesystems support idmapped mounts, thus this is not a problem as onlyCAP_SYS_ADMINininit_user_nsis 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 haveCAP_SYS_ADMINin the target user namespace.Quoted 3 lines
Fixes bd303368b776 ("fs: support mapped mounts of mapped filesystems")Signed-off-by Seth Forshee <[email protected]>---
Quoted 6 lines
Fwiw, I think we can probably move the check into
build_mount_idmapped()right before we setupkattr->mnt_usernsso we don't end up calling this multiple times for each mount. But no need to resend for this. I can move this. In general that seems like a good idea and good future proofing,
That makes sense. Thanks!