🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23305

[PATCH net] bonding: check slave xdp_features in bond_xdp_xmit

#23305
From: Hangbin Liu
Date: Fri, 27 Nov 2026 03:08
79 lines
11307 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>

bond_xdp_xmit() may select a slave that bond_enslave() made visible
before bond_xdp_set_features() republished the bond's xdp_features.
Frames enqueued in that window pass __xdp_enqueue()'s bond-level
checks, and the bulk-queue flush later calls bond_xdp_xmit() without
rechecking anything. The selected slave may be unable to transmit
XDP frames:

  - NETDEV_XDP_ACT_NDO_XMIT appears only once the driver's XDP TX
    queues are up.
  - a linear-only slave receives multi-buffer frames enqueued while
    the bond still advertised NETDEV_XDP_ACT_NDO_XMIT_SG.
  - with no bond->xdp_prog, bond_enslave() skips the capability
    check: a slave without XDP joins while the bond still
    advertises NETDEV_XDP_ACT_NDO_XMIT (built from the other
    slaves; __xdp_enqueue() never looks at dev->xdp_prog) and
    bond_xdp_set_features() drops the flag only afterwards.

Apply the __xdp_enqueue() contract to the selected slave at xmit
time: require NETDEV_XDP_ACT_NDO_XMIT and, for fragmented frames,
NETDEV_XDP_ACT_NDO_XMIT_SG, failing with -ENXIO otherwise (the
caller frees the frames).

Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Cc: stable@vger.kernel.org # b9d460c92455 ("bpf: devmap: check XDP features in __xdp_enqueue routine")
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
The issue was identified when sashiko review other patches.
The issue is theoretical and only happen in a race window, I didn't
reproduce it.

For Sashiko,
Please ignore the error out issues during bond_enslave. They will
be addressed in other patches.
---
 drivers/net/bonding/bond_main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 042d7c75548f..6ceefb0bfc20 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -5664,6 +5664,7 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
 		struct xdp_frame *frame = frames[nxmit];
 		struct xdp_frame *frames1[] = {frame};
 		struct net_device *slave_dev;
+		xdp_features_t feats;
 		struct xdp_buff xdp;
 
 		xdp_convert_frame_to_buff(frame, &xdp);
@@ -5674,6 +5675,18 @@ static int bond_xdp_xmit(struct net_device *bond_dev,
 			break;
 		}
 
+		/* The slave can be selected before bond_xdp_set_features()
+		 * republishes the bond's xdp_features, so apply the
+		 * __xdp_enqueue() contract to the slave itself.
+		 */
+		feats = READ_ONCE(slave_dev->xdp_features);
+		if (unlikely(!(feats & NETDEV_XDP_ACT_NDO_XMIT) ||
+			     (!(feats & NETDEV_XDP_ACT_NDO_XMIT_SG) &&
+			      xdp_frame_has_frags(frame)))) {
+			err = -ENXIO;
+			break;
+		}
+
 		err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
 		if (err < 1)
 			break;

---
base-commit: e1055cbfd6eb578417f3ce983cf44462e8465267
change-id: 20261127-bond_xdp_xmit-5dfe5b99d10c

