πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13701

[PATCH net v3 2/2] virtio_net: Disable AF_XDP pools on queues above curr_queue_pairs

#13701
From: Haishuang Yan
Date: Tue, 10 Nov 2026 15:30
57 lines
11337 bytes
With an XDP program attached, virtnet_xdp_set() adds nr_cpu_ids queue
pairs for XDP_TX and raises curr_queue_pairs and real_num_rx_queues to
match. virtnet_xsk_pool_enable() accepts any queue below
curr_queue_pairs, so an AF_XDP zero-copy socket can be bound to one of
them.

When the program is removed, the queue count goes down again while the
pool stays bound to the driver. When the socket is closed afterwards,
virtnet_xsk_pool_disable() rejects the queue with -EINVAL, and the core
frees the pool anyway:

  WARNING: net/xdp/xsk_buff_pool.c:160 at xp_disable_drv_zc+0x1ee/0x260
  BUG: KASAN: slab-use-after-free in xp_alloc_batch+0x930/0xb40
  Read of size 8 at addr ffff8880028eb400 by task ksoftirqd/0/14
   xp_alloc_batch+0x930/0xb40
   try_fill_recv+0xb27/0x26e0

as rq->xsk_pool still points to it and the queue is refilled from it.

The device going away with XDP attached, e.g. on hot-unplug or driver
unbind, ends the same way without an explicit removal:
unregister_netdevice_many_notify() removes XDP before the xsk notifier
unbinds the socket, so the pool is disabled on a queue above
curr_queue_pairs there as well.

Removing XDP must not fail, so let virtnet_xsk_pool_disable() accept
any queue the driver has, below max_queue_pairs. The receive and send
queues above curr_queue_pairs still exist, so they are unbound as usual.

This was pointed out by the Sashiko review of v1 of this series, and
reproduced in QEMU by binding a socket to an XDP queue and then either
removing XDP and closing the socket, or unbinding the device from
virtio_net.

Fixes: 09d2b3182c8e ("virtio_net: xsk: bind/unbind xsk for rx")
Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
---
 drivers/net/virtio_net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4f5d8812f75b..f9d227060375 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -6030,7 +6030,8 @@ static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid)
 	struct send_queue *sq;
 	int err;
 
-	if (qid >= vi->curr_queue_pairs)
+	/* Removing XDP can leave the pool on a queue above curr_queue_pairs */
+	if (qid >= vi->max_queue_pairs)
 		return -EINVAL;
 
 	sq = &vi->sq[qid];
-- 
2.43.0
Technical Details
Message-ID: <20261110153003.23731-3-yanhaishuang@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359945-linux-kernel-netdev=dewy.ru
References: <20261110153003.23731-1-yanhaishuang@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359945-linux-kernel-netdev=dewy.ru
From: yanhaishuang@cmss.chinamobile.com (Haishuang Yan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 2/2] virtio_net: Disable AF_XDP pools on queues above curr_queue_pairs
Date: Wed, 11 Nov 2026 00:30:01 +0900
Organization: Usenet Network
Message-ID: <20261110153003.23731-3-yanhaishuang@cmss.chinamobile.com>
References: <20261110153003.23731-1-yanhaishuang@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="552200"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+cmHP0kaJlQIETPavXt6Njyl0Nk= sha256:AZCcbYSTooWuxkvMGfvCsSmKN4TIZtMtGLQ1fZF0e7w=
	sha1:3OQJZ3W1cFH6ZW1GWwyjEePgrRI= sha256:VBcmuwibFFw26A2mU9REIGgPuuTBwvfUYoyPwHTVoFs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 2E683113A7C; Tue, 10 Nov 2026 10:46:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.749
X-Spam-Status: No, score=-2.749 tagged_above=-9999 required=6.31
	tests=[DATE_IN_FUTURE_06_12=0.001, DCC_REPUT_70_89=0.1,
	DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id iIixERRcGMUq;
	Tue, 10 Nov 2026 10:46:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-359945-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 641151139D8; Tue, 10 Nov 2026 10:46:31 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 7418138CE9; Tue, 10 Nov 2026 07:37:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794296195;
	b=pucPICCThx8CKxa6AYted20KzbA+Ktn7QMqpdKASlN72OFHqaFTX8MzHQBMrwZjDrYFQ
	 0oFMWc1nlXjSU+akEBn/AH6xbYE+1MDeqO26Th1r5v/DeQq4cxvv4a2orprcIvU1QSDbF
	 tn+U5rurXiEbu0WLtsjZ+eY/nFtYOugF7QvLKzItgam9eRU+lAsbUYaTCG4oT7EDYjxx8
	 QTIEtLkjMVRi6K1rwyQAeLGqqT/nkGqLgTaWKIgo1hzAk8BqNoQDdBLN2XhxylGY6VbXd
	 mPX0b3t+FeCLieM3f+7YfBZeY3KGYkke9uTg1aOySvozV01x/JKXp3F3jxXJXQwUvjw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794296195;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=QQphr5euVsYvR57wxTaQJrr/VmZFbUsWVLJgzTq93eA=;
	b=ap4gaHv2YTpssvd3D4PaOt026B8IsQgDzzzKSdgl/FzesIWu+fG+L/9BalFYzdNiVy23
	 1XYhj8PSDdys2eeF9/MQVFicjKCNg2WohOEaUuZWeQO0st5XHALNYi/OhGI1+D2I555xg
	 rv8pNTw8mMZh090aSHl3aAVgcJVXjDAwjjucv07HkInbVir5eKuSQ/2igFKHbomNidLLK
	 XJX6uriAgqei8HVQ/H69jtg7smpOpUZIk3PHAqQZofJrinAimXJfk2tkYauwRXCrKNEDv
	 7Y+I75VrATMS9RN8rpZ5LgPpQNe5CyZIJn6vhNCsNaW/OQrW7DaxDVYcuisYuRrt+6Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=faDfODPK;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D30D60A2620;
	Tue, 10 Nov 2026 07:36:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=faDfODPK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.139
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794296194;
	b=WAhVGjNzaC4SDYGQeskdmL64W/gSzububTXBQQYSAbg5vJBXEMxy0m5bUBeLksIPxwbn
	 NIVQ+lKFg3FtjTCNRLjq1oSP3DN3OHzaJfgPM04Geh3uOQzThtSivfOZKAULofConhI+J
	 2gkDG+LcMn00hFKE0QXzFZk/Lx/bygwJC3o1l04myWQSRXs0/zCM3k0Lm+EyyoZTskr+b
	 VzSfNKSPoVN7DthOmnHu3LJUvW7YSoKIRlD875G/DCuOpsxRpnYKU7rK2af4UGQ3HfZCG
	 iRiVE00K64kzBCT5/GeGPp0gQgG9OsjXDxhVP/WizspmEZJK7MzmqczV5tlAY/HepBQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794296194;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=QQphr5euVsYvR57wxTaQJrr/VmZFbUsWVLJgzTq93eA=;
	b=VYbiAZ+zvJuQCaMu37tBlZ20IGF+9+nrCp4lBOlzgJKmT33TD46P13Pe4vdaPYAhZdfd
	 paI5xxRn/VxVohWOWQRuSvuzfPShSo3tPh/IKXijo+Lvf+EL9vY/atOgwd+Ntd9tL/1ud
	 gXDHoj+ijn+JGFMDJEfP8UZbGJLQxcwKuImGBsl8AfRKX3cA3EXaKK9sGksVT877hCwpy
	 IXfQbEY78/grsuGjijhSBU/88LRxHTLT/DbLm81ICaTGgsGlQMZFVVNxdHdy14/0m874p
	 6KHldrfr0lOOf7akjZegnrimspBLv87BxAhHBwubw9hwKBnrVciXDUnvshrYSUE83gg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=faDfODPK;
	arc=none smtp.remote-ip=111.22.67.139
X-Received: from cmccmta6.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 67A5160A260C;
	Tue, 10 Nov 2026 07:36:33 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67A5160A260C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=faDfODPKGCL0NiCe7ruPNzlVNMD4hbQVfyDslV67WGRRk6+leMiHWdWw+tEly6OPTmK/dhHH7G7OV
	 nVIOcLvwqUg9LPG2v5Oa8vznochR+NlHxAc8+hHC63QDAp7zENIabDM2ooy5HfWEqmS7Zx/QfWWoyf
	 2Op59Q4aNQ/Z3eKM=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app01-12001 (RichMail) with SMTP id 2ee16af2c97fc53-a8049;
	Tue, 10 Nov 2026 15:36:32 +0800 (CST)
X-RM-TRANSID: 2ee16af2c97fc53-a8049
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from  (unknown[74.82.203.40])
	by rmsmtp-syy-appsvr03-12003 (RichMail) with SMTP id 2ee36af2c970885-ab73e;
	Tue, 10 Nov 2026 15:36:32 +0800 (CST)
X-RM-TRANSID: 2ee36af2c970885-ab73e
X-Cc: Eugenio PΓ©rez <eperezma@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	netdev@vger.kernel.org,
	virtualization@lists.linux.dev,
	bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261110153003.23731-1-yanhaishuang@cmss.chinamobile.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list