From: David Howells <dhowells@redhat.com>
To: Max Kellermann <max.kellermann@ionos.com>
Cc: dhowells@redhat.com, Paulo Alcantara <pc@manguebit.org>,
Christian Brauner <brauner@kernel.org>,
netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-stable@vger.kernel.org
Subject: Re: [PATCH] fs/netfs: fix reference leak
Date: Wed, 24 Sep 2025 16:24:59 +0100 [thread overview]
Message-ID: <745741.1758727499@warthog.procyon.org.uk> (raw)
In-Reply-To: <20250911222501.1417765-1-max.kellermann@ionos.com>
Max Kellermann <max.kellermann@ionos.com> wrote:
> For my taste, the whole netfs code needs an overhaul to make reference
> counting easier to understand and less fragile & obscure. But to fix
> this bug here and now and produce a patch that is adequate for a
> stable backport, I tried a minimal approach that quickly frees the
> request object upon early failure.
I'm not entirely satisfied with the refcounting either, as it's tricky with
the asynchronicity requirements.
> I decided against adding a second netfs_put_request() each time because that
> would cause code duplication which obscures the code further. Instead, I
> added the function netfs_put_failed_request() which frees such a failed
> request synchronously under the assumption that the reference count is
> exactly 2 (as initially set by netfs_alloc_request() and never touched),
> verified by a WARN_ON_ONCE().
I like this.
> ... and frees the allocation (without the "call_rcu" indirection).
Unfortunately, this isn't good. The request has already been added to the
proc list and is removed in netfs_deinit_request() by netfs_proc_del_rreq() -
but that means that someone reading /proc/fs/netfs/requests can be looking at
it as you free it.
You still need the call_rcu() - or you have to call synchronize_rcu().
I can change netfs_put_failed_request() to do the call_rcu() rather than
mempool_free()/netfs_stat_d().
Another possibility could be to defer the addition to the proc list to right
before we start adding subrequests. Deleting from the proc list would be a
no-op if the thing isn't queued.
Thanks,
David
next prev parent reply other threads:[~2025-09-24 15:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 22:24 [PATCH] fs/netfs: fix reference leak Max Kellermann
2025-09-24 15:24 ` David Howells [this message]
2025-09-24 15:39 ` David Howells
2025-09-24 18:52 ` Max Kellermann
2025-09-24 19:10 ` David Howells
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=745741.1758727499@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stable@vger.kernel.org \
--cc=max.kellermann@ionos.com \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.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