xfs: check for invalid inode reflink flags
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 3 Oct 2016 16:11:50 +0000 (09:11 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 5 Oct 2016 23:26:31 +0000 (16:26 -0700)
We don't support sharing blocks on the realtime device.  Flag inodes
with the reflink or cowextsize flags set when the reflink feature is
disabled.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/xfs_ioctl.c

index a3e803823a19abe3716ad8f1317c58ff3b3a431e..f1b9d97c540fd69a2493aed849ffbe8801e611fa 100644 (file)
@@ -375,6 +375,9 @@ xfs_dinode_verify(
        struct xfs_inode        *ip,
        struct xfs_dinode       *dip)
 {
+       uint16_t                flags;
+       uint64_t                flags2;
+
        if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC))
                return false;
 
@@ -391,6 +394,19 @@ xfs_dinode_verify(
                return false;
        if (!uuid_equal(&dip->di_uuid, &mp->m_sb.sb_meta_uuid))
                return false;
+
+       flags = be16_to_cpu(dip->di_flags);
+       flags2 = be64_to_cpu(dip->di_flags2);
+
+       /* don't allow reflink/cowextsize if we don't have reflink */
+       if ((flags2 & (XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE)) &&
+            !xfs_sb_version_hasreflink(&mp->m_sb))
+               return false;
+
+       /* don't let reflink and realtime mix */
+       if ((flags2 & XFS_DIFLAG2_REFLINK) && (flags & XFS_DIFLAG_REALTIME))
+               return false;
+
        return true;
 }
 
index 1388a1275dc8332590c8a073579ea9d348167435..c65d9eacf54daeb1336a104199cdea14c7b42fb1 100644 (file)
@@ -1034,6 +1034,10 @@ xfs_ioctl_setattr_xflags(
                        return -EINVAL;
        }
 
+       /* Don't allow us to set realtime mode for a reflinked file. */
+       if ((fa->fsx_xflags & FS_XFLAG_REALTIME) && xfs_is_reflink_inode(ip))
+               return -EINVAL;
+
        /*
         * Can't modify an immutable/append-only file unless
         * we have appropriate permission.