🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11952

[PATCH net RESEND v5] bonding: fix slave_cnt leak on XDP error paths

#11952
From: Hangbin Liu
Date: Fri, 06 Nov 2026 01:34
112 lines
12619 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>

When bond_enslave() succeeds up to the XDP setup stage, slave_cnt is
already incremented. If XDP setup subsequently fails, the error paths
jump directly to err_sysfs_del, bypassing the slave_cnt decrement.

This causes slave_cnt to drift upward on each failed enslaving attempt,
which would lead to unbalanced traffic distribution with round-robin
mode.

Add an error out to make sure slave_cnt gets decreased correctly.

Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
This issue is found during code review. The reproducer is from
Eric's patch

  ip link add bond0 type bond mode balance-rr
  ip link set bond0 xdpdrv obj xdp_dummy.bpf.o sec xdp
  for i in 0 1 2; do
    ip link add d$i type dummy
    ip link set d$i master bond0   # fails: Slave does not support XDP
  done

num_slaves read via SIOCBONDINFOQUERY is 3 before this patch, 0 after.

For Sashiko:

This patch only focuses on fixing the bond_slave_cnt leak issue.

1. `bond_xdp_xmit()` may call the slave's `ndo_xdp_xmit` before checking
whether `slave->netdev_ops->ndo_xdp_xmit` exists. This is a separate issue
and I will address it in another patch.
2. `bond_slave_ns_maddrs_add()` and device promiscuous/allmulti error
handling are also separate issues, which I will fix separately.

PS: I'm working on a restruct of bond_enslave to fix all these issues.
---
Changes in v5:
- Re-post, no code change.
- Link to v4: https://lore.kernel.org/r/20260914-bond_slave_cnt-v4-1-d14864a39e60@kylinos.cn

Changes in v4:
- Revert to v1 version as the bond_select_active_slave() just under
  slave_cnt increase also calls bond_update_slave_arr() (sashiko)
- re-run all bonding selftests with debug kernel, all passed.
- Link to v3: https://lore.kernel.org/r/20260907-bond_slave_cnt-v3-1-57df3b3cf2cb@kylinos.cn

Changes in v3:
- move the slave_cnt increasement before bond_update_slave_arr() (selftest)
- run all bonding selftests on debug kernel to make sure no regression (Jakub)
- Link to v2: https://lore.kernel.org/r/20260903-bond_slave_cnt-v2-1-02e27304ca36@kylinos.cn

Changes in v2:
- move the slave_cnt increasement after XDP setup (Nikolay Aleksandrov)
- balance-xor mode is not affected, not mention it (Nikolay Aleksandrov)
- Link to v1: https://lore.kernel.org/r/20260902-bond_slave_cnt-v1-1-36e95bf4a6ff@kylinos.cn
---
 drivers/net/bonding/bond_main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index a1c156c145b2..34f1b8083fbb 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2305,7 +2305,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 			SLAVE_NL_ERR(bond_dev, slave_dev, extack,
 				     "Slave does not support XDP");
 			res = -EOPNOTSUPP;
