Netdev List
 help / color / mirror / Atom feed
* [PATCH net] xen-netfront: unwind created queues when page_pool creation fails
@ 2026-11-25 11:11 Mark Syms
  0 siblings, 0 replies; only message in thread
From: Mark Syms @ 2026-11-25 11:11 UTC (permalink / raw)
  To: jgross, sstabellini, oleksandr_tyshchenko, andrew+netdev, davem,
	edumazet, kuba, pabeni
  Cc: hawk, ast, daniel, john.fastabend, sdf, netdev, xen-devel, bpf,
	mark.syms, stable

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.

Link: https://lore.kernel.org/r/sashiko-outbox-232996@kernel.org
Fixes: 6c5aa6fc4def ("xen networking: add basic XDP support for xen-netfront")
Cc: stable@vger.kernel.org
Signed-off-by: Mark Syms <mark.syms@citrix.com>
---
 drivers/net/xen-netfront.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index fdcb91042f29..9abae76871f3 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -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. */
-- 
2.56.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25 11:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:11 [PATCH net] xen-netfront: unwind created queues when page_pool creation fails Mark Syms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox