]> git.ipfire.org Git - thirdparty/linux.git/commit
xfs: fix a buffer lookup against removal race
authorChristoph Hellwig <hch@lst.de>
Mon, 18 May 2026 06:02:05 +0000 (08:02 +0200)
committerCarlos Maiolino <cem@kernel.org>
Thu, 21 May 2026 11:43:58 +0000 (13:43 +0200)
commitc69439a891ccb37ede5d68539636337c6bd92fab
tree260f96ded264e775867828cc197ce2b8bb8edafd
parent509fdeb3326be0db055e88d0f689a3888f147f90
xfs: fix a buffer lookup against removal race

When a buffer is freed either by LRU eviction or because it is unset,
the lockref is marked as dead instantly, which prevents the buffer from
being used after finding it in the buffer hash in xfs_buf_lookup and
xfs_buf_find_insert.  But the latter will then not add the new buffer to
the hash because it already found an existing buffer.

Fix this using in two places:  Remove the buffer from the hash before
marking the lockref dead so that that no buffer with a dead lockref can
be found in the hash, but if we find one in xfs_buf_find_insert due to
store reordering, handle this case correctly instead of returning an
unhashed buffer.

Fixes: 67fe4303972e ("xfs: don't keep a reference for buffers on the LRU")
Reported-by: Andrey Albershteyn <aalbersh@redhat.com>
Reported-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_buf.c