From: "dongchenchen (A)" <dongchenchen2@huawei.com>
To: Paolo Abeni <pabeni@redhat.com>, <hawk@kernel.org>,
<ilias.apalodimas@linaro.org>, <davem@davemloft.net>,
<edumazet@google.com>, <kuba@kernel.org>, <horms@kernel.org>,
<almasrymina@google.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<zhangchangzhong@huawei.com>,
<syzbot+204a4382fcb3311f3858@syzkaller.appspotmail.com>
Subject: Re: [PATCH net] page_pool: Fix use-after-free in page_pool_recycle_in_ring
Date: Mon, 26 May 2025 23:02:24 +0800 [thread overview]
Message-ID: <7d632b35-2a37-452f-9604-848d4145eab6@huawei.com> (raw)
In-Reply-To: <af41c789-9e0d-4310-ae28-055beef73f10@redhat.com>
在 2025/5/23 21:31, Paolo Abeni 写道:
> On 5/23/25 8:45 AM, Dong Chenchen wrote:
>> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
>> index 7745ad924ae2..08f1b000ebc1 100644
>> --- a/net/core/page_pool.c
>> +++ b/net/core/page_pool.c
>> @@ -707,19 +707,16 @@ void page_pool_return_page(struct page_pool *pool, netmem_ref netmem)
>>
>> static bool page_pool_recycle_in_ring(struct page_pool *pool, netmem_ref netmem)
>> {
>> + bool in_softirq;
>> int ret;
>> /* BH protection not needed if current is softirq */
>> - if (in_softirq())
>> - ret = ptr_ring_produce(&pool->ring, (__force void *)netmem);
>> - else
>> - ret = ptr_ring_produce_bh(&pool->ring, (__force void *)netmem);
>> -
>> - if (!ret) {
>> + in_softirq = page_pool_producer_lock(pool);
>> + ret = !__ptr_ring_produce(&pool->ring, (__force void *)netmem);
>> + if (ret)
>> recycle_stat_inc(pool, ring);
>> - return true;
>> - }
> Does not build in our CI:
>
> net/core/page_pool.c: In function ‘page_pool_recycle_in_ring’:
> net/core/page_pool.c:750:45: error: suggest braces around empty body in
> an ‘if’ statement [-Werror=empty-body]
> 750 | recycle_stat_inc(pool, ring);
> | ^
>
> /P
>
I am sorry for this mistake.
recycle_stat_inc() is empty when CONFIG_PAGE_POOL_STATS is not enabled.
Maybe we can fix it as:
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 08f1b000ebc1..19c1505ec40f 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -154,8 +154,8 @@ EXPORT_SYMBOL(page_pool_ethtool_stats_get);
#else
#define alloc_stat_inc(pool, __stat)
-#define recycle_stat_inc(pool, __stat)
-#define recycle_stat_add(pool, __stat, val)
+#define recycle_stat_inc(pool, __stat) do { } while (0)
+#define recycle_stat_add(pool, __stat, val) do { } while (0)
#endif
Thanks a lot!
Dong Chenchen
next prev parent reply other threads:[~2025-05-26 15:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 6:45 Dong Chenchen
2025-05-23 8:30 ` Yunsheng Lin
2025-05-23 16:45 ` Mina Almasry
2025-05-26 14:47 ` dongchenchen (A)
2025-05-26 17:51 ` Mina Almasry
2025-05-27 1:52 ` dongchenchen (A)
2025-05-27 2:13 ` Mina Almasry
2025-05-26 14:27 ` dongchenchen (A)
2025-05-23 9:16 ` Toke Høiland-Jørgensen
2025-05-23 13:31 ` Paolo Abeni
2025-05-26 15:02 ` dongchenchen (A) [this message]
2025-05-23 21:23 ` kernel test robot
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=7d632b35-2a37-452f-9604-848d4145eab6@huawei.com \
--to=dongchenchen2@huawei.com \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+204a4382fcb3311f3858@syzkaller.appspotmail.com \
--cc=zhangchangzhong@huawei.com \
/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
all inboxes | Powered by JetHome®