netdevsim: update queue NAPI association on queue reset
Subsystems (3)
PATCH 1/1 netdevsim: update queue NAPI association on queue reset
In netdevsim, receive queues (struct nsim_rq) embed their own struct napi_struct. When queue reset is performed (e.g. via queue_reset debugfs), nsim_queue_start() swaps in a newly allocated struct nsim_rq, and nsim_queue_mem_free() later deletes and frees the old one.
However, nsim_queue_start() failed to update the queue-to-NAPI mapping via netif_queue_set_napi(). As a result, dev->_rx[idx].napi continued to point to the old NAPI struct. After the old queue was freed, a subsequent queue dump via Netlink (NETDEV_CMD_QUEUE_GET) triggered a KASAN slab-use-after-free read in nla_put_napi_id() when accessing rxq->napi->napi_id.
Fix this by calling netif_queue_set_napi() in nsim_queue_start() to associate the new NAPI with the RX queue, and clear the association with netif_queue_set_napi(..., NULL) in nsim_del_napi() during teardown.
--- drivers/net/netdevsim/netdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/netdevsim/netdev.c +2 -0
@@ -529,6 +529,7 @@ static void nsim_del_napi(struct netdevsim *ns)for (i =0 ; i < dev->num_rx_queues; i++) {struct nsim_rq *rq = ns->rq[i]; +netif_queue_set_napi (dev, i,NETDEV_QUEUE_TYPE_RX ,NULL );napi_disable_locked (&rq->napi);__netif_napi_del_locked (&rq->napi); }
@@ -826,6 +827,7 @@ nsim_queue_start(struct net_device *dev, struct netdev_queue_config *qcfg, } ns->rq[idx] = qmem->rq; +netif_queue_set_napi (dev, idx,NETDEV_QUEUE_TYPE_RX , &ns->rq[idx]->napi);napi_enable_locked (&ns->rq[idx]->napi);return 0 ;
Signature · 1 line
2.55.0.699.gb54405d56f-goog
Quoted 37 lines · Eric Dumazet
In netdevsim, receive queues (struct
nsim_rq) embed their own structnapi_struct. When queue reset is performed (e.g. viaqueue_resetdebugfs),nsim_queue_start()swaps in a newly allocated structnsim_rq, andnsim_queue_mem_free()later deletes and frees the old one.However,
nsim_queue_start()failed to update the queue-to-NAPI mapping vianetif_queue_set_napi(). As a result, dev->_rx[idx].napi continued to point to the old NAPI struct. After the old queue was freed, a subsequent queue dump via Netlink (NETDEV_CMD_QUEUE_GET) triggered a KASAN slab-use-after-free read innla_put_napi_id()when accessingrxq->napi->napi_id.Fix this by calling
netif_queue_set_napi()innsim_queue_start()to associate the new NAPI with the RX queue, and clear the association withnetif_queue_set_napi(..., NULL)innsim_del_napi()during teardown.Fixes 5bc8e8dbef27 ("netdevsim: add queue management API support")Reported-by [email protected]Signed-off-by Eric Dumazet <[email protected]>--- drivers/net/netdevsim/netdev.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/netdevsim/netdev.c +1
-0@@ -529,6 +529,7 @@ static void nsim_del_napi(struct netdevsim *ns)for (i =0 ; i < dev->num_rx_queues; i++) {struct nsim_rq *rq = ns->rq[i]; +netif_queue_set_napi (dev, i,NETDEV_QUEUE_TYPE_RX ,NULL );napi_disable_locked (&rq->napi);__netif_napi_del_locked (&rq->napi); }
drivers/net/netdevsim/netdev.c nsim_queue_start(struct net_device *dev, struct netdev_queue_config *qcfg, · line 833
Quoted 7 lines
drivers/net/netdevsim/netdev.c +1
-0@@ -826,6 +827,7 @@ nsim_queue_start(struct net_device *dev, struct netdev_queue_config *qcfg, } ns->rq[idx] = qmem->rq; +netif_queue_set_napi (dev, idx,NETDEV_QUEUE_TYPE_RX , &ns->rq[idx]->napi);napi_enable_locked (&ns->rq[idx]->napi);return 0 ;
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Mon, 17 Aug 2026 08:25:11 +0000 you wrote:
In netdevsim, receive queues (struct
nsim_rq) embed their own structnapi_struct. When queue reset is performed (e.g. viaqueue_resetdebugfs),nsim_queue_start()swaps in a newly allocated structnsim_rq, andnsim_queue_mem_free()later deletes and frees the old one.
Quoted 8 lines
However,
nsim_queue_start()failed to update the queue-to-NAPI mapping vianetif_queue_set_napi(). As a result, dev->_rx[idx].napi continued to point to the old NAPI struct. After the old queue was freed, a subsequent queue dump via Netlink (NETDEV_CMD_QUEUE_GET) triggered a KASAN slab-use-after-free read innla_put_napi_id()when accessingrxq->napi->napi_id.[...]
Here is the summary with links:
- [net] netdevsim: update queue NAPI association on queue reset
https://git.kernel.org/netdev/net/c/07e98a4d5e9c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html