🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13401

[PATCH net-next v2 1/5] hv_netvsc: fix the program refcount when the VF refuses XDP

#13401
From: Jakub Kicinski
Date: Mon, 09 Nov 2026 19:48
93 lines
11214 bytes
ndo_bpf() takes over the reference it is passed only on success, the
caller puts it back itself on failure. netvsc_xdp_set() takes that one
plus num_chn - 1 more for its channels, and the rollback after the VF
refuses the program clears the channels again, putting all num_chn of
them. dev_xdp_install() then puts the one it passed in a second time,
and the program can be freed while the fd which loaded it still points
at it.

The VF refuses a program netvsc has already committed to when the
program is single-buffer and the VF has header-data split enabled, when
the VF has a memory provider bound, or when the VF's driver has
conditions of its own.

The rollback clears the channels rather than putting back the program
they ran before, too. A refused replace or removal then leaves the
synthetic path running no program at all, while the core and the VF
keep the old one. Put the old program back instead.

Reported by Sashiko during core rework. Unverified and untested.

Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path
Fixes: 184367dce4f7 ("hv_netvsc: Fix XDP refcnt for synthetic and VF NICs")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
 - put the old program back on the channels rather than clearing them
   (Kameron)
 - reword the comment on the extra reference, it's the caller's, which
   isn't always the core
 - Tested-by tags from v1 not carried over, the rollback changed
v1: https://lore.kernel.org/20261001014131.310771-2-kuba@kernel.org
---
 drivers/net/hyperv/netvsc_bpf.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_bpf.c b/drivers/net/hyperv/netvsc_bpf.c
index 1dd3755d9e6d..fcc60729384e 100644
--- a/drivers/net/hyperv/netvsc_bpf.c
+++ b/drivers/net/hyperv/netvsc_bpf.c
@@ -197,6 +197,7 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 	struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
 	struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev);
 	struct netlink_ext_ack *extack = bpf->extack;
