Re: [PATCH] fs/netfs: fix reference leak
From: Max Kellermann
Date: Wed Sep 24 2025 - 14:52:54 EST
On Wed, Sep 24, 2025 at 5:39 PM David Howells <dhowells@xxxxxxxxxx> wrote:
> > > ... 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.
Oh, right. I saw the linked list operations were protected by a
spinlock, but I missed that this lock is not taken for traversal while
reading proc. I'll send v2 with your suggested fix.
> >
> > 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().
>
> How about:
>
> /*
> * Free a request (synchronously) that was just allocated but has failed before
> * it could be submitted.
> */
> void netfs_put_failed_request(struct netfs_io_request *rreq)
> {
> int r;
>
> /* New requests have two references (see netfs_alloc_request(), and
> * this function is only allowed on new request objects
> */
> if (!__refcount_sub_and_test(2, &rreq->ref, &r))
> WARN_ON_ONCE(1);
You changed the refcount_read() check to an atomic decrement, but at
this point, nobody cares for the reference counter anymore (and my
check was just for bug-catching purposes).
Why bother doing the decrement?