* [PATCH net] bonding: clear stale usable_slaves in broadcast mode
@ 2026-11-24 13:01 JiangJieHua
2026-11-25 1:26 ` Hangbin Liu
2026-11-25 12:28 ` netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: JiangJieHua @ 2026-11-24 13:01 UTC (permalink / raw)
To: netdev
Cc: Jay Vosburgh, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Hangbin Liu, Changzhong Zhang,
linux-kernel
In broadcast mode, bond_set_slave_arr() frees the usable_slaves argument
and returns early, but does not clear bond->usable_slaves.
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
2026-11-24 13:01 [PATCH net] bonding: clear stale usable_slaves in broadcast mode JiangJieHua
@ 2026-11-25 1:26 ` Hangbin Liu
2026-11-25 7:00 ` jiangjiehua (A)
2026-11-25 12:28 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Hangbin Liu @ 2026-11-25 1:26 UTC (permalink / raw)
To: JiangJieHua
Cc: netdev, Jay Vosburgh, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Hangbin Liu,
Changzhong Zhang, linux-kernel
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
2026-11-25 1:26 ` Hangbin Liu
@ 2026-11-25 7:00 ` jiangjiehua (A)
0 siblings, 0 replies; 4+ messages in thread
From: jiangjiehua (A) @ 2026-11-25 7:00 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, Jay Vosburgh, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Hangbin Liu,
Changzhong Zhang, linux-kernel
Hi Hangbin,
On 11/25/2026 9:26 AM, Hangbin Liu wrote:
> 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?
Clearing bond->usable_slaves in bond_set_slave_arr() does fix the leak,
but it is too late for updelay: bond_enslave() links the new slave via
bond_master_upper_dev_link() before calling bond_update_slave_arr(),
so miimon can already see the slave while the stale empty array is
still there and skip updelay.
Clearing when the mode changes to broadcast happens while the bond is
down with no slaves and mii_work has already been canceled, so the
stale pointer is gone before any new slave is visible. That fixes both
the leak and the updelay issue.
Thanks,
Jiehua
>
> 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
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
2026-11-24 13:01 [PATCH net] bonding: clear stale usable_slaves in broadcast mode JiangJieHua
2026-11-25 1:26 ` Hangbin Liu
@ 2026-11-25 12:28 ` netdev-bot+sashiko
1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 12:28 UTC (permalink / raw)
To: jiangjiehua1
Cc: netdev, j.vosburgh, andrew+netdev, davem, edumazet, kuba, pabeni,
liuhangbin, zhangchangzhong, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch only fixes one target mode.
--
bonding: clear stale usable_slaves in broadcast mode
When the last slave is released in an xmit-hash mode, an empty
usable_slaves array is left published. If the bond is later switched to
broadcast mode, that array survives and makes bond_miimon_inspect()
ignore updelay. It also leaks from bond_uninit(). The patch frees the
array and clears the pointer in bond_option_mode_set() when the new mode
is broadcast.
> diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
> index 9efadeff6a223..f65916444fa1c 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);
> + }
[Severity: High]
Does balance-rr still skip updelay after this change?
The commit message says the cause is that "later mode changes do not
clear it". It also says "Broadcast never publishes usable_slaves, so it
stays NULL". The same is true of BOND_MODE_ROUNDROBIN. Nothing in
balance-rr replaces or clears usable_slaves. bond_mode_can_use_xmit_hash()
covers only 8023AD, XOR, TLB and ALB, so these refreshes all skip
round-robin:
drivers/net/bonding/bond_main.c:bond_open() {
...
if (bond_mode_can_use_xmit_hash(bond))
bond_update_slave_arr(bond, NULL);
...
}
drivers/net/bonding/bond_main.c:bond_enslave() {
...
if (bond_mode_can_use_xmit_hash(bond) ||
BOND_MODE(bond) == BOND_MODE_BROADCAST)
bond_update_slave_arr(bond, NULL);
...
}
The same check gates the refreshes in __bond_release_one() and in the
NETDEV_UP/CHANGE/DOWN handler. The miimon and ARP commit paths refresh
the array only for XOR.
bond_miimon_inspect() handles every mode except active-backup the same
way, so round-robin also reaches this code:
usable_slaves = rcu_dereference(bond->usable_slaves);
if (usable_slaves && usable_slaves->count == 0)
ignore_updelay = true;
Here is the trigger. Release the last slave in balance-xor, 802.3ad,
balance-tlb or balance-alb. __bond_release_one()->bond_update_slave_arr()
then publishes a count-0 array. Switch to balance-rr, bring the bond up
and enslave a slave whose link is up. bond_enslave() puts the slave in
BOND_LINK_BACK with delay = updelay, but bond_miimon_inspect() skips the
delay because ignore_updelay is set.
The reproducer in the commit message, with "mode balance-rr" in place of
"mode broadcast", should still bring dummy0 up at once. The array does
not leak in balance-rr, because bond_uninit()->bond_set_slave_arr() takes
the non-broadcast path and frees it. Only the updelay bypass remains.
The balance-rr case looks like it dates back to f8a65ab2f3ff74.
The mode option requires BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN.
bond_open() rebuilds the array for the modes that use it. Could the
broadcast-only condition be dropped, so that usable_slaves is cleared on
every mode change?
> /* 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
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124130102.18807-1-jiangjiehua1%40huawei.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 12:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:01 [PATCH net] bonding: clear stale usable_slaves in broadcast mode JiangJieHua
2026-11-25 1:26 ` Hangbin Liu
2026-11-25 7:00 ` jiangjiehua (A)
2026-11-25 12:28 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®