xfs_ioctl.c (21cb47be6fb9ece7e6ee63f6780986faa384a77c) xfs_ioctl.c (f736d93d76d3e97d6986c6d26c8eaa32536ccc5c)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6#include "xfs.h"
7#include "xfs_fs.h"
8#include "xfs_shared.h"

--- 679 unchanged lines hidden (view full) ---

688 error = xfs_alloc_file_space(ip, XFS_ISIZE(ip),
689 bf->l_start - XFS_ISIZE(ip), 0);
690 if (error)
691 goto out_unlock;
692 }
693
694 iattr.ia_valid = ATTR_SIZE;
695 iattr.ia_size = bf->l_start;
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6#include "xfs.h"
7#include "xfs_fs.h"
8#include "xfs_shared.h"

--- 679 unchanged lines hidden (view full) ---

688 error = xfs_alloc_file_space(ip, XFS_ISIZE(ip),
689 bf->l_start - XFS_ISIZE(ip), 0);
690 if (error)
691 goto out_unlock;
692 }
693
694 iattr.ia_valid = ATTR_SIZE;
695 iattr.ia_size = bf->l_start;
696 error = xfs_vn_setattr_size(file_dentry(filp), &iattr);
696 error = xfs_vn_setattr_size(file_mnt_user_ns(filp), file_dentry(filp),
697 &iattr);
697 if (error)
698 goto out_unlock;
699
700 error = xfs_update_prealloc_flags(ip, flags);
701
702out_unlock:
703 xfs_iunlock(ip, iolock);
704 mnt_drop_write_file(filp);

--- 24 unchanged lines hidden (view full) ---

