From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Carlos Maiolino <cem@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/2] xfs: check for dead buffers in xfs_buf_find_insert
Date: Sun, 12 Jan 2025 20:56:21 -0800 [thread overview]
Message-ID: <20250113045621.GR1387004@frogsfrogsfrogs> (raw)
In-Reply-To: <20250113042542.2051287-2-hch@lst.de>
On Mon, Jan 13, 2025 at 05:24:26AM +0100, Christoph Hellwig wrote:
> 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@lst.de>
Cc: <stable@vger.kernel.org> # v6.0
and with that added,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_buf.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index 6f313fbf7669..f80e39fde53b 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -664,9 +664,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)
> --
> 2.45.2
>
next prev parent reply other threads:[~2025-01-13 4:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 4:24 fix buffer refcount races Christoph Hellwig
2025-01-13 4:24 ` [PATCH 1/2] xfs: check for dead buffers in xfs_buf_find_insert Christoph Hellwig
2025-01-13 4:56 ` Darrick J. Wong [this message]
2025-01-14 0:24 ` Dave Chinner
2025-01-13 4:24 ` [PATCH 2/2] xfs: fix buffer lookup vs release race Christoph Hellwig
2025-01-13 17:55 ` Darrick J. Wong
2025-01-13 20:55 ` Dave Chinner
2025-01-15 5:38 ` Christoph Hellwig
2025-01-15 11:21 ` Dave Chinner
2025-01-13 5:08 ` fix buffer refcount races Darrick J. Wong
2025-01-13 5:14 ` Christoph Hellwig
2025-01-13 7:13 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2025-01-16 6:01 fix buffer refcount races v2 Christoph Hellwig
2025-01-16 6:01 ` [PATCH 1/2] xfs: check for dead buffers in xfs_buf_find_insert Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250113045621.GR1387004@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox