[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250513142150.3cb416e1@kernel.org>
Date: Tue, 13 May 2025 14:21:50 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Mina Almasry <almasrymina@...gle.com>
Cc: Dong Chenchen <dongchenchen2@...wei.com>, hawk@...nel.org,
ilias.apalodimas@...aro.org, davem@...emloft.net, edumazet@...gle.com,
pabeni@...hat.com, horms@...nel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, zhangchangzhong@...wei.com
Subject: Re: [BUG Report] KASAN: slab-use-after-free in
page_pool_recycle_in_ring
On Tue, 13 May 2025 13:06:38 -0700 Mina Almasry wrote:
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 2b76848659418..8654608734773 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -1146,10 +1146,17 @@ static void page_pool_scrub(struct page_pool *pool)
>
> static int page_pool_release(struct page_pool *pool)
> {
> + bool in_softirq;
> int inflight;
>
> +
> + /* Acquire producer lock to make sure we don't race with another thread
> + * returning a netmem to the ptr_ring.
> + */
> + in_softirq = page_pool_producer_lock(pool);
> page_pool_scrub(pool);
> inflight = page_pool_inflight(pool, true);
> + page_pool_producer_unlock(pool, in_softirq);
Makes sense! A couple minor notes.
Consumer lock should be outside, but really we only need to make
sure producer has "exited" right? So lock/unlock, no need to wrap
any code in it.
I'd add a helper to ptr_ring.h, a "producer barrier" which just
takes/releases the producer lock. We can't be in softirq context
here but doesn't matter, let's take the lock in "any" mode IOW
irqsave() ?
The barrier is only needed if we're proceeding to destruction.
If inflight returns != 0 we won't destroy the pool so no need
to touch producer lock.
Powered by blists - more mailing lists