linux-stable/fs/xfs/libxfs
Gao Xiang 7f2b8046da xfs: fix forkoff miscalculation related to XFS_LITINO(mp)
commit ada49d64fb upstream.

Currently, commit e9e2eae89d dropped a (int) decoration from
XFS_LITINO(mp), and since sizeof() expression is also involved,
the result of XFS_LITINO(mp) is simply as the size_t type
(commonly unsigned long).

Considering the expression in xfs_attr_shortform_bytesfit():
  offset = (XFS_LITINO(mp) - bytes) >> 3;
let "bytes" be (int)340, and
    "XFS_LITINO(mp)" be (unsigned long)336.

on 64-bit platform, the expression is
  offset = ((unsigned long)336 - (int)340) >> 3 =
           (int)(0xfffffffffffffffcUL >> 3) = -1

but on 32-bit platform, the expression is
  offset = ((unsigned long)336 - (int)340) >> 3 =
           (int)(0xfffffffcUL >> 3) = 0x1fffffff
instead.

so offset becomes a large positive number on 32-bit platform, and
cause xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
  "ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

assertion failure in xfs_idata_realloc(), which was also the root
cause of the original bugreport from Dennis, see:
   https://bugzilla.redhat.com/show_bug.cgi?id=1894177

And it can also be manually triggered with the following commands:
  $ touch a;
  $ setfattr -n user.0 -v "`seq 0 80`" a;
  $ setfattr -n user.1 -v "`seq 0 80`" a

on 32-bit platform.

Fix the case in xfs_attr_shortform_bytesfit() by bailing out
"XFS_LITINO(mp) < bytes" in advance suggested by Eric and a misleading
comment together with this bugfix suggested by Darrick. It seems the
other users of XFS_LITINO(mp) are not impacted.

Fixes: e9e2eae89d ("xfs: only check the superblock version for dinode size calculation")
Cc: <stable@vger.kernel.org> # 5.7+
Reported-and-tested-by: Dennis Gilmore <dgilmore@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-26 11:24:06 +02:00
..
xfs_ag.c
xfs_ag.h
xfs_ag_resv.c
xfs_ag_resv.h
xfs_alloc.c xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_alloc.h
xfs_alloc_btree.c
xfs_alloc_btree.h
xfs_attr.c xfs: fix misuse of the XFS_ATTR_INCOMPLETE flag 2022-10-07 09:16:56 +02:00
xfs_attr.h
xfs_attr_leaf.c xfs: fix forkoff miscalculation related to XFS_LITINO(mp) 2023-04-26 11:24:06 +02:00
xfs_attr_leaf.h xfs: streamline xfs_attr3_leaf_inactive 2022-10-07 09:16:57 +02:00
xfs_attr_remote.c xfs: fix memory corruption during remote attr value buffer invalidation 2022-10-07 09:16:57 +02:00
xfs_attr_remote.h xfs: refactor remote attr value buffer invalidation 2022-10-07 09:16:56 +02:00
xfs_attr_sf.h
xfs_bit.c
xfs_bit.h
xfs_bmap.c xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_bmap.h xfs: redesign the reflink remap loop to fix blkres depletion crash 2022-11-25 17:42:03 +01:00
xfs_bmap_btree.c
xfs_bmap_btree.h
xfs_btree.c xfs: consider shutdown in bmapbt cursor delete assert 2023-04-20 12:07:38 +02:00
xfs_btree.h
xfs_cksum.h
xfs_da_btree.c xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_da_btree.h xfs: move incore structures out of xfs_da_format.h 2022-10-07 09:16:57 +02:00
xfs_da_format.c xfs: move incore structures out of xfs_da_format.h 2022-10-07 09:16:57 +02:00
xfs_da_format.h xfs: move incore structures out of xfs_da_format.h 2022-10-07 09:16:57 +02:00
xfs_defer.c xfs: only relog deferred intent items if free space in the log gets low 2023-02-22 12:50:37 +01:00
xfs_defer.h xfs: fix an incore inode UAF in xfs_bui_recover 2023-02-22 12:50:37 +01:00
xfs_dir2.c xfs: always log corruption errors 2022-09-28 11:04:10 +02:00
xfs_dir2.h xfs: move incore structures out of xfs_da_format.h 2022-10-07 09:16:57 +02:00
xfs_dir2_block.c xfs: check owner of dir3 blocks 2022-10-29 10:20:33 +02:00
xfs_dir2_data.c xfs: check owner of dir3 data blocks 2022-10-29 10:20:33 +02:00
xfs_dir2_leaf.c xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_dir2_node.c xfs: fix buffer corruption reporting when xfs_dir3_free_header_check fails 2022-10-29 10:20:33 +02:00
xfs_dir2_priv.h xfs: move incore structures out of xfs_da_format.h 2022-10-07 09:16:57 +02:00
xfs_dir2_sf.c xfs: fix an ABBA deadlock in xfs_rename 2022-09-28 11:04:11 +02:00
xfs_dquot_buf.c xfs: remove the xfs_disk_dquot_t and xfs_dquot_t 2022-10-29 10:20:33 +02:00
xfs_errortag.h
xfs_format.h xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_fs.h
xfs_health.h
xfs_ialloc.c xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_ialloc.h xfs: don't commit sunit/swidth updates to disk if that would cause repair failures 2022-09-28 11:04:11 +02:00
xfs_ialloc_btree.c
xfs_ialloc_btree.h
xfs_iext_tree.c xfs: fix inode fork extent count overflow 2020-10-01 13:17:13 +02:00
xfs_inode_buf.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_inode_buf.h xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_inode_fork.c xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_inode_fork.h xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_log_format.h xfs: only check the superblock version for dinode size calculation 2023-04-20 12:07:37 +02:00
xfs_log_recover.h
xfs_log_rlimit.c
xfs_quota_defs.h
xfs_refcount.c xfs: always log corruption errors 2022-09-28 11:04:10 +02:00
xfs_refcount.h
xfs_refcount_btree.c
xfs_refcount_btree.h
xfs_rmap.c xfs: fix flags argument to rmap lookup when converting shared file rmaps 2020-11-18 19:20:27 +01:00
xfs_rmap.h
xfs_rmap_btree.c xfs: revert "xfs: fix rmap key and record comparison functions" 2020-11-24 13:29:18 +01:00
xfs_rmap_btree.h
xfs_rtbitmap.c xfs: rename xfs_bmap_is_real_extent to is_written_extent 2022-11-25 17:42:03 +01:00
xfs_sb.c
xfs_sb.h
xfs_shared.h xfs: preserve rmapbt swapext block reservation from freed blocks 2022-11-25 17:42:03 +01:00
xfs_symlink_remote.c
xfs_trans_inode.c xfs: remove the xfs_inode_log_item_t typedef 2023-02-22 12:50:35 +01:00
xfs_trans_resv.c xfs: add a new xfs_sb_version_has_v3inode helper 2023-04-20 12:07:37 +02:00
xfs_trans_resv.h
xfs_trans_space.h xfs: fix off-by-one in inode alloc block reservation calculation 2020-09-17 13:47:46 +02:00
xfs_types.c
xfs_types.h