🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22222

Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode

#22222
From: Hangbin Liu
Date: Wed, 25 Nov 2026 01:26
73 lines
11353 bytes
Hi Jiehua,
On Tue, Nov 24, 2026 at 09:01:02PM +0800, JiangJieHua wrote:
> In broadcast mode, bond_set_slave_arr() frees the usable_slaves argument
> and returns early, but does not clear bond->usable_slaves.

Since the issue was introduced in bond_set_slave_arr(). Should we set
the bond->usable_slaves to NULL here before return?

Thanks
Hangbin
> 
> A mode change requires the bond to be down with no slaves.  When the
> last slave is removed in balance-xor, balance-tlb or balance-alb,
> bond_update_slave_arr() publishes an empty usable array, and later mode
> changes do not clear it.  If the bond is switched to broadcast, the
> stale pointer remains: bond_miimon_inspect() sees count == 0 and
> ignores updelay for slaves enslaved while the stale array remains, and
> bond_uninit() leaks the array.
> 
> Clear bond->usable_slaves when the mode is changed to broadcast.  The
> bond is down and has no slaves at that point, so the array can be freed
> and set to NULL before the bond is brought up again.  Broadcast never
> publishes usable_slaves, so it stays NULL.
> 
> The issue was discovered by an AI code review agent and confirmed by
> manual code inspection.  It was reproduced on mainline with virtme-ng;
> no kernel modifications or error injection were needed.  With a dummy
> slave and miimon=1:
> 
>   ip link add bond0 type bond mode balance-xor miimon 1 updelay 1000
>   ip link add dummy0 type dummy
>   ip link set bond0 up
>   ip link set dummy0 master bond0
>   ip link set dummy0 nomaster
>   ip link set bond0 down
>   ip link set bond0 type bond mode broadcast
>   ip link set bond0 up
>   ip link set dummy0 master bond0
> 
> After the final enslavement, dummy0 comes up within 50 ms despite
> updelay=1000 (20 of 20 runs on the unpatched kernel).  With the fix,
> none of 300 runs skipped updelay.  The bonding mode-2 recovery-updelay
> selftest passes on the same kernel.
> 
> Fixes: 45fc134bcfad ("bonding: do not set usable_slaves for broadcast mode")
> Signed-off-by: JiangJieHua <jiangjiehua1@huawei.com>
> ---
>  drivers/net/bonding/bond_options.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
> index 9efadeff6a22..f65916444fa1 100644
> --- a/drivers/net/bonding/bond_options.c
> +++ b/drivers/net/bonding/bond_options.c
> @@ -936,6 +936,14 @@ static int bond_option_mode_set(struct bonding *bond,
>  	WRITE_ONCE(bond->params.arp_validate, BOND_ARP_VALIDATE_NONE);
>  	WRITE_ONCE(bond->params.mode, newval->value);
>  
> +	if (newval->value == BOND_MODE_BROADCAST) {
> +		struct bond_up_slave *usable;
> +
> +		usable = rtnl_dereference(bond->usable_slaves);
> +		RCU_INIT_POINTER(bond->usable_slaves, NULL);
> +		kfree_rcu(usable, rcu);
> +	}
> +
>  	/* When changing mode, the bond device is down, we may reduce
>  	 * the bond_bcast_neigh_enabled in bond_close() if broadcast_neighbor
>  	 * enabled in 8023ad mode. Therefore, only clear broadcast_neighbor
> -- 
> 2.33.8
> 
Technical Details
Message-ID: <20261125012632.GB19338@Liu-laptop>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370940-linux-kernel-netdev=dewy.ru
References: <20261124130102.18807-1-jiangjiehua1@huawei.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370940-linux-kernel-netdev=dewy.ru
From: hangbin.liu@linux.dev (Hangbin Liu)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
Date: Wed, 25 Nov 2026 09:26:32 +0800
Organization: Usenet Network
Message-ID: <20261125012632.GB19338@Liu-laptop>
References: <20261124130102.18807-1-jiangjiehua1@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="81624"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:cQgX5ih2v8voMyNSYopp1cIfSFw= sha256:AJ98lotOLaDLUntVTSzEUUereZixhTs5r5F60FSkGmw=
	sha1:UADyAsNoTuzMCtJPIOrnJFEzAXI= sha256:k+IMwf0z93sV6nwT3egraN7cbffu3QT7NarWaOWPnwc=
Content-Disposition: inline
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 C7709125E38; Wed, 25 Nov 2026 04:27:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[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,
	URIBL_BLOCKED=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 kXvEBga-uevV;
	Wed, 25 Nov 2026 04:26:57 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-370940-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id E8314125E2F; Wed, 25 Nov 2026 04:26:47 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 38B4160478E; Wed, 25 Nov 2026 01:26:47 +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=1795570003;
	b=gdOuCW0yKoHBmi2sfHxjC9zLtuexD8PNJo6w1jenTyGSlUkdsKAzoVJYLoa4yNbhpvOo
	 4R7HCrdcInPXjqWrE//mVgZ5e3t32s2t0OOuWVIQQLNuVmMFiaCYKlQje+I7eqffoaDkM
	 F4AafkdsVrURmeb9mW7mWUVyCwCdtbXHtKXxt1dOOGOThhB+hm6ZMlOdGf9UyyVpqarBo
	 y52aYhXwmvyqQm04W1Q17oSwH4qpSrmjPKkxBV7fEuzOSfli5nt/EovxyRdkU9il55H9P
	 SF3K//3ZeEszTzJAu55ipL2fSoqVSvDajnoN0yaeOdqWP6nl28LF4KHkB6NZnSAnSkw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795570003;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=GYnMm6oY2CoBK3VQDfahz7r3axfDYTK/q7aun/2ckiM=;
	b=UI5aRX/iUR+a1BdHA/S91v7zeUpcFY1CZx11z+F9U47AER8XT+zTBuMf3JtZ65caqCHi
	 +esoCBweO+0xX99TAGDzErgdWWIceFj2I/af/FpL8l09cNPVD6TBBrSj40Y96w3t6CSyk
	 aXRBq3JBHtpQTHy9UFaqHDvLaTVfCKILD4Tj7S/NyMj9HOByg4hpx/Jt5ctpjQ47iTVCg
	 ZOVOrf4+GF1scMHm4b3KsXwmY+ty1N4h80KOGqAre7sMNJ9/spCcJw26VzM2cNZ4x6WhM
	 E7U2vWTVLZV2AScmQTlURU3kOjzflF8TPEuQXcesaEFN3X9omBbEE00mgkADGQe+Xhw==
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=Ch4jCDMM;
	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 B6955606A338;
	Wed, 25 Nov 2026 01:26:43 +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=Ch4jCDMM
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795570002;
	b=07PL+5HDMc19HfQrLu+WhhpRiwmJAC0/bkPgS7YqJJflSEQPgw0O38rr4rKugb57Z9JA
	 yYOdz2EQeUJDecxX335KYd3dKg5hcErVwMKVVA0rYU/2FAsvzF5w+yw6ikn1LIus6vvep
	 BnLlSx98iJxj6XNSMaP9krfMhq6rtu2BxIXNbqc49PaAft3LUzTY8WhVZK4W8j4fke1gz
	 9CCMssC9n5w/Qvmuq9ZecWe/IbCNNbSJ8b1SmOgtWjnfCWrSoExuI3j6i5jGMOWHc/04I
	 ELWY04oGbeg+mGd65SZW9BSHNsprwdhyrG5q/XOwlW0+IgT9PuYLZi0METHTY0U/mKA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795570002;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=GYnMm6oY2CoBK3VQDfahz7r3axfDYTK/q7aun/2ckiM=;
	b=T1lxrNuyvGHqbnfP7tGN5lPZ/3gbHZmnMU+ERS2aWWRg9FYMvaj6uxwaDl3T4mCNG74a
	 tiA3ELsrngwWwSCsI+4HzwLADSdaGaGHgENSvHEGy04L7ogEoD7rnRooL/ey3hgiBB/Le
	 OEj7M/0V6UPEpULCSY8/PewkimN/M0zeqU6j6nw82BVGwHiRuzTkKyaWz/aJ+MkeOyOEW
	 R8tpnKhzo2mt8DuE+TR4JXCWIq+epUu/0hkOkElmAkBaBCGJP5/zeRsLm0ai11n735t+e
	 lw+TLfxR9VWDeBvEAKdGrgL/Usc39fDW/b4zPHDeDsLgwDSbNQHm6C0iFAzDkVrgQhg==
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=Ch4jCDMM;
	arc=none smtp.remote-ip=95.215.58.50
X-Received: from mta1.migadu.com (out-50.mta1.migadu.com [95.215.58.50])
	(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 48C4E606A321
	for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 01:26:41 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48C4E606A321
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=xAfnthVrgNB8tpYjNLuTpMrchkhx5LSnJ0Zyzi4R/fc=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795569999; v=1; x=1796174799;
 b=Ch4jCDMMhT5G5wa2/hi6TzX8vIDzKiE/hQlgCuPRhO0dkr1805Zy3nLvvh3DLe4Tg5JnmvTH
 WS6N/H/utZKgKaBDoNmmpufjYgYUeKyXs0zfqZ+7jVmR+d4ypKCcZm3VYokTwzDWD+fDlTTQOwR
 Zb6fanCO0HPWlrOGt6UGAyFc=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta10.migadu.com with ESMTPS id 7beb4e14288bbdcb;
	Wed, 25 Nov 2026 01:26:39 +0000
X-Mizu-Trace-ID: 7beb4e14288bbdcb
X-Migadu-Flow: FLOW_OUT
X-Cc: netdev@vger.kernel.org, Jay Vosburgh <j.vosburgh@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Hangbin Liu <liuhangbin@kylinos.cn>,
	Changzhong Zhang <zhangchangzhong@huawei.com>,
	linux-kernel@vger.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
X-In-Reply-To: <20261124130102.18807-1-jiangjiehua1@huawei.com>