Skip to content

Commit

Permalink
fs/mount_setattr: tighten permission checks
Browse files Browse the repository at this point in the history
We currently don't have any filesystems that support idmapped mounts
which are mountable inside a user namespace. That was a deliberate
decision for now as a userns root can just mount the filesystem
themselves. So enforce this restriction explicitly until there's a real
use-case for this. This way we can notice it and will have a chance to
adapt and audit our translation helpers and fstests appropriately if we
need to support such filesystems.

Cc: Christoph Hellwig <[email protected]>
Cc: Al Viro <[email protected]>
Cc: [email protected]
CC: [email protected]
Suggested-by: Seth Forshee <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
Christian Brauner committed May 12, 2021
1 parent 6efb943 commit 2ca4dcc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3855,8 +3855,12 @@ 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;

/* Don't yet support filesystem mountable in user namespaces. */
if (m->mnt_sb->s_user_ns != &init_user_ns)
return -EINVAL;

/* We're not controlling the superblock. */
if (!ns_capable(m->mnt_sb->s_user_ns, CAP_SYS_ADMIN))
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

/* Mount has already been visible in the filesystem hierarchy. */
Expand Down

0 comments on commit 2ca4dcc

Please sign in to comment.