xen-netfront: unwind created queues when page_pool creation fails
Subsystems (5)
PATCH 1/1 xen-netfront: unwind created queues when page_pool creation fails
If xennet_create_page_pool() fails for any queue after the first, xennet_create_queues() returns without undoing the queues it has already set up, and talk_to_netback() then frees info->queues. The NAPI instances of those queues stay on the netdev's napi_list, pointing into the freed array, and their page pools, XDP rxq registrations and grant references leak, as do the grant references of the queue that failed. Reaching this needs an allocation failure in page_pool_create() or the XDP rxq registration during connect or resume.
Release the failing queue's grant references and unwind every queue created before it inside xennet_create_queues(). talk_to_netback() still frees the array; on this path neither xennet_disconnect_backend() nor xennet_destroy_queues() sees the queues, so nothing is released twice.
sashiko-bot found the bug while reviewing an unrelated netfront fix.
The patch builds without warnings at W=1 on net (gcc 12.4) and passes checkpatch --strict. The failure path was not exercised: no fault injection or boot test was run.
An AI coding assistant (Claude Code) was used to confirm the report, write the fix and draft this changelog.
--- drivers/net/xen-netfront.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/xen-netfront.c +18 -2
@@ -2244,8 +2244,9 @@ static int xennet_create_queues(struct netfront_info *info, ret =xennet_create_page_pool (queue);if (ret <0 ) {dev_err (&info->xbdev->dev,"can't allocate page pool\n" ); - *num_queues = i; -return ret; +gnttab_free_grant_references (queue->gref_tx_head); +gnttab_free_grant_references (queue->gref_rx_head); + goto err_unwind; }netif_napi_add (queue->info->netdev, &queue->napi, xennet_poll);
@@ -2260,6 +2261,21 @@ static int xennet_create_queues(struct netfront_info *info,return -EINVAL ; }return 0 ; + +err_unwind: +while (i--) { +struct netfront_queue *queue = &info->queues[i]; + +if (netif_running (info->netdev)) +napi_disable (&queue->napi); +netif_napi_del (&queue->napi); +xdp_rxq_info_unreg (&queue->xdp_rxq); +page_pool_destroy (queue->page_pool); +gnttab_free_grant_references (queue->gref_tx_head); +gnttab_free_grant_references (queue->gref_rx_head); + } + *num_queues =0 ; +return ret; }/* Common code used when first setting up, and when resuming. */
Signature · 1 line
2.56.0
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Wed, 25 Nov 2026 11:11:29 +0000 you wrote:
If
xennet_create_page_pool()fails for any queue after the first,xennet_create_queues()returns without undoing the queues it has already set up, andtalk_to_netback()then freesinfo->queues. The NAPI instances of those queues stay on the netdev'snapi_list, pointing into the freed array, and their page pools, XDP rxq registrations and grant references leak, as do the grant references of the queue that failed. Reaching this needs an allocation failure inpage_pool_create()or the XDP rxq registration during connect or resume.[...]
Here is the summary with links:
- [net] xen-netfront: unwind created queues when page_pool creation fails
https://git.kernel.org/netdev/net-next/c/21e3bc509753
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html