Skip to content

Commit edba3df

Browse files
committed
page_pool: Fix use-after-free in page_pool_recycle_in_ring
jira VULN-71839 cve CVE-2025-38129 commit-author Dong Chenchen <dongchenchen2@huawei.com> commit 271683b upstream-diff | page_pool_recycle_in_ring() Accounted for the non-backported 4dec64c ("page_pool: convert to use netmem") page_pool_release() (The following were the context conflicts, no actual diffs from the upstream in the strict sense) - Retained the single-argument `page_pool_inflight()' call instead of passing additional `true' as it is in the upstream. The boolean argument relates to the reporting feature introduced in the non-backported commit 7aee842 ("net: page_pool: report amount of memory held by page pools"). - LTS 9.4 lacks the backport of de97502 ("page_pool: introduce page_pool_alloc() API"). Without it the `__page_pool_destroy()' call in upstream is equivalent to `page_pool_free()' in ciqlts9_4. Retained the ciqlts9_4-native `page_pool_free()' call. syzbot reported a uaf in page_pool_recycle_in_ring: BUG: KASAN: slab-use-after-free in lock_release+0x151/0xa30 kernel/locking/lockdep.c:5862 Read of size 8 at addr ffff8880286045a0 by task syz.0.284/6943 CPU: 0 UID: 0 PID: 6943 Comm: syz.0.284 Not tainted 6.13.0-rc3-syzkaller-gdfa94ce54f41 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0x169/0x550 mm/kasan/report.c:489 kasan_report+0x143/0x180 mm/kasan/report.c:602 lock_release+0x151/0xa30 kernel/locking/lockdep.c:5862 __raw_spin_unlock_bh include/linux/spinlock_api_smp.h:165 [inline] _raw_spin_unlock_bh+0x1b/0x40 kernel/locking/spinlock.c:210 spin_unlock_bh include/linux/spinlock.h:396 [inline] ptr_ring_produce_bh include/linux/ptr_ring.h:164 [inline] page_pool_recycle_in_ring net/core/page_pool.c:707 [inline] page_pool_put_unrefed_netmem+0x748/0xb00 net/core/page_pool.c:826 page_pool_put_netmem include/net/page_pool/helpers.h:323 [inline] page_pool_put_full_netmem include/net/page_pool/helpers.h:353 [inline] napi_pp_put_page+0x149/0x2b0 net/core/skbuff.c:1036 skb_pp_recycle net/core/skbuff.c:1047 [inline] skb_free_head net/core/skbuff.c:1094 [inline] skb_release_data+0x6c4/0x8a0 net/core/skbuff.c:1125 skb_release_all net/core/skbuff.c:1190 [inline] __kfree_skb net/core/skbuff.c:1204 [inline] sk_skb_reason_drop+0x1c9/0x380 net/core/skbuff.c:1242 kfree_skb_reason include/linux/skbuff.h:1263 [inline] __skb_queue_purge_reason include/linux/skbuff.h:3343 [inline] root cause is: page_pool_recycle_in_ring ptr_ring_produce spin_lock(&r->producer_lock); WRITE_ONCE(r->queue[r->producer++], ptr) //recycle last page to pool page_pool_release page_pool_scrub page_pool_empty_ring ptr_ring_consume page_pool_return_page //release all page __page_pool_destroy free_percpu(pool->recycle_stats); free(pool) //free spin_unlock(&r->producer_lock); //pool->ring uaf read recycle_stat_inc(pool, ring); page_pool can be free while page pool recycle the last page in ring. Add producer-lock barrier to page_pool_release to prevent the page pool from being free before all pages have been recycled. recycle_stat_inc() is empty when CONFIG_PAGE_POOL_STATS is not enabled, which will trigger Wempty-body build warning. Add definition for pool stat macro to fix warning. Suggested-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/netdev/20250513083123.3514193-1-dongchenchen2@huawei.com Fixes: ff7d6b2 ("page_pool: refurbish version of page_pool code") Reported-by: syzbot+204a4382fcb3311f3858@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=204a4382fcb3311f3858 Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Reviewed-by: Mina Almasry <almasrymina@google.com> Link: https://patch.msgid.link/20250527114152.3119109-1-dongchenchen2@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 271683b) Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>
1 parent bea37d6 commit edba3df

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

net/core/page_pool.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
140140
EXPORT_SYMBOL(page_pool_ethtool_stats_get);
141141

142142
#else
143-
#define alloc_stat_inc(pool, __stat)
144-
#define recycle_stat_inc(pool, __stat)
145-
#define recycle_stat_add(pool, __stat, val)
143+
#define alloc_stat_inc(...) do { } while (0)
144+
#define recycle_stat_inc(...) do { } while (0)
145+
#define recycle_stat_add(...) do { } while (0)
146146
#endif
147147

148148
static bool page_pool_producer_lock(struct page_pool *pool)
@@ -553,19 +553,16 @@ static void page_pool_return_page(struct page_pool *pool, struct page *page)
553553

554554
static bool page_pool_recycle_in_ring(struct page_pool *pool, struct page *page)
555555
{
556-
int ret;
557-
/* BH protection not needed if current is softirq */
558-
if (in_softirq())
559-
ret = ptr_ring_produce(&pool->ring, page);
560-
else
561-
ret = ptr_ring_produce_bh(&pool->ring, page);
556+
bool in_softirq, ret;
562557

563-
if (!ret) {
558+
/* BH protection not needed if current is softirq */
559+
in_softirq = page_pool_producer_lock(pool);
560+
ret = !__ptr_ring_produce(&pool->ring, page);
561+
if (ret)
564562
recycle_stat_inc(pool, ring);
565-
return true;
566-
}
563+
page_pool_producer_unlock(pool, in_softirq);
567564

568-
return false;
565+
return ret;
569566
}
570567

571568
/* Only allow direct recycling in special circumstances, into the
@@ -854,10 +851,14 @@ static void page_pool_scrub(struct page_pool *pool)
854851

855852
static int page_pool_release(struct page_pool *pool)
856853
{
854+
bool in_softirq;
857855
int inflight;
858856

859857
page_pool_scrub(pool);
860858
inflight = page_pool_inflight(pool);
859+
/* Acquire producer lock to make sure producers have exited. */
860+
in_softirq = page_pool_producer_lock(pool);
861+
page_pool_producer_unlock(pool, in_softirq);
861862
if (!inflight)
862863
page_pool_free(pool);
863864

0 commit comments

Comments
 (0)