729 xfs_inumbers_to_inogrp(&ig1, igrp);
730 if (copy_to_user(breq->ubuffer, &ig1, sizeof(struct xfs_inogrp)))
731 return -EFAULT;
732 return xfs_ibulk_advance(breq, sizeof(struct xfs_inogrp));
733}
734
735STATIC int
736xfs_ioc_fsbulkstat(
698 if (error)
699 goto out_unlock;
700
701 error = xfs_update_prealloc_flags(ip, flags);
702
703out_unlock:
704 xfs_iunlock(ip, iolock);
705 mnt_drop_write_file(filp);

--- 24 unchanged lines hidden (view full) ---

730 xfs_inumbers_to_inogrp(&ig1, igrp);
731 if (copy_to_user(breq->ubuffer, &ig1, sizeof(struct xfs_inogrp)))
732 return -EFAULT;
733 return xfs_ibulk_advance(breq, sizeof(struct xfs_inogrp));
734}
735
736STATIC int
737xfs_ioc_fsbulkstat(
737 xfs_mount_t *mp,
738 struct file *file,
738 unsigned int cmd,
739 void __user *arg)
740{
739 unsigned int cmd,
740 void __user *arg)
741{
742 struct xfs_mount *mp = XFS_I(file_inode(file))->i_mount;
741 struct xfs_fsop_bulkreq bulkreq;
742 struct xfs_ibulk breq = {
743 .mp = mp,
743 struct xfs_fsop_bulkreq bulkreq;
744 struct xfs_ibulk breq = {
745 .mp = mp,
746 .mnt_userns = file_mnt_user_ns(file),
744 .ocount = 0,
745 };
746 xfs_ino_t lastino;
747 int error;
748
749 /* done = 1 if there are more stats to get and if bulkstat */
750 /* should be called again (unused here, but used in dmapi) */
751

--- 151 unchanged lines hidden (view full) ---

903{
904 hdr->ino = breq->startino;
905 hdr->ocount = breq->ocount;
906}
907
908/* Handle the v5 bulkstat ioctl. */
909STATIC int
910xfs_ioc_bulkstat(
747 .ocount = 0,
748 };
749 xfs_ino_t lastino;
750 int error;
751
752 /* done = 1 if there are more stats to get and if bulkstat */
753 /* should be called again (unused here, but used in dmapi) */
754

--- 151 unchanged lines hidden (view full) ---

906{
907 hdr->ino = breq->startino;
908 hdr->ocount = breq->ocount;
909}
910
911/* Handle the v5 bulkstat ioctl. */
912STATIC int
913xfs_ioc_bulkstat(
911 struct xfs_mount *mp,
914 struct file *file,
912 unsigned int cmd,
913 struct xfs_bulkstat_req __user *arg)
914{
915 unsigned int cmd,
916 struct xfs_bulkstat_req __user *arg)
917{
918 struct xfs_mount *mp = XFS_I(file_inode(file))->i_mount;
915 struct xfs_bulk_ireq hdr;
916 struct xfs_ibulk breq = {
917 .mp = mp,
919 struct xfs_bulk_ireq hdr;
920 struct xfs_ibulk breq = {
921 .mp = mp,
922 .mnt_userns = file_mnt_user_ns(file),
918 };
919 int error;
920
921 if (!capable(CAP_SYS_ADMIN))
922 return -EPERM;
923
924 if (XFS_FORCED_SHUTDOWN(mp))
925 return -EIO;

--- 344 unchanged lines hidden (view full) ---

1270/*
1271 * Set up the transaction structure for the setattr operation, checking that we
1272 * have permission to do so. On success, return a clean transaction and the
1273 * inode locked exclusively ready for further operation specific checks. On
1274 * failure, return an error without modifying or locking the inode.
1275 */
1276static struct xfs_trans *
1277xfs_ioctl_setattr_get_trans(
923 };
924 int error;
925
926 if (!capable(CAP_SYS_ADMIN))
927 return -EPERM;
928
929 if (XFS_FORCED_SHUTDOWN(mp))
930 return -EIO;

--- 344 unchanged lines hidden (view full) ---

1275/*
1276 * Set up the transaction structure for the setattr operation, checking that we
1277 * have permission to do so. On success, return a clean transaction and the
1278 * inode locked exclusively ready for further operation specific checks. On
1279 * failure, return an error without modifying or locking the inode.
1280 */
1281static struct xfs_trans *
1282xfs_ioctl_setattr_get_trans(
1278 struct xfs_inode *ip)
1283 struct file *file)
1279{
1284{
1285 struct xfs_inode *ip = XFS_I(file_inode(file));
1280 struct xfs_mount *mp = ip->i_mount;
1281 struct xfs_trans *tp;
1282 int error = -EROFS;
1283
1284 if (mp->m_flags & XFS_MOUNT_RDONLY)
1285 goto out_unlock;
1286 error = -EIO;
1287 if (XFS_FORCED_SHUTDOWN(mp))

--- 7 unchanged lines hidden (view full) ---

1295 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1296
1297 /*
1298 * CAP_FOWNER overrides the following restrictions:
1299 *
1300 * The user ID of the calling process must be equal to the file owner
1301 * ID, except in cases where the CAP_FSETID capability is applicable.
1302 */
1286 struct xfs_mount *mp = ip->i_mount;
1287 struct xfs_trans *tp;
1288 int error = -EROFS;
1289
1290 if (mp->m_flags & XFS_MOUNT_RDONLY)
1291 goto out_unlock;
1292 error = -EIO;
1293 if (XFS_FORCED_SHUTDOWN(mp))

--- 7 unchanged lines hidden (view full) ---

1301 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1302
1303 /*
1304 * CAP_FOWNER overrides the following restrictions:
1305 *
1306 * The user ID of the calling process must be equal to the file owner
1307 * ID, except in cases where the CAP_FSETID capability is applicable.
1308 */
1303 if (!inode_owner_or_capable(&init_user_ns, VFS_I(ip))) {
1309 if (!inode_owner_or_capable(file_mnt_user_ns(file), VFS_I(ip))) {
1304 error = -EPERM;
1305 goto out_cancel;
1306 }
1307
1308 if (mp->m_flags & XFS_MOUNT_WSYNC)
1309 xfs_trans_set_sync(tp);
1310
1311 return tp;

--- 111 unchanged lines hidden (view full) ---

1423 if (fa->fsx_projid > (uint16_t)-1 &&
1424 !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb))
1425 return -EINVAL;
1426 return 0;
1427}
1428
1429STATIC int
1430xfs_ioctl_setattr(
1310 error = -EPERM;
1311 goto out_cancel;
1312 }
1313
1314 if (mp->m_flags & XFS_MOUNT_WSYNC)
1315 xfs_trans_set_sync(tp);
1316
1317 return tp;

--- 111 unchanged lines hidden (view full) ---

1429 if (fa->fsx_projid > (uint16_t)-1 &&
1430 !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb))
1431 return -EINVAL;
1432 return 0;
1433}
1434
1435STATIC int
1436xfs_ioctl_setattr(
1431 xfs_inode_t *ip,
1437 struct file *file,
1432 struct fsxattr *fa)
1433{
1438 struct fsxattr *fa)
1439{
1440 struct user_namespace *mnt_userns = file_mnt_user_ns(file);
1441 struct xfs_inode *ip = XFS_I(file_inode(file));
1434 struct fsxattr old_fa;
1435 struct xfs_mount *mp = ip->i_mount;
1436 struct xfs_trans *tp;
1437 struct xfs_dquot *pdqp = NULL;
1438 struct xfs_dquot *olddquot = NULL;
1439 int code;
1440
1441 trace_xfs_ioctl_setattr(ip);

--- 15 unchanged lines hidden (view full) ---

1457 VFS_I(ip)->i_gid, fa->fsx_projid,
1458 XFS_QMOPT_PQUOTA, NULL, NULL, &pdqp);
1459 if (code)
1460 return code;
1461 }
1462
1463 xfs_ioctl_setattr_prepare_dax(ip, fa);
1464
1442 struct fsxattr old_fa;
1443 struct xfs_mount *mp = ip->i_mount;
1444 struct xfs_trans *tp;
1445 struct xfs_dquot *pdqp = NULL;
1446 struct xfs_dquot *olddquot = NULL;
1447 int code;
1448
1449 trace_xfs_ioctl_setattr(ip);

--- 15 unchanged lines hidden (view full) ---

1465 VFS_I(ip)->i_gid, fa->fsx_projid,
1466 XFS_QMOPT_PQUOTA, NULL, NULL, &pdqp);
1467 if (code)
1468 return code;
1469 }
1470
1471 xfs_ioctl_setattr_prepare_dax(ip, fa);
1472
1465 tp = xfs_ioctl_setattr_get_trans(ip);
1473 tp = xfs_ioctl_setattr_get_trans(file);
1466 if (IS_ERR(tp)) {
1467 code = PTR_ERR(tp);
1468 goto error_free_dquots;
1469 }
1470
1471 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) &&
1472 ip->i_d.di_projid != fa->fsx_projid) {
1473 code = xfs_qm_vop_chown_reserve(tp, ip, NULL, NULL, pdqp,

--- 23 unchanged lines hidden (view full) ---

1497 * Change file ownership. Must be the owner or privileged. CAP_FSETID
1498 * overrides the following restrictions:
1499 *
1500 * The set-user-ID and set-group-ID bits of a file will be cleared upon
1501 * successful return from chown()
1502 */
1503
1504 if ((VFS_I(ip)->i_mode & (S_ISUID|S_ISGID)) &&
1474 if (IS_ERR(tp)) {
1475 code = PTR_ERR(tp);
1476 goto error_free_dquots;
1477 }
1478
1479 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) &&
1480 ip->i_d.di_projid != fa->fsx_projid) {
1481 code = xfs_qm_vop_chown_reserve(tp, ip, NULL, NULL, pdqp,

--- 23 unchanged lines hidden (view full) ---

1505 * Change file ownership. Must be the owner or privileged. CAP_FSETID
1506 * overrides the following restrictions:
1507 *
1508 * The set-user-ID and set-group-ID bits of a file will be cleared upon
1509 * successful return from chown()
1510 */
1511
1512 if ((VFS_I(ip)->i_mode & (S_ISUID|S_ISGID)) &&
1505 !capable_wrt_inode_uidgid(&init_user_ns, VFS_I(ip), CAP_FSETID))
1513 !capable_wrt_inode_uidgid(mnt_userns, VFS_I(ip), CAP_FSETID))
1506 VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID);
1507
1508 /* Change the ownerships and register project quota modifications */
1509 if (ip->i_d.di_projid != fa->fsx_projid) {
1510 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) {
1511 olddquot = xfs_qm_vop_chown(tp, ip,
1512 &ip->i_pdquot, pdqp);
1513 }

--- 30 unchanged lines hidden (view full) ---

1544 xfs_trans_cancel(tp);
1545error_free_dquots:
1546 xfs_qm_dqrele(pdqp);
1547 return code;
1548}
1549
1550STATIC int
1551xfs_ioc_fssetxattr(
1514 VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID);
1515
1516 /* Change the ownerships and register project quota modifications */
1517 if (ip->i_d.di_projid != fa->fsx_projid) {
1518 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) {
1519 olddquot = xfs_qm_vop_chown(tp, ip,
1520 &ip->i_pdquot, pdqp);
1521 }

--- 30 unchanged lines hidden (view full) ---

1552 xfs_trans_cancel(tp);
1553error_free_dquots:
1554 xfs_qm_dqrele(pdqp);
1555 return code;
1556}
1557
1558STATIC int
1559xfs_ioc_fssetxattr(
1552 xfs_inode_t *ip,
1553 struct file *filp,
1554 void __user *arg)
1555{
1556 struct fsxattr fa;
1557 int error;
1558
1559 if (copy_from_user(&fa, arg, sizeof(fa)))
1560 return -EFAULT;
1561
1562 error = mnt_want_write_file(filp);
1563 if (error)
1564 return error;
1560 struct file *filp,
1561 void __user *arg)
1562{
1563 struct fsxattr fa;
1564 int error;
1565
1566 if (copy_from_user(&fa, arg, sizeof(fa)))
1567 return -EFAULT;
1568
1569 error = mnt_want_write_file(filp);
1570 if (error)
1571 return error;
1565 error = xfs_ioctl_setattr(ip, &fa);
1572 error = xfs_ioctl_setattr(filp, &fa);
1566 mnt_drop_write_file(filp);
1567 return error;
1568}
1569
1570STATIC int
1571xfs_ioc_getxflags(
1572 xfs_inode_t *ip,
1573 void __user *arg)

--- 29 unchanged lines hidden (view full) ---

1603 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
1604
1605 error = mnt_want_write_file(filp);
1606 if (error)
1607 return error;
1608
1609 xfs_ioctl_setattr_prepare_dax(ip, &fa);
1610
1573 mnt_drop_write_file(filp);
1574 return error;
1575}
1576
1577STATIC int
1578xfs_ioc_getxflags(
1579 xfs_inode_t *ip,
1580 void __user *arg)

--- 29 unchanged lines hidden (view full) ---

1610 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
1611
1612 error = mnt_want_write_file(filp);
1613 if (error)
1614 return error;
1615
1616 xfs_ioctl_setattr_prepare_dax(ip, &fa);
1617
1611 tp = xfs_ioctl_setattr_get_trans(ip);
1618 tp = xfs_ioctl_setattr_get_trans(filp);
1612 if (IS_ERR(tp)) {
1613 error = PTR_ERR(tp);
1614 goto out_drop_write;
1615 }
1616
1617 xfs_fill_fsxattr(ip, false, &old_fa);
1618 error = vfs_ioc_fssetxattr_check(VFS_I(ip), &old_fa, &fa);
1619 if (error) {

--- 494 unchanged lines hidden (view full) ---

2114 if (copy_to_user(arg, &da, sizeof(da)))
2115 return -EFAULT;
2116 return 0;
2117 }
2118
2119 case XFS_IOC_FSBULKSTAT_SINGLE:
2120 case XFS_IOC_FSBULKSTAT:
2121 case XFS_IOC_FSINUMBERS:
1619 if (IS_ERR(tp)) {
1620 error = PTR_ERR(tp);
1621 goto out_drop_write;
1622 }
1623
1624 xfs_fill_fsxattr(ip, false, &old_fa);
1625 error = vfs_ioc_fssetxattr_check(VFS_I(ip), &old_fa, &fa);
1626 if (error) {

--- 494 unchanged lines hidden (view full) ---

2121 if (copy_to_user(arg, &da, sizeof(da)))
2122 return -EFAULT;
2123 return 0;
2124 }
2125
2126 case XFS_IOC_FSBULKSTAT_SINGLE:
2127 case XFS_IOC_FSBULKSTAT:
2128 case XFS_IOC_FSINUMBERS:
2122 return xfs_ioc_fsbulkstat(mp, cmd, arg);
2129 return xfs_ioc_fsbulkstat(filp, cmd, arg);
2123
2124 case XFS_IOC_BULKSTAT:
2130
2131 case XFS_IOC_BULKSTAT:
2125 return xfs_ioc_bulkstat(mp, cmd, arg);
2132 return xfs_ioc_bulkstat(filp, cmd, arg);
2126 case XFS_IOC_INUMBERS:
2127 return xfs_ioc_inumbers(mp, cmd, arg);
2128
2129 case XFS_IOC_FSGEOMETRY_V1:
2130 return xfs_ioc_fsgeometry(mp, arg, 3);
2131 case XFS_IOC_FSGEOMETRY_V4:
2132 return xfs_ioc_fsgeometry(mp, arg, 4);
2133 case XFS_IOC_FSGEOMETRY:

