From: Christoph Hellwig <hch@xxxxxx> commit 07eae0fa67ca4bbb199ad85645e0f9dfaef931cd upstream. Commit 32dd4f9c506b ("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: 32dd4f9c506b ("xfs: remove a superflous hash lookup when inserting new buffers") Signed-off-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx> Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> Cc: stable@xxxxxxxxxxxxxxx # v6.0 Signed-off-by: Carlos Maiolino <cem@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/xfs/xfs_buf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -663,9 +663,8 @@ xfs_buf_find_insert( spin_unlock(&bch->bc_lock); goto out_free_buf; } - if (bp) { + if (bp && atomic_inc_not_zero(&bp->b_hold)) { /* found an existing buffer */ - atomic_inc(&bp->b_hold); spin_unlock(&bch->bc_lock); error = xfs_buf_find_lock(bp, flags); if (error) Patches currently in stable-queue which might be from hch@xxxxxx are queue-6.12/xfs-check-for-dead-buffers-in-xfs_buf_find_insert.patch queue-6.12/nvme-add-error-path-for-xa_store-in-nvme_init_effect.patch queue-6.12/nvme-tcp-fix-i-o-queue-cpu-spreading-for-multiple-co.patch queue-6.12/xfs-don-t-shut-down-the-filesystem-for-media-failures-beyond-end-of-log.patch queue-6.12/block-don-t-update-blk_feat_poll-in-__blk_mq_update_.patch queue-6.12/block-retry-call-probe-after-request_module-in-blk_r.patch queue-6.12/block-check-blk_feat_poll-under-q_usage_count.patch queue-6.12/nvme-add-error-check-for-xa_store-in-nvme_get_effect.patch queue-6.12/ps3disk-do-not-use-dev-bounce_size-before-it-is-set.patch queue-6.12/block-copy-back-bounce-buffer-to-user-space-correctl.patch queue-6.12/nbd-don-t-allow-reconnect-after-disconnect.patch