+	struct bpf_prog *old_prog;
 	int ret;
 
 	if (!nvdev || nvdev->destroy) {
@@ -205,10 +206,17 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 
 	switch (bpf->command) {
 	case XDP_SETUP_PROG:
+		/* Hold on to the old program, to put it back on the channels
+		 * if the VF refuses the change.
+		 */
+		old_prog = netvsc_xdp_get(nvdev);
+		if (old_prog)
+			bpf_prog_inc(old_prog);
+
 		ret = netvsc_xdp_set(dev, bpf->prog, extack, nvdev);
 
 		if (ret)
-			return ret;
+			goto put_old_prog;
 
 		ret = netvsc_vf_setxdp(vf_netdev, bpf->prog);
 
@@ -216,9 +224,22 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 			netdev_err(dev, "vf_setxdp failed:%d\n", ret);
 			NL_SET_ERR_MSG_MOD(extack, "vf_setxdp failed");
 
-			netvsc_xdp_set(dev, NULL, extack, nvdev);
+			/* The caller hands us its reference to bpf->prog only
+			 * on success, take one so that putting the num_chn
+			 * channel references below doesn't consume it.
+			 */
+			if (bpf->prog)
+				bpf_prog_inc(bpf->prog);
+			/* Can't fail, old_prog has passed the same checks
+			 * before. The channels take over our reference to it.
+			 */
+			netvsc_xdp_set(dev, old_prog, extack, nvdev);
+			return ret;
 		}
 
+put_old_prog:
+		if (old_prog)
+			bpf_prog_put(old_prog);
 		return ret;
 
 	default:
-- 
2.56.0
Technical Details
Message-ID: <20261109194843.1353592-2-kuba@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359577-linux-kernel-netdev=dewy.ru
References: <20261109194843.1353592-1-kuba@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359577-linux-kernel-netdev=dewy.ru
From: kuba@kernel.org (Jakub Kicinski)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2 1/5] hv_netvsc: fix the program refcount when the VF refuses XDP
Date: Mon,  9 Nov 2026 11:48:39 -0800
Organization: Usenet Network
Message-ID: <20261109194843.1353592-2-kuba@kernel.org>
References: <20261109194843.1353592-1-kuba@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="436988"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CiUSW4Cpom4tdugZP3B5efTmHgI= sha256:9pS83+RzdBjI49xQqdbza6TBwjaWJX6GTjsBcBkHnTY=
	sha1:cgF7apbhNjZVuoSq7TJ7oOYa22k= sha256:yhHhwVm2RXQuoupPpWLs2YWQrZ9qcLk2C89Jnc82BOA=
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 7C93B1138FC; Mon,  9 Nov 2026 22:51:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 wZcmgdYEXyNG;
	Mon,  9 Nov 2026 22:51:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359577-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 7323D1138C2; Mon,  9 Nov 2026 22:51:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 342B468401; Mon,  9 Nov 2026 19:49:02 +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=1794253736;
	b=GDNgNPpR90wr5vhTlutfihTOExWbIX6G1qrsX9Ex7Qt1+m9xfcS/RmX5P0nEETaqldl7
	 deSmRXLOUINr3fjhwwaq76zne192NA4OGyfRhkilS+vHIrTfBEXdbvPsprKmTDiS/Erg5
	 /SCGItm5m22LNSjyQ88l3qQHCYOcsZKNCw5lQaoh44lQ8A0zVTnF3aans6eijy9g+ylgO
	 o92i8VpBwDLvPO6oItuAo8uDksqzxP84wIw9SoBjeC5dO4tomltdA7Yt/ovHR0DFX3kNL
	 sQ1+dHTfl8uprMRNiaUyrvM7a87SQaq8Tj+/jwwxifc+8nK3KB+cPCt1UcnYLlVkSjA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794253736;
	h=X-Original-To:Received:Received:DKIM-Signature: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=CSRtMtlF+ByoNSybcSp5RPlobIyfbjmSYQic9q5nQeg=;
	b=m5ypMO2rR5GT9kmQU4KrjUWyrUurIGvGykvDwhnvpJnqR32reFDc4VV+EQP8tJZedL/u
	 ucsySG16/1YCZPjg0+83M2GxutqbdbXfPop8VSlttzuZNWTzqggdu8w6gtRTbu+ZuPK4M
	 da5qXfSCQb4K/f3O6oCR+Y5SB8ElPEj1r+WQkNE4+JEL+3pbVLGd68Ma0k7JJ1Jt3fsj7
	 ox4QlKIUHJe2LAUj+HZphZYjilLNXhZOiLqFO3zqBkbzYqeP5k5yp5+zLpu9SynEftJRK
	 m1FNh1/POA/NvGRu+ejb7NSuRj5Byu9m8zdXQSS3QhQ35zC9o/3KWb+tWkQfXmb3kbg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QtaJIGVl;
	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 2FAED606A336;
	Mon,  9 Nov 2026 19:48:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QtaJIGVl
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794253730;
	b=xxiBrD+SLBcuE/ekIm3Z0k2gbmHVAsB7SmHM6X06Fj0RMCg6CxcqV43CeLUl+udbaU7r
	 aTeLRKARtAN74nrkRtURGlcie7Tp5lVTk1cjyscibQXHDJYyMJ35+6V7atEpGeYqMBnng
	 f9XdCz1ZzoRZTQK1T2Kn5JT/IxF97Yw2KSQ2RRd/seucFq2Q4dmZx9uUE+jALTMGcLS+B
	 RDhhhqebW2JsJGugsNQXafCKUwalA2RQxjrss/ByKNnyXlYg5tkNYJzCYbJwa3M+uG2DC
	 o0pDK/heT2qXOAZxzeSHu3Cnq2QfqZNybN+sZlKFUMVbsnjigiN46xi3Ek5V1q5mmig==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794253730;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=CSRtMtlF+ByoNSybcSp5RPlobIyfbjmSYQic9q5nQeg=;
	b=RpW+fCnznMEi17ELzAKUtpMpxYbQErOZXurxUB5VAQB2UWUfuqMhcpCasELzrNZw6O8D
	 pxHX8PUSVOzIsXs3qztwaLApfROxRSgsUO89m72uG1V+Uoubxm3CtmQa1TF4VYFTK9hGO
	 m7SgJdiWEqtTUkX2D57Sr9B0bwe7XGwyBcZ+y5yDNn9a5erznkrCodPI4cfR6IReX5ouD
	 OkcadlPQ9ujDWSj7cL8aGpCqBZpQF/iBqLYlX3h3fTQJy6aTqanLzhHjrDcEwUiryged6
	 vImZfCaIzROP7sdTGJxR+rJqQH/7naGTyIipK0KdgCQAstgrIQicbp1VMK/LB578M9Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QtaJIGVl;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2928606A325
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 19:48:49 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFB9D1F008A7;
	Mon,  9 Nov 2026 19:48:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794253729;
	bh=CSRtMtlF+ByoNSybcSp5RPlobIyfbjmSYQic9q5nQeg=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=QtaJIGVlNomKVZ7q8DUBDOVFeDTaxD2G+SiB457BkpMZYZvT6UtT/CyM/s4bVtFMn
	 B8zDkATsbXpbkj/afM99iZoNRjk7tKse6ItXKne5hRck6HFtcPmiBxmHz22iQ24q1P
	 I5fb13uLOsdPXGB+NWSqFssAB5E+g+rPlLH9s/AvKDipPs0wXZXITmHgHmXPW1/WUM
	 eO7qzo2ZY8qvMFo8ofuH0eC20PWfhzBik1fHqUSFlyCgfU+cnrxXmb/w7cTBd6waFG
	 5i7Hs7AKamMWe4gHS5xAxu8SuuY34zwc8xAzv8FKAC97LrdvPicCw+pGnVKjtYytkO
	 oXL8mCDuvVdjQ==
X-Cc: netdev@vger.kernel.org,
	edumazet@google.com,
	pabeni@redhat.com,
	andrew+netdev@lunn.ch,
	horms@kernel.org,
	haiyangz@microsoft.com,
	wei.liu@kernel.org,
	decui@microsoft.com,
	kameroncarr@linux.microsoft.com,
	ernis@linux.microsoft.com,
	Jakub Kicinski <kuba@kernel.org>,
	stable+noautosel@kernel.org
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261109194843.1353592-1-kuba@kernel.org>
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