xfs: don't allow reflinked dir/dev/fifo/socket/pipe files
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 3 Oct 2016 16:11:31 +0000 (09:11 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 5 Oct 2016 01:06:40 +0000 (18:06 -0700)
Only non-rt files can be reflinked, so check that when we load an
inode.  Also, don't leak the attr fork if there's a failure.

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

index bbcc8c7a44b3ffde66bf152583e87ebbd9763da7..7699a033dd3ca5a0b794d19480178db23c008c1f 100644 (file)
@@ -121,6 +121,26 @@ xfs_iformat_fork(
                return -EFSCORRUPTED;
        }
 
+       if (unlikely(xfs_is_reflink_inode(ip) &&
+           (VFS_I(ip)->i_mode & S_IFMT) != S_IFREG)) {
+               xfs_warn(ip->i_mount,
+                       "corrupt dinode %llu, wrong file type for reflink.",
+                       ip->i_ino);
+               XFS_CORRUPTION_ERROR("xfs_iformat(reflink)",
+                                    XFS_ERRLEVEL_LOW, ip->i_mount, dip);
+               return -EFSCORRUPTED;
+       }
+
+       if (unlikely(xfs_is_reflink_inode(ip) &&
+           (ip->i_d.di_flags & XFS_DIFLAG_REALTIME))) {
+               xfs_warn(ip->i_mount,
+                       "corrupt dinode %llu, has reflink+realtime flag set.",
+                       ip->i_ino);
+               XFS_CORRUPTION_ERROR("xfs_iformat(reflink)",
+                                    XFS_ERRLEVEL_LOW, ip->i_mount, dip);
+               return -EFSCORRUPTED;
+       }
+
        switch (VFS_I(ip)->i_mode & S_IFMT) {
        case S_IFIFO:
        case S_IFCHR:
@@ -208,7 +228,8 @@ xfs_iformat_fork(
                        XFS_CORRUPTION_ERROR("xfs_iformat(8)",
                                             XFS_ERRLEVEL_LOW,
                                             ip->i_mount, dip);
-                       return -EFSCORRUPTED;
+                       error = -EFSCORRUPTED;
+                       break;
                }
 
                error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK, size);