Commit 881ceebe authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nathan Scott

[XFS] Fix r/o check in xfs_ioc_space, fix checks on xfs_swapext validity.

SGI Modid: xfs-linux:xfs-kern:169135a
parent 83ea3f02
......@@ -850,6 +850,9 @@ xfs_ioctl(
case XFS_IOC_ERROR_INJECTION: {
xfs_error_injection_t in;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (copy_from_user(&in, (char *)arg, sizeof(in)))
return -XFS_ERROR(EFAULT);
......@@ -858,6 +861,9 @@ xfs_ioctl(
}
case XFS_IOC_ERROR_CLEARALL:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
error = xfs_errortag_clearall(mp);
return -error;
......@@ -882,7 +888,7 @@ xfs_ioc_space(
if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
return -XFS_ERROR(EPERM);
if (filp->f_flags & O_RDONLY)
if (!(filp->f_flags & FMODE_WRITE))
return -XFS_ERROR(EBADF);
if (vp->v_type != VREG)
......
......@@ -119,6 +119,11 @@ xfs_swapext(
tip = XFS_BHVTOI(tbdp);
}
if (ip->i_mount != tip->i_mount) {
error = XFS_ERROR(EINVAL);
goto error0;
}
if (ip->i_ino == tip->i_ino) {
error = XFS_ERROR(EINVAL);
goto error0;
......@@ -147,20 +152,17 @@ xfs_swapext(
xfs_lock_inodes(ips, 2, 0, lock_flags);
/* Check permissions */
if ((error = _MAC_XFS_IACCESS(ip, MACWRITE, NULL))) {
goto error0;
}
if ((error = _MAC_XFS_IACCESS(tip, MACWRITE, NULL))) {
error = xfs_iaccess(ip, S_IWUSR, NULL);
if (error)
goto error0;
}
if ((current_fsuid(cred) != ip->i_d.di_uid) &&
(error = xfs_iaccess(ip, S_IWUSR, NULL)) &&
!capable_cred(NULL, CAP_FOWNER)) {
error = xfs_iaccess(tip, S_IWUSR, NULL);
if (error)
goto error0;
}
if ((current_fsuid(cred) != tip->i_d.di_uid) &&
(error = xfs_iaccess(tip, S_IWUSR, NULL)) &&
!capable_cred(NULL, CAP_FOWNER)) {
/* Verify that both files have the same format */
if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
error = XFS_ERROR(EINVAL);
goto error0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment