Merge tag 'idmapped-mounts-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-rpi.git] / fs / xfs / xfs_ioctl.c
index 248083e..99dfe89 100644 (file)
@@ -693,7 +693,8 @@ xfs_ioc_space(
 
        iattr.ia_valid = ATTR_SIZE;
        iattr.ia_size = bf->l_start;
-       error = xfs_vn_setattr_size(file_dentry(filp), &iattr);
+       error = xfs_vn_setattr_size(file_mnt_user_ns(filp), file_dentry(filp),
+                                   &iattr);
        if (error)
                goto out_unlock;
 
@@ -734,13 +735,15 @@ xfs_fsinumbers_fmt(
 
 STATIC int
 xfs_ioc_fsbulkstat(
-       xfs_mount_t             *mp,
+       struct file             *file,
        unsigned int            cmd,
        void                    __user *arg)
 {
+       struct xfs_mount        *mp = XFS_I(file_inode(file))->i_mount;
        struct xfs_fsop_bulkreq bulkreq;
        struct xfs_ibulk        breq = {
                .mp             = mp,
+               .mnt_userns     = file_mnt_user_ns(file),
                .ocount         = 0,
        };
        xfs_ino_t               lastino;
@@ -908,13 +911,15 @@ xfs_bulk_ireq_teardown(
 /* Handle the v5 bulkstat ioctl. */
 STATIC int
 xfs_ioc_bulkstat(
-       struct xfs_mount                *mp,
+       struct file                     *file,
        unsigned int                    cmd,
        struct xfs_bulkstat_req __user  *arg)
 {
+       struct xfs_mount                *mp = XFS_I(file_inode(file))->i_mount;
        struct xfs_bulk_ireq            hdr;
        struct xfs_ibulk                breq = {
                .mp                     = mp,
+               .mnt_userns             = file_mnt_user_ns(file),
        };
        int                             error;
 
@@ -1275,9 +1280,10 @@ xfs_ioctl_setattr_prepare_dax(
  */
 static struct xfs_trans *
 xfs_ioctl_setattr_get_trans(
-       struct xfs_inode        *ip,
+       struct file             *file,
        struct xfs_dquot        *pdqp)
 {
+       struct xfs_inode        *ip = XFS_I(file_inode(file));
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_trans        *tp;
        int                     error = -EROFS;
@@ -1299,7 +1305,7 @@ xfs_ioctl_setattr_get_trans(
         * The user ID of the calling process must be equal to the file owner
         * ID, except in cases where the CAP_FSETID capability is applicable.
         */
-       if (!inode_owner_or_capable(VFS_I(ip))) {
+       if (!inode_owner_or_capable(file_mnt_user_ns(file), VFS_I(ip))) {
                error = -EPERM;
                goto out_cancel;
        }
@@ -1427,9 +1433,11 @@ xfs_ioctl_setattr_check_projid(
 
 STATIC int
 xfs_ioctl_setattr(
-       xfs_inode_t             *ip,
+       struct file             *file,
        struct fsxattr          *fa)
 {
+       struct user_namespace   *mnt_userns = file_mnt_user_ns(file);
+       struct xfs_inode        *ip = XFS_I(file_inode(file));
        struct fsxattr          old_fa;
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_trans        *tp;
@@ -1461,7 +1469,7 @@ xfs_ioctl_setattr(
 
        xfs_ioctl_setattr_prepare_dax(ip, fa);
 
-       tp = xfs_ioctl_setattr_get_trans(ip, pdqp);
+       tp = xfs_ioctl_setattr_get_trans(file, pdqp);
        if (IS_ERR(tp)) {
                error = PTR_ERR(tp);
                goto error_free_dquots;
@@ -1493,7 +1501,7 @@ xfs_ioctl_setattr(
         */
 
        if ((VFS_I(ip)->i_mode & (S_ISUID|S_ISGID)) &&
-           !capable_wrt_inode_uidgid(VFS_I(ip), CAP_FSETID))
+           !capable_wrt_inode_uidgid(mnt_userns, VFS_I(ip), CAP_FSETID))
                VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID);
 
        /* Change the ownerships and register project quota modifications */
@@ -1540,7 +1548,6 @@ error_free_dquots:
 
 STATIC int
 xfs_ioc_fssetxattr(
-       xfs_inode_t             *ip,
        struct file             *filp,
        void                    __user *arg)
 {
@@ -1553,7 +1560,7 @@ xfs_ioc_fssetxattr(
        error = mnt_want_write_file(filp);
        if (error)
                return error;
-       error = xfs_ioctl_setattr(ip, &fa);
+       error = xfs_ioctl_setattr(filp, &fa);
        mnt_drop_write_file(filp);
        return error;
 }
@@ -1599,7 +1606,7 @@ xfs_ioc_setxflags(
 
        xfs_ioctl_setattr_prepare_dax(ip, &fa);
 
-       tp = xfs_ioctl_setattr_get_trans(ip, NULL);
+       tp = xfs_ioctl_setattr_get_trans(filp, NULL);
        if (IS_ERR(tp)) {
                error = PTR_ERR(tp);
                goto out_drop_write;
@@ -2110,10 +2117,10 @@ xfs_file_ioctl(
        case XFS_IOC_FSBULKSTAT_SINGLE:
        case XFS_IOC_FSBULKSTAT:
        case XFS_IOC_FSINUMBERS:
-               return xfs_ioc_fsbulkstat(mp, cmd, arg);
+               return xfs_ioc_fsbulkstat(filp, cmd, arg);
 
        case XFS_IOC_BULKSTAT:
-               return xfs_ioc_bulkstat(mp, cmd, arg);
+               return xfs_ioc_bulkstat(filp, cmd, arg);
        case XFS_IOC_INUMBERS:
                return xfs_ioc_inumbers(mp, cmd, arg);
 
@@ -2135,7 +2142,7 @@ xfs_file_ioctl(
        case XFS_IOC_FSGETXATTRA:
                return xfs_ioc_fsgetxattr(ip, 1, arg);
        case XFS_IOC_FSSETXATTR:
-               return xfs_ioc_fssetxattr(ip, filp, arg);
+               return xfs_ioc_fssetxattr(filp, arg);
        case XFS_IOC_GETXFLAGS:
                return xfs_ioc_getxflags(ip, arg);
        case XFS_IOC_SETXFLAGS: