nsim_napi_rx() reads the skb's queue_mapping after skb_queue_tail() has queued it on the peer's RX queue, where the peer's NAPI poll may already have dequeued and freed it on another CPU. With AF_PACKET senders on one device, threaded NAPI on its peer and a 2 ms udelay() after skb_queue_tail() to widen the window, KASAN reports it within seconds: BUG: KASAN: slab-use-after-free in nsim_start_xmit+0x693/0x6c0 Read of size 2 at addr ff1100010124a57c by task python3/200 Call Trace: nsim_start_xmit+0x693/0x6c0 __dev_direct_xmit+0x2d1/0x420 packet_xmit+0x195/0x2c0 Freed by task 190: kmem_cache_free+0xf8/0x390 __netif_receive_skb_core+0x2155/0x2e30 ... gro_receive_skb+0x4f2/0xb10 nsim_poll+0xe2/0x420 Read queue_mapping before queueing the skb. Found with a prototype static analysis tool I am developing. The analysis, the reproducer and the fix were written with Claude Code (Claude Opus 5.5). Fixes: ff2ac4df58ad ("netdevsim: implement peer queue flow control") Signed-off-by: SeungJong Ha <engi…@gmail.com> --- I found this with a prototype static analysis tool I am developing. It checks drivers against ownership contracts of the networking core, and flagged the skb read after skb_queue_tail() hands the skb to NAPI. The analysis, the reproducer and the fix were written with Claude Code (Claude Opus 5.5). I reviewed every line of the patch and the commit message, and re-ran the reproducer myself. Tested in a QEMU guest with KASAN on net (6902a2bb708c). With a 2 ms udelay() added before the read to widen the window, the report shows within 10 s without this patch, and not once in 600 s with it. Without the delay it hit once in two 30-minute runs on v7.3. The netdevsim peer.sh selftest passes with this patch. --- drivers/net/netdevsim/netdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index eebc02ccc4a9..b68b108a1fc7 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -85,6 +85,8 @@ static void nsim_stop_tx_queue(struct net_device *tx_dev, static int nsim_napi_rx(struct net_device *tx_dev, struct net_device *rx_dev, struct nsim_rq *rq, struct sk_buff *skb) { + u16 idx = skb_get_queue_mapping(skb); + if (skb_queue_len(&rq->skb_queue) > NSIM_RING_SIZE) { dev_kfree_skb_any(skb); return NET_RX_DROP; @@ -94,8 +96,7 @@ static int nsim_napi_rx(struct net_device *tx_dev, struct net_device *rx_dev, /* Stop the peer TX queue avoiding dropping packets later */ if (skb_queue_len(&rq->skb_queue) >= NSIM_RING_SIZE) - nsim_stop_tx_queue(tx_dev, rx_dev, rq, - skb_get_queue_mapping(skb)); + nsim_stop_tx_queue(tx_dev, rx_dev, rq, idx); return NET_RX_SUCCESS; } --- base-commit: 6902a2bb708c4075d3de6ec18ab6a5864c4c1aa2 change-id: 20261206-b4-netdevsim-rx-uaf-5b5c8829282f Best regards, -- SeungJong Ha <engi…@gmail.com>