Best regards,
--  
Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID: <20261127-bond_xdp_xmit-v1-1-c2a7b622b95d@kylinos.cn>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372423-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372423-linux-kernel-netdev=dewy.ru
From: hangbin.liu@linux.dev (Hangbin Liu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] bonding: check slave xdp_features in bond_xdp_xmit
Date: Fri, 27 Nov 2026 11:08:54 +0800
Organization: Usenet Network
Message-ID: <20261127-bond_xdp_xmit-v1-1-c2a7b622b95d@kylinos.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="625061"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DTOLV6pVwK8+zwSpsZ7Bi1rVYfE= sha256:+AS2ZaZjreRSNSBexKC0ucg5LElUJgbZrwWK0OrIr5s=
	sha1:TxvTumMqH9gqZ3HKcAdQ1bToy6o= sha256:pe8eCOadgTeQG0HkMU9teHadsDWe3dhC/EhZ3JTPJZo=
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 07096125F0D; Fri, 27 Nov 2026 06:09:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-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] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
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 GpsfGcYNjx0B;
	Fri, 27 Nov 2026 06:09:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372423-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E8766125F04; Fri, 27 Nov 2026 06:09:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3759A31947; Fri, 27 Nov 2026 03:09:10 +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=1795748950;
	b=tW551smYjsJ6vsAkhR5DU9iuVH+bxLez6fZ7WDuJlh3mXURhwacPpX9D7TVx65le8qO+
	 RrAfcHGGSif1REUpagCS1NW6xfcRoE1+JJjjo6HmRQBrJ+ct6QK39R33S50cRzj4dla6J
	 oHL439lHS2aqvVlxmqXsptMYP0ER0zKPHDnzaB84NrY2dq3ZvpjSq0KHiqfYCYIOr8XPU
	 R7uVPDb9KGWk57P3SR1ECJr4HT7p0W/xV35+khofCRUseZFHnPvi4peW/LpOYmydYevki
	 3jxMQBXYLpLgM03dqmRmlso3wl8/C6xGKGbKBu7DUXhFAow1Cx032v7kVdN0o+CJDIg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795748950;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:
	 X-Mailer;
	bh=T6qnIZ7knEuhMvn/FGLmk9K4xZfB2NGqdkhivjTYbDY=;
	b=ETFllQL4HpsaqpOZkuuNqTSQkXOiiiP54INrzLgcsrty5tMq93zF0l0ezzA8oOjoLIQn
	 4zdBpE0LEb29d5MTMimu90/oJvcKz6KJXc753tDdWqG5hOYewS7sC34/CAOf6Yeflj3PH
	 iRP7boQpFbtoiO5EFFrkPE4cHppbDLzZCvYx2A8CajdPrErZYKOPOzOMbzdYvbjjGgtSB
	 UG5pZJjwZL/btWQ+qojVMpoZxFz141I6Npi8rkIu8ME/d4Jzir2jdhYD7i+aM4DMFC5JK
	 2pkF0LOTl93aPi/QrJ4oB4AygY8cOUvzpunITKE6UNp0qck0KtIVRPTWsoBOsPVqA4g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=s0BSqbI+;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 0EAA3606A32A;
	Fri, 27 Nov 2026 03:09:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=s0BSqbI+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.215
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795748949;
	b=hqWFkx/JWQwCiOv0P/w9qAodrDqfP7jU0B3iQKA29MBpaOwBLWCBcoiqVoevAPWBw2CM
	 NAoSx5OBjrfqJURyAA9lka/Ra9TUq1Qvyb3EJRsBX2vJPe0cJeO5T8ro58qmTbG2l/X9D
	 7BiGS3bYy/1iyJCxf0bSj8ilGb8AATfXh+6+1cDPRrsT3yYeRXPtK6PYetnpsz37Q6Liz
	 6CIzlaiZONVrg765ylQHdUVsF2qPoXhDyFl55y6eXgnw5DqvYzrEqKx84vRP/Gc3rgwej
	 mHGm4V+DD00ik9hd6e63uOyE9AAYaeBE6iqr994zda8VWRPZdiXORRllTNFr5vceWOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795748949;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking:
	 X-Change-ID:To:Cc:X-Mailer;
	bh=T6qnIZ7knEuhMvn/FGLmk9K4xZfB2NGqdkhivjTYbDY=;
	b=HO4O3OWvSmy992mXtadqTNsdoI2cLIs2hOZlaBN5CeDBKGePJw/0COM8YBzqccd4Wip8
	 eREg4gK5Rr+8y+Z12HejufuXuVMRuhJ7dVmFQ66T/YmakkL5RUVeqLb8f7KaKPp5s8cpC
	 G+a7Eo4oIrI42GBRD5ssG1u6fYMTLmKSwlnRrPPxHCHbAtpJS7h2V/F0XXNNXuumsiRZT
	 L9W8FDJ2OuPLn7DTHebGtBzt8jHNV+3VR5exDepRuUPh0bDgPezIo9H0TYrUBV57zbxzK
	 nh/qkBuxaqX1e6FjjKJLwrR5M9YUtImDeghm7fGgXsk1nHy7GZNkmm1zc5xKc/lre/w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=s0BSqbI+;
	arc=none smtp.remote-ip=91.218.175.215
X-Received: from mta0.migadu.com (out-215.mta0.migadu.com [91.218.175.215])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 596E7606A327
	for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 03:09:06 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 596E7606A327
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=mCX+dAX2Y234AOj5HIr3xihBIeZcfHva9jzek9gcGfU=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795748945; v=1; x=1796353745;
 b=s0BSqbI+eAbIQqC7WMFoNdn47RylD755qd0VR+036T8m52Ar8tR63oEecIsgItGiKgs2C/vv
 UkxVguf2TdE07mwDwTK1ddkUxop3ynfH9Gb/V2tdjk05xa9Bd1RrZ/x+RCM8U8pKjJNsqNwstsa
 72nOPI+k3ushVLwMUPQOzHrQ=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta11.migadu.com with ESMTPS id cfccce07b52ac0bc;
	Fri, 27 Nov 2026 03:09:04 +0000
X-Mizu-Trace-ID: cfccce07b52ac0bc
X-Migadu-Flow: FLOW_OUT
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
X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWMUQqDMBAFryLvuwETsGKvUoqY7Gq30ChJlIB49
 6b6OQMzOyIH4YhHtSPwJlFmX0DfKrj34CdWQoVhanPX2rTKzp76TEufv5JUQyM3tutI1w6lWQK
 Pks/fE54TXpeMq/2wS/8TjuMHzHcuNnYAAAA=
X-Change-ID: 20261127-bond_xdp_xmit-5dfe5b99d10c
X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, 
 bpf@vger.kernel.org, stable@vger.kernel.org, 
 Hangbin Liu <hangbin.liu@linux.dev>
X-Mailer: b4 0.16.0