-			goto err_sysfs_del;
+			goto err_slave_cnt;
 		}
 	} else if (bond->xdp_prog) {
 		struct netdev_bpf xdp = {
@@ -2319,14 +2319,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 			SLAVE_NL_ERR(bond_dev, slave_dev, extack,
 				     "Slave has XDP program loaded, please unload before enslaving");
 			res = -EOPNOTSUPP;
-			goto err_sysfs_del;
+			goto err_slave_cnt;
 		}
 
 		res = dev_xdp_propagate(slave_dev, &xdp);
 		if (res < 0) {
 			/* ndo_bpf() sets extack error message */
 			slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
-			goto err_sysfs_del;
+			goto err_slave_cnt;
 		}
 		if (bond->xdp_prog)
 			bpf_prog_inc(bond->xdp_prog);
@@ -2348,6 +2348,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 	return 0;
 
 /* Undo stages on error */
+err_slave_cnt:
+	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
+
 err_sysfs_del:
 	bond_sysfs_slave_del(new_slave);
 

---
base-commit: fafbc4051123d5459ea6950899cec08ed946e278
change-id: 20260807-bond_slave_cnt-88e78c5f0ab9

Best regards,
--  
Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID: <20261106-bond_slave_cnt-v5-1-40857a722b6c@kylinos.cn>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357696-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357696-linux-kernel-netdev=dewy.ru
From: hangbin.liu@linux.dev (Hangbin Liu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net RESEND v5] bonding: fix slave_cnt leak on XDP error
 paths
Date: Fri, 06 Nov 2026 09:34:32 +0800
Organization: Usenet Network
Message-ID: <20261106-bond_slave_cnt-v5-1-40857a722b6c@kylinos.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3771450"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Zyvt9a1aChtZYDpeVag9jJph6eU= sha256:LF2R6hSNPc+CIzB+BQrtuJTZM5eMNBOwt9rANMUJZ/Y=
	sha1:s6NnBOFasWb/EgVxA1ZVaEbmJb8= sha256:zQQ2nuK8nY0wAcNlN+p7bRXYVfZSPF368Y4rXgnB1hE=
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 7399F112E3C; Fri,  6 Nov 2026 04:36:04 +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 tjTxLADBJB5N;
	Fri,  6 Nov 2026 04:35:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-357696-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id A8599111FA8; Fri,  6 Nov 2026 04:35:43 +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 9A44926EBC; Fri,  6 Nov 2026 01:35:11 +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=1793928911;
	b=2I+wuVfrYdy7xzae9I35x8kRNdoF0WY2XiBeoLTY1WhcySqg6pybxAIZtpjxX+F0m9dH
	 NZ2LBykB50lXdPa3zyl27tXhmVOLbvONMbgjzAPmcS//EhkhI//ebU8bVgEYUU8CZ9nf9
	 +pbh2vzDyHhiEqgroayxIwAFiHQdxWo6X8n5vGNiPiTsg+Q6NmBdjLamlPhtu47jWcMUs
	 3IPdDo9NWzoCK7QJ4E+p9TDa7QIfcohW1Hbyr1CfsRcvDnHGt38hdbu+lnI9PVh6098NL
	 FOZTTim7xPdZx+6Cr3R7kqX7NKGC7Hu4QJDYOz3S/Oh7SUcSFv+u7zgVwHp7iTOOX9Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793928911;
	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=37zF0J9YNQQfNg00zUsp96qSKKkGdLAWq7jkYoSVkEw=;
	b=Aa9btBJAHduhG9Iq5zOPFDz+RTflpDMdW/vjl9IB0fbiuxmI+6NBxwxXZ9GDE3FzQN1k
	 eZMRt/gSFHJoBgBbjJJxFLzpyVU9jBhD8wW9iVqIxb+vBRP0J3uLrMlAa7CjHMMFzqrKh
	 mWQaJpZUSVdGdm3a7mwL5kyBWM1gG2UBeKuTUgoaRYuraLSFhySNhqXnNCV46qPaVa/B2
	 UYRiesReEW+lHxT68TP0vcvNbsmXVzUukL2Zab5usL6+Q3E/Sa6A06eiGwP2FDG7qjNXQ
	 0OMlOpL+H7wfy3rvirxhPsSUGt0sXx3H7O0Urpr6pR3apmI6iZzxzpo20ja3MQKBetg==
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=e3YSw8Ew;
	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 16D01606A32C;
	Fri,  6 Nov 2026 01:35:11 +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=e3YSw8Ew
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.80
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793928894;
	b=htX7eYiUQHlPbD4iQ3Ev0UGVoOmfRwwvmIZH3CA0i22qRxHvib3Kk2yUR0E6JMhD4F1Q
	 VDhSVD1hEfOHlorA91BJvtfhEuNYtV0HB7U6KLswkBDmS46WBPYvWGmnQbOfo52GLFdct
	 IUMdaxCP+iDxZ24SM2XLFIh+xcE9/PZUpiG/mbTTCnLu11ptzJTnfnsLRMGLUF07VVg8I
	 z6DInmAq91OWoeZXVV3s9dCyzS84hWoDOMxGyvC4r5MvIBD9R60oMghAgmrFzGuKpJray
	 yQOffuvAgG1krfegWEGMcjtGS9kLN8T+WjX+FY00/KLEwoqr/yRjSFCBOL9KPvwqOZw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793928894;
	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=37zF0J9YNQQfNg00zUsp96qSKKkGdLAWq7jkYoSVkEw=;
	b=d4jSpR2co8DRH6ibYHwl2+Rr0N1s+nOWfiFHmlD4Qc/yOTyzRwJoYdkegvIeY9CqB4ai
	 274i9hpccyfzYDzD9+MrUAW+T76tYgvmHk2uPwckShDILGZISQn2hmKzkcchWNWnZ96TR
	 CDM93F4Sl0iJ8RRjbmMs2RsIcW/x9ZB1Q2MIMUCHF6VaKGp+nlak5hcU5LqQezJyNKs/t
	 WP8mQVsvqQvQokM/3NnPNqM+gZYaUZlni4ZSlqILHEp7lLTRByiE7L6Py1W5eR2u0hV+J
	 YJ04Y6ON+XFqm0vuhhCLokS0r1OdGR9ktV9nw/41uYOl31KM7v+9WoQXuKmTQN9ZSpg==
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=e3YSw8Ew;
	arc=none smtp.remote-ip=95.215.58.80
X-Received: from mta1.migadu.com (out-80.mta1.migadu.com [95.215.58.80])
	(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 1FFC1606A31B
	for <netdev@vger.kernel.org>; Fri,  6 Nov 2026 01:34:51 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1FFC1606A31B
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=YOPsIY4Tuyad8OkdA/iv+lBNUq8frqmfosXKiJVdAj4=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793928890; v=1; x=1794533690;
 b=e3YSw8EwtMVJjgbTlXMguKv8bj5d1A7SL9MNQ4ZICLgvMkJBXAC+F0IS6vbsvXjXMQGhZlLK
 wQNXvKWBwZMYcOI3CIUBUjJIy99LFhumPQFKsZioBIYA5pFYy62jcLHotcEoL9IkMSQOzqucl/c
 ys2p2/Ev/tMtOH6H8/tSkHzk=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta11.migadu.com with ESMTPS id 81f11a3f24812833;
	Fri, 06 Nov 2026 01:34:50 +0000
X-Mizu-Trace-ID: 81f11a3f24812833
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/2XPwW7DIAwG4FepOI8JMCFkpx3W6w7rcaoqIGZFq
 8gUItSqyruXccrGzbb8/ZbvJOEcMJGX3Z3MmEMKUyxN97Qj7mziF9Iwlp4IJhTTrKd2iuMpXUz
 Gk4sL1Rp77TrPjB1IQT8z+nCtgZ8k4vI7+9gf9u9v5FjKc0jLNN/quczrUk0emPifnDnlFBQOn
 fXSKO9fv2+XEKf07GLNymLrofGieCZQ9MCkM6AaD1vffJah+K4fPVhwXjjbeLnxXDZeFj9yqZU
 0MKBif/y6rg8NFsCzfAEAAA==
X-Change-ID: 20260807-bond_slave_cnt-88e78c5f0ab9
X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, 
 linux-kernel@vger.kernel.org, Hangbin Liu <liuhangbin@kylinos.cn>
X-Mailer: b4 0.16.0