mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
inode: make init and permission helpers idmapped mount aware
The inode_owner_or_capable() helper determines whether the caller is the owner of the inode or is capable with respect to that inode. Allow it to handle idmapped mounts. If the inode is accessed through an idmapped mount it according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before. Similarly, allow the inode_init_owner() helper to handle idmapped mounts. It initializes a new inode on idmapped mounts by mapping the fsuid and fsgid of the caller from the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before. Link: https://lore.kernel.org/r/20210121131959.646623-7-christian.brauner@ubuntu.com Cc: Christoph Hellwig <hch@lst.de> Cc: David Howells <dhowells@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: James Morris <jamorris@linux.microsoft.com> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -972,7 +972,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
|
||||
inode->i_uid = current_fsuid();
|
||||
inode->i_gid = dir->i_gid;
|
||||
} else
|
||||
inode_init_owner(inode, dir, mode);
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
|
||||
if (ext4_has_feature_project(sb) &&
|
||||
ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT))
|
||||
|
@@ -139,7 +139,8 @@ static long swap_inode_boot_loader(struct super_block *sb,
|
||||
}
|
||||
|
||||
if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
|
||||
!inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN)) {
|
||||
!inode_owner_or_capable(&init_user_ns, inode) ||
|
||||
!capable(CAP_SYS_ADMIN)) {
|
||||
err = -EPERM;
|
||||
goto journal_err_out;
|
||||
}
|
||||
@@ -829,7 +830,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
case FS_IOC_SETFLAGS: {
|
||||
int err;
|
||||
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EACCES;
|
||||
|
||||
if (get_user(flags, (int __user *) arg))
|
||||
@@ -871,7 +872,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
__u32 generation;
|
||||
int err;
|
||||
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EPERM;
|
||||
|
||||
if (ext4_has_metadata_csum(inode->i_sb)) {
|
||||
@@ -1010,7 +1011,7 @@ mext_out:
|
||||
case EXT4_IOC_MIGRATE:
|
||||
{
|
||||
int err;
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EACCES;
|
||||
|
||||
err = mnt_want_write_file(filp);
|
||||
@@ -1032,7 +1033,7 @@ mext_out:
|
||||
case EXT4_IOC_ALLOC_DA_BLKS:
|
||||
{
|
||||
int err;
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EACCES;
|
||||
|
||||
err = mnt_want_write_file(filp);
|
||||
@@ -1217,7 +1218,7 @@ resizefs_out:
|
||||
|
||||
case EXT4_IOC_CLEAR_ES_CACHE:
|
||||
{
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EACCES;
|
||||
ext4_clear_inode_es(inode);
|
||||
return 0;
|
||||
@@ -1263,7 +1264,7 @@ resizefs_out:
|
||||
return -EFAULT;
|
||||
|
||||
/* Make sure caller has proper permission */
|
||||
if (!inode_owner_or_capable(inode))
|
||||
if (!inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EACCES;
|
||||
|
||||
if (fa.fsx_xflags & ~EXT4_SUPPORTED_FS_XFLAGS)
|
||||
|
Reference in New Issue
Block a user