Skip to content

Commit 07eae0f

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: check for dead buffers in xfs_buf_find_insert
Commit 32dd4f9 ("xfs: remove a superflous hash lookup when inserting new buffers") converted xfs_buf_find_insert to use rhashtable_lookup_get_insert_fast and thus an operation that returns the existing buffer when an insert would duplicate the hash key. But this code path misses the check for a buffer with a reference count of zero, which could lead to reusing an about to be freed buffer. Fix this by using the same atomic_inc_not_zero pattern as xfs_buf_insert. Fixes: 32dd4f9 ("xfs: remove a superflous hash lookup when inserting new buffers") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Cc: stable@vger.kernel.org # v6.0 Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 4e35be6 commit 07eae0f

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

fs/xfs/xfs_buf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,8 @@ xfs_buf_find_insert(
655655
spin_unlock(&bch->bc_lock);
656656
goto out_free_buf;
657657
}
658-
if (bp) {
658+
if (bp && atomic_inc_not_zero(&bp->b_hold)) {
659659
/* found an existing buffer */
660-
atomic_inc(&bp->b_hold);
661660
spin_unlock(&bch->bc_lock);
662661
error = xfs_buf_find_lock(bp, flags);
663662
if (error)

0 commit comments

Comments
 (0)