This is a note to let you know that I've just added the patch titled xfs: don't set v3 xflags for v2 inodes to the 4.13-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xfs-don-t-set-v3-xflags-for-v2-inodes.patch and it can be found in the queue-4.13 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Mon Sep 18 10:25:08 CEST 2017 From: Christoph Hellwig <hch@xxxxxx> Date: Sun, 17 Sep 2017 14:06:29 -0700 Subject: xfs: don't set v3 xflags for v2 inodes To: stable@xxxxxxxxxxxxxxx Cc: linux-xfs@xxxxxxxxxxxxxxx, "Darrick J . Wong" <darrick.wong@xxxxxxxxxx> Message-ID: <20170917210631.10725-24-hch@xxxxxx> From: Christoph Hellwig <hch@xxxxxx> commit dd60687ee541ca3f6df8758f38e6f22f57c42a37 upstream. Reject attempts to set XFLAGS that correspond to di_flags2 inode flags if the inode isn't a v3 inode, because di_flags2 only exists on v3. Signed-off-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/xfs/xfs_ioctl.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -931,16 +931,15 @@ xfs_ioc_fsgetxattr( return 0; } -STATIC void -xfs_set_diflags( +STATIC uint16_t +xfs_flags2diflags( struct xfs_inode *ip, unsigned int xflags) { - unsigned int di_flags; - uint64_t di_flags2; - /* can't set PREALLOC this way, just preserve it */ - di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC); + uint16_t di_flags = + (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC); + if (xflags & FS_XFLAG_IMMUTABLE) di_flags |= XFS_DIFLAG_IMMUTABLE; if (xflags & FS_XFLAG_APPEND) @@ -970,19 +969,24 @@ xfs_set_diflags( if (xflags & FS_XFLAG_EXTSIZE) di_flags |= XFS_DIFLAG_EXTSIZE; } - ip->i_d.di_flags = di_flags; - /* diflags2 only valid for v3 inodes. */ - if (ip->i_d.di_version < 3) - return; + return di_flags; +} + +STATIC uint64_t +xfs_flags2diflags2( + struct xfs_inode *ip, + unsigned int xflags) +{ + uint64_t di_flags2 = + (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK); - di_flags2 = (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK); if (xflags & FS_XFLAG_DAX) di_flags2 |= XFS_DIFLAG2_DAX; if (xflags & FS_XFLAG_COWEXTSIZE) di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; - ip->i_d.di_flags2 = di_flags2; + return di_flags2; } STATIC void @@ -1023,6 +1027,7 @@ xfs_ioctl_setattr_xflags( struct fsxattr *fa) { struct xfs_mount *mp = ip->i_mount; + uint64_t di_flags2; /* Can't change realtime flag if any extents are allocated. */ if ((ip->i_d.di_nextents || ip->i_delayed_blks) && @@ -1053,7 +1058,14 @@ xfs_ioctl_setattr_xflags( !capable(CAP_LINUX_IMMUTABLE)) return -EPERM; - xfs_set_diflags(ip, fa->fsx_xflags); + /* diflags2 only valid for v3 inodes. */ + di_flags2 = xfs_flags2diflags2(ip, fa->fsx_xflags); + if (di_flags2 && ip->i_d.di_version < 3) + return -EINVAL; + + ip->i_d.di_flags = xfs_flags2diflags(ip, fa->fsx_xflags); + ip->i_d.di_flags2 = di_flags2; + xfs_diflags_to_linux(ip); xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); Patches currently in stable-queue which might be from hch@xxxxxx are queue-4.13/xfs-open-code-xfs_buf_item_dirty.patch queue-4.13/xfs-properly-retry-failed-inode-items-in-case-of-error-during-buffer-writeback.patch queue-4.13/xfs-use-kmem_free-to-free-return-value-of-kmem_zalloc.patch queue-4.13/xfs-add-infrastructure-needed-for-error-propagation-during-buffer-io-failure.patch queue-4.13/xfs-don-t-set-v3-xflags-for-v2-inodes.patch queue-4.13/xfs-toggle-readonly-state-around-xfs_log_mount_finish.patch queue-4.13/xfs-fix-log-recovery-corruption-error-due-to-tail-overwrite.patch queue-4.13/xfs-move-bmbt-owner-change-to-last-step-of-extent-swap.patch queue-4.13/xfs-check-for-race-with-xfs_reclaim_inode-in-xfs_ifree_cluster.patch queue-4.13/xfs-always-verify-the-log-tail-during-recovery.patch queue-4.13/xfs-open-code-end_buffer_async_write-in-xfs_finish_page_writeback.patch queue-4.13/xfs-relog-dirty-buffers-during-swapext-bmbt-owner-change.patch queue-4.13/xfs-disable-per-inode-dax-flag.patch queue-4.13/xfs-refactor-buffer-logging-into-buffer-dirtying-helper.patch queue-4.13/xfs-fix-recovery-failure-when-log-record-header-wraps-log-end.patch queue-4.13/xfs-skip-bmbt-block-ino-validation-during-owner-change.patch queue-4.13/xfs-don-t-log-dirty-ranges-for-ordered-buffers.patch queue-4.13/xfs-stop-searching-for-free-slots-in-an-inode-chunk-when-there-are-none.patch queue-4.13/xfs-fix-incorrect-log_flushed-on-fsync.patch queue-4.13/xfs-evict-all-inodes-involved-with-log-redo-item.patch queue-4.13/xfs-write-unmount-record-for-ro-mounts.patch queue-4.13/xfs-remove-unnecessary-dirty-bli-format-check-for-ordered-bufs.patch queue-4.13/xfs-disallow-marking-previously-dirty-buffers-as-ordered.patch queue-4.13/xfs-handle-efscorrupted-during-head-tail-verification.patch queue-4.13/xfs-ordered-buffer-log-items-are-never-formatted.patch