--- 5 unchanged lines hidden (view full) ---

2139 case XFS_IOC_GETVERSION:
2140 return put_user(inode->i_generation, (int __user *)arg);
2141
2142 case XFS_IOC_FSGETXATTR:
2143 return xfs_ioc_fsgetxattr(ip, 0, arg);
2144 case XFS_IOC_FSGETXATTRA:
2145 return xfs_ioc_fsgetxattr(ip, 1, arg);
2146 case XFS_IOC_FSSETXATTR:
2133 case XFS_IOC_INUMBERS:
2134 return xfs_ioc_inumbers(mp, cmd, arg);
2135
2136 case XFS_IOC_FSGEOMETRY_V1:
2137 return xfs_ioc_fsgeometry(mp, arg, 3);
2138 case XFS_IOC_FSGEOMETRY_V4:
2139 return xfs_ioc_fsgeometry(mp, arg, 4);
2140 case XFS_IOC_FSGEOMETRY:

--- 5 unchanged lines hidden (view full) ---

2146 case XFS_IOC_GETVERSION:
2147 return put_user(inode->i_generation, (int __user *)arg);
2148
2149 case XFS_IOC_FSGETXATTR:
2150 return xfs_ioc_fsgetxattr(ip, 0, arg);
2151 case XFS_IOC_FSGETXATTRA:
2152 return xfs_ioc_fsgetxattr(ip, 1, arg);
2153 case XFS_IOC_FSSETXATTR:
2147 return xfs_ioc_fssetxattr(ip, filp, arg);
2154 return xfs_ioc_fssetxattr(filp, arg);
2148 case XFS_IOC_GETXFLAGS:
2149 return xfs_ioc_getxflags(ip, arg);
2150 case XFS_IOC_SETXFLAGS:
2151 return xfs_ioc_setxflags(ip, filp, arg);
2152
2153 case XFS_IOC_GETBMAP:
2154 case XFS_IOC_GETBMAPA:
2155 case XFS_IOC_GETBMAPX:

--- 205 unchanged lines hidden ---
2155 case XFS_IOC_GETXFLAGS:
2156 return xfs_ioc_getxflags(ip, arg);
2157 case XFS_IOC_SETXFLAGS:
2158 return xfs_ioc_setxflags(ip, filp, arg);
2159
2160 case XFS_IOC_GETBMAP:
2161 case XFS_IOC_GETBMAPA:
2162 case XFS_IOC_GETBMAPX:

--- 205 unchanged lines hidden ---