xfs: preserve buffer item with outstanding references
PATCH 1/1 xfs: preserve buffer item with outstanding references
The buffer log item can still be referenced by the CIL after the buffer's synchronous write completes. In this case xfs_buf_item_relse() is called from xfs_buf_ioend() with bli_refcount non-zero. Freeing the item leaves a stale pointer in the CIL, which xlog_cil_committed() later dereferences.
Restore the reference-count check removed by commit d2fe5c4c8d25 ("xfs: rearrange code in xfs_buf_item.c"). If references remain, keep the log item attached to the buffer so that its final reference release can perform cleanup.
Build-tested: fs/xfs/xfs_buf_item.o (ARCH=arm64, W=1).
The syzbot report does not include a reproducer, so runtime testing was not possible.
--- fs/xfs/xfs_buf_item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_buf_item.c +2 -1
@@ -80,7 +80,8 @@ xfs_buf_item_relse(trace_xfs_buf_item_relse (bp, _RET_IP_);ASSERT (!test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)); -ASSERT (atomic_read (&bip->bli_refcount) ==0 ); +if (atomic_read (&bip->bli_refcount)) +return ; bp->b_log_item =NULL ;xfs_buf_rele (bp);
Quoted 38 lines · Eduard Zateev
The buffer log item can still be referenced by the CIL after the buffer's synchronous write completes. In this case
xfs_buf_item_relse()is called fromxfs_buf_ioend()withbli_refcountnon-zero. Freeing the item leaves a stale pointer in the CIL, whichxlog_cil_committed()later dereferences.Restore the reference-count check removed by commit
d2fe5c4c8d25("xfs: rearrange code inxfs_buf_item.c"). If references remain, keep the log item attached to the buffer so that its final reference release can perform cleanup.Build-tested:
fs/xfs/xfs_buf_item.o(ARCH=arm64, W=1).
The syzbot report does not include a reproducer, so runtime testing was not possible.Fixes d2fe5c4c8d25 ("xfs: rearrange code in xfs_buf_item.c")Reported-by [email protected]Assisted-by LLM OpenAI Codex--- fs/xfs/xfs_buf_item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/xfs/xfs_buf_item.c +2
-1@@ -80,7 +80,8 @@ xfs_buf_item_relse(trace_xfs_buf_item_relse (bp, _RET_IP_);ASSERT (!test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)); -ASSERT (atomic_read (&bip->bli_refcount) ==0 ); +if (atomic_read (&bip->bli_refcount)) +return ; bp->b_log_item =NULL ;xfs_buf_rele (bp);
Quoted 1 line
Signed-off-by Eduard Zateev <[email protected]>
You didn't bother to check the mailing list or syzbot for duplicates or prior discussion, did you?
What I said about this less than two days ago:
https://lore.kernel.org/linux-xfs/atUsQVuCKnAIZc3X@dread/
-Dave.
Signature · 2 lines
Dave Chinner [email protected]