mirror-linux/net
Dong Chenchen 271683bb2c page_pool: Fix use-after-free in page_pool_recycle_in_ring
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: ff7d6b27f8 ("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>
2025-05-28 19:19:36 -07:00
..
6lowpan
9p 9p: Use hashtable.h for hash_errmap 2025-03-23 06:20:48 +09:00
802 net: 802: Remove unused p8022 code 2025-04-22 07:04:02 -07:00
8021q net: 802: Remove unused p8022 code 2025-04-22 07:04:02 -07:00
appletalk treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
atm treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
ax25 treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
batman-adv Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-15 11:28:30 -07:00
bluetooth Bluetooth: MGMT: iterate over mesh commands in mgmt_mesh_foreach() 2025-05-22 13:06:11 -04:00
bpf selftests/bpf: Add test to access const void pointer argument in tracing program 2025-04-23 11:26:22 -07:00
bridge Networking changes for 6.16. 2025-05-28 15:24:36 -07:00
caif
can can: bcm: add missing rcu read protection for procfs content 2025-05-19 16:58:19 +02:00
ceph A small CephFS encryption-related fix and a dead code cleanup. 2025-04-25 15:51:28 -07:00
core page_pool: Fix use-after-free in page_pool_recycle_in_ring 2025-05-28 19:19:36 -07:00
dcb
devlink devlink: use DEVLINK_VAR_ATTR_TYPE_* instead of NLA_* in fmsg 2025-05-06 18:21:11 -07:00
dns_resolver
dsa Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-22 09:42:41 -07:00
ethernet
ethtool net: Add support for providing the PTP hardware source in tsinfo 2025-05-22 15:32:00 +02:00
handshake
hsr net: hsr: sync hw addr of slave2 according to slave1 hw addr on PRP 2025-04-14 12:40:06 +01:00
ieee802154 net: core: Convert dev_set_mac_address() to struct sockaddr_storage 2025-05-27 08:25:43 +02:00
ife
ipv4 net: devmem: preserve sockc_err 2025-05-27 19:19:35 -07:00
ipv6 netfilter pull request 25-05-23 2025-05-26 18:53:41 +02:00
iucv
kcm
key xfrm: Migrate offload configuration 2025-04-17 11:00:03 +02:00
l2tp
l3mdev net: fib_rules: Fix iif / oif matching on L3 master device 2025-04-15 17:54:56 -07:00
lapb treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
llc llc: fix data loss when reading from a socket in llc_ui_recvmsg() 2025-05-19 12:12:54 +01:00
mac80211 Lots of new things, notably: 2025-05-22 14:05:18 -07:00
mac802154
mctp net: mctp: use nlmsg_payload() for netlink message data extraction 2025-05-26 17:38:27 +02:00
mpls mpls: Use nlmsg_payload in mpls_valid_getroute_req 2025-04-15 08:28:54 -07:00
mptcp mptcp: Use nested-BH locking for hmac_storage 2025-05-15 15:23:31 +02:00
ncsi net: core: Convert dev_set_mac_address() to struct sockaddr_storage 2025-05-27 08:25:43 +02:00
netfilter netfilter pull request 25-05-23 2025-05-26 18:53:41 +02:00
netlabel calipso: Don't call calipso functions for AF_INET sk. 2025-05-28 08:59:09 +02:00
netlink netlink: fix policy dump for int with validation callback 2025-05-12 18:50:09 -07:00
netrom treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
nfc treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
nsh
openvswitch Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-28 10:11:15 +02:00
packet af_packet: move notifier's packet_dev_mc out of rcu critical section 2025-05-27 11:36:26 +02:00
phonet
psample
qrtr
rds replace strncpy with strscpy_pad 2025-05-26 22:28:44 +02:00
rfkill
rose treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
rxrpc rxrpc: rxgk: Fix some reference count leaks 2025-04-24 18:06:05 -07:00
sched Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-28 10:11:15 +02:00
sctp sctp: mark sctp_do_peeloff static 2025-05-27 18:18:55 -07:00
shaper
smc smc: Fix lockdep false-positive for IPPROTO_SMC. 2025-04-11 14:14:26 -07:00
strparser strparser: Remove unused __strp_unpause 2025-05-05 16:48:12 -07:00
sunrpc NFSD 6.16 Release Notes 2025-05-28 12:21:12 -07:00
switchdev
tipc tipc: use kfree_sensitive() for aead cleanup 2025-05-27 17:31:42 -07:00
tls bpf-next-6.16 2025-05-28 15:52:42 -07:00
unix Networking changes for 6.16. 2025-05-28 15:24:36 -07:00
vmw_vsock Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-28 10:11:15 +02:00
wireless Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-08 08:59:02 -07:00
x25 treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
xdp Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-22 09:42:41 -07:00
xfrm ipsec-next-2025-05-23 2025-05-26 18:32:48 +02:00
Kconfig net: Kconfig NET_DEVMEM selects GENERIC_ALLOCATOR 2025-05-27 17:31:42 -07:00
Kconfig.debug
Makefile net: Retire DCCP socket. 2025-04-11 18:58:10 -07:00
compat.c
devres.c
socket.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-03-26 09:32:10 -07:00
sysctl_net.c