Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7922c1b

Browse files
sandeengregkh
authored andcommitted
xfs: fix up xfs_swap_extent_forks inline extent handling
commit 4dfce57 upstream. There have been several reports over the years of NULL pointer dereferences in xfs_trans_log_inode during xfs_fsr processes, when the process is doing an fput and tearing down extents on the temporary inode, something like: BUG: unable to handle kernel NULL pointer dereference at 0000000000000018 PID: 29439 TASK: ffff880550584fa0 CPU: 6 COMMAND: "xfs_fsr" [exception RIP: xfs_trans_log_inode+0x10] hardkernel#9 [ffff8800a57bbbe0] xfs_bunmapi at ffffffffa037398e [xfs] hardkernel#10 [ffff8800a57bbce8] xfs_itruncate_extents at ffffffffa0391b29 [xfs] hardkernel#11 [ffff8800a57bbd88] xfs_inactive_truncate at ffffffffa0391d0c [xfs] hardkernel#12 [ffff8800a57bbdb8] xfs_inactive at ffffffffa0392508 [xfs] hardkernel#13 [ffff8800a57bbdd8] xfs_fs_evict_inode at ffffffffa035907e [xfs] hardkernel#14 [ffff8800a57bbe00] evict at ffffffff811e1b67 hardkernel#15 [ffff8800a57bbe28] iput at ffffffff811e23a5 hardkernel#16 [ffff8800a57bbe58] dentry_kill at ffffffff811dcfc8 hardkernel#17 [ffff8800a57bbe88] dput at ffffffff811dd06c hardkernel#18 [ffff8800a57bbea8] __fput at ffffffff811c823b hardkernel#19 [ffff8800a57bbef0] ____fput at ffffffff811c846e hardkernel#20 [ffff8800a57bbf00] task_work_run at ffffffff81093b27 hardkernel#21 [ffff8800a57bbf30] do_notify_resume at ffffffff81013b0c hardkernel#22 [ffff8800a57bbf50] int_signal at ffffffff8161405d As it turns out, this is because the i_itemp pointer, along with the d_ops pointer, has been overwritten with zeros when we tear down the extents during truncate. When the in-core inode fork on the temporary inode used by xfs_fsr was originally set up during the extent swap, we mistakenly looked at di_nextents to determine whether all extents fit inline, but this misses extents generated by speculative preallocation; we should be using if_bytes instead. This mistake corrupts the in-memory inode, and code in xfs_iext_remove_inline eventually gets bad inputs, causing it to memmove and memset incorrect ranges; this became apparent because the two values in ifp->if_u2.if_inline_ext[1] contained what should have been in d_ops and i_itemp; they were memmoved due to incorrect array indexing and then the original locations were zeroed with memset, again due to an array overrun. Fix this by properly using i_df.if_bytes to determine the number of extents, not di_nextents. Thanks to dchinner for looking at this with me and spotting the root cause. [nborisov: backported to 4.4] Cc: [email protected] Signed-off-by: Eric Sandeen <[email protected]> Reviewed-by: Brian Foster <[email protected]> Signed-off-by: Dave Chinner <[email protected]> Signed-off-by: Nikolay Borisov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> -- fs/xfs/xfs_bmap_util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
1 parent c4cf86f commit 7922c1b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ xfs_swap_extents(
17131713
xfs_trans_t *tp;
17141714
xfs_bstat_t *sbp = &sxp->sx_stat;
17151715
xfs_ifork_t *tempifp, *ifp, *tifp;
1716+
xfs_extnum_t nextents;
17161717
int src_log_flags, target_log_flags;
17171718
int error = 0;
17181719
int aforkblks = 0;
@@ -1899,7 +1900,8 @@ xfs_swap_extents(
18991900
* pointer. Otherwise it's already NULL or
19001901
* pointing to the extent.
19011902
*/
1902-
if (ip->i_d.di_nextents <= XFS_INLINE_EXTS) {
1903+
nextents = ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
1904+
if (nextents <= XFS_INLINE_EXTS) {
19031905
ifp->if_u1.if_extents =
19041906
ifp->if_u2.if_inline_ext;
19051907
}
@@ -1918,7 +1920,8 @@ xfs_swap_extents(
19181920
* pointer. Otherwise it's already NULL or
19191921
* pointing to the extent.
19201922
*/
1921-
if (tip->i_d.di_nextents <= XFS_INLINE_EXTS) {
1923+
nextents = tip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
1924+
if (nextents <= XFS_INLINE_EXTS) {
19221925
tifp->if_u1.if_extents =
19231926
tifp->if_u2.if_inline_ext;
19241927
}

0 commit comments

Comments
 (0)