linux-stable/fs/xfs
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
..
libxfs xfs: fix forkoff miscalculation related to XFS_LITINO(mp) 2023-04-26 11:24:06 +02:00
scrub xfs: strengthen rmap record flags checking 2020-11-24 13:29:18 +01:00
Kconfig
kmem.c
kmem.h
Makefile
mrlock.h
xfs.h
xfs_acl.c xfs: remove the kuid/kgid conversion wrappers 2023-04-20 12:07:37 +02:00
xfs_acl.h
xfs_aops.c xfs: fix missing CoW blocks writeback conversion retry 2023-02-22 12:50:38 +01:00
xfs_aops.h
xfs_attr_inactive.c xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_attr_list.c xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_bio_io.c
xfs_bmap_item.c xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_bmap_item.h xfs: proper replay of deferred ops queued during log recovery 2023-02-22 12:50:36 +01:00
xfs_bmap_util.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_bmap_util.h
xfs_buf.c xfs: xfs_buf_corruption_error should take __this_address 2022-10-29 10:20:33 +02:00
xfs_buf.h xfs: add a function to deal with corrupt buffers post-verifiers 2022-10-29 10:20:33 +02:00
xfs_buf_item.c xfs: add a new xfs_sb_version_has_v3inode helper 2023-04-20 12:07:37 +02:00
xfs_buf_item.h
xfs_dir2_readdir.c
xfs_discard.c
xfs_discard.h
xfs_dquot.c xfs: remove the kuid/kgid conversion wrappers 2023-04-20 12:07:37 +02:00
xfs_dquot.h xfs: remove the xfs_dq_logitem_t typedef 2022-10-29 10:20:33 +02:00
xfs_dquot_item.c xfs: trylock underlying buffer on dquot flush 2022-10-29 10:20:34 +02:00
xfs_dquot_item.h xfs: factor out quotaoff intent AIL removal and memory free 2022-10-29 10:20:33 +02:00
xfs_error.c xfs: report corruption only as a regular error 2023-04-20 12:07:38 +02:00
xfs_error.h xfs: xfs_buf_corruption_error should take __this_address 2022-10-29 10:20:33 +02:00
xfs_export.c xfs: factor out a new xfs_log_force_inode helper 2022-10-29 10:20:34 +02:00
xfs_export.h
xfs_extent_busy.c xfs: don't reuse busy extents on extent trim 2023-04-20 12:07:38 +02:00
xfs_extent_busy.h
xfs_extfree_item.c xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_extfree_item.h xfs: proper replay of deferred ops queued during log recovery 2023-02-22 12:50:36 +01:00
xfs_file.c xfs: use MMAPLOCK around filemap_map_pages() 2022-11-25 17:42:03 +01:00
xfs_filestream.c
xfs_filestream.h
xfs_fsmap.c xfs: add missing assert in xfs_fsmap_owner_from_rmap 2022-09-28 11:04:09 +02:00
xfs_fsmap.h xfs: fix deadlock and streamline xfs_getfsmap performance 2020-10-29 09:57:48 +01:00
xfs_fsops.c
xfs_fsops.h
xfs_globals.c
xfs_health.c
xfs_icache.c xfs: ensure that the inode uid/gid match values match the icdinode ones 2023-04-20 12:07:37 +02:00
xfs_icache.h
xfs_icreate_item.c xfs: expose the log push threshold 2023-02-22 12:50:37 +01:00
xfs_icreate_item.h
xfs_inode.c xfs: fix up non-directory creation in SGID directories 2023-04-20 12:07:37 +02:00
xfs_inode.h xfs: merge the projid fields in struct xfs_icdinode 2023-04-20 12:07:37 +02:00
xfs_inode_item.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_inode_item.h xfs: remove the xfs_inode_log_item_t typedef 2023-02-22 12:50:35 +01:00
xfs_ioctl.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_ioctl.h
xfs_ioctl32.c xfs: clear kernel only flags in XFS_IOC_ATTRMULTI_BY_HANDLE 2020-03-05 16:43:51 +01:00
xfs_ioctl32.h
xfs_iomap.c xfs: don't fail unwritten extent conversion on writeback due to edquot 2022-11-10 17:57:54 +01:00
xfs_iomap.h
xfs_iops.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_iops.h
xfs_itable.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_itable.h
xfs_iwalk.c xfs: fix the forward progress assertion in xfs_iwalk_run_callbacks 2023-02-22 12:50:38 +01:00
xfs_iwalk.h
xfs_linux.h xfs: report corruption only as a regular error 2023-04-20 12:07:38 +02:00
xfs_log.c xfs: sync lazy sb accounting on quiesce of read-only mounts 2023-02-22 12:50:38 +01:00
xfs_log.h xfs: sync lazy sb accounting on quiesce of read-only mounts 2023-02-22 12:50:38 +01:00
xfs_log_cil.c xfs: prevent UAF in xfs_log_item_in_current_chkpt 2023-02-22 12:50:38 +01:00
xfs_log_priv.h xfs: fix use-after-free on CIL context on shutdown 2022-10-29 10:20:34 +02:00
xfs_log_recover.c xfs: remove the di_version field from struct icdinode 2023-04-20 12:07:37 +02:00
xfs_message.c xfs: constify the buffer pointer arguments to error functions 2022-09-28 11:04:10 +02:00
xfs_message.h xfs: constify the buffer pointer arguments to error functions 2022-09-28 11:04:10 +02:00
xfs_mount.c xfs: force log and push AIL to clear pinned inodes when aborting mount 2023-04-20 12:07:38 +02:00
xfs_mount.h xfs: move inode flush to the sync workqueue 2022-10-29 10:20:34 +02:00
xfs_mru_cache.c
xfs_mru_cache.h
xfs_ondisk.h
xfs_pnfs.c xfs: slightly tweak an assert in xfs_fs_map_blocks 2022-09-28 11:04:09 +02:00
xfs_pnfs.h
xfs_pwork.c
xfs_pwork.h
xfs_qm.c xfs: remove the kuid/kgid conversion wrappers 2023-04-20 12:07:37 +02:00
xfs_qm.h
xfs_qm_bhv.c xfs: merge the projid fields in struct xfs_icdinode 2023-04-20 12:07:37 +02:00
xfs_qm_syscalls.c xfs: fix unmount hang and memory leak on shutdown during quotaoff 2022-10-29 10:20:33 +02:00
xfs_quota.h xfs: remove the icdinode di_uid/di_gid members 2023-04-20 12:07:37 +02:00
xfs_quotaops.c xfs: Sanity check flags of Q_XQUOTARM call 2020-01-26 10:00:59 +01:00
xfs_refcount_item.c xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_refcount_item.h xfs: proper replay of deferred ops queued during log recovery 2023-02-22 12:50:36 +01:00
xfs_reflink.c xfs: redesign the reflink remap loop to fix blkres depletion crash 2022-11-25 17:42:03 +01:00
xfs_reflink.h
xfs_rmap_item.c xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_rmap_item.h xfs: proper replay of deferred ops queued during log recovery 2023-02-22 12:50:36 +01:00
xfs_rtalloc.c xfs: fix realtime bitmap/summary file truncation when growing rt volume 2020-11-05 11:43:14 +01:00
xfs_rtalloc.h
xfs_stats.c xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_stats.h xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_super.c xfs: show the proper user quota options 2023-04-20 12:07:37 +02:00
xfs_super.h
xfs_symlink.c xfs: set inode size after creating symlink 2023-04-20 12:07:38 +02:00
xfs_symlink.h
xfs_sysctl.c
xfs_sysctl.h
xfs_sysfs.c xfs: avoid unused to_mp() function warning 2019-09-24 09:40:19 -07:00
xfs_sysfs.h xfs: Fix UBSAN null-ptr-deref in xfs_sysfs_init 2020-08-26 10:40:58 +02:00
xfs_trace.c
xfs_trace.h xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_trans.c xfs: preserve rmapbt swapext block reservation from freed blocks 2022-11-25 17:42:03 +01:00
xfs_trans.h xfs: periodically relog deferred intent items 2023-02-22 12:50:37 +01:00
xfs_trans_ail.c xfs: drain the buf delwri queue before xfsaild idles 2022-11-25 17:42:03 +01:00
xfs_trans_buf.c
xfs_trans_dquot.c xfs: shut down the filesystem if we screw up quota reservation 2023-04-20 12:07:38 +02:00
xfs_trans_priv.h xfs: tail updates only need to occur when LSN changes 2022-10-29 10:20:34 +02:00
xfs_xattr.c