Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Hangbin Liu
Wed, 25 Nov 2026 01:26
Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
Author: Hangbin Liu
Date: Wed, 25 Nov 2026 01:26
Date: Wed, 25 Nov 2026 01:26
73 lines
11353 bytes
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
>
Re: [PATCH net] bonding: clear stale usable_slaves in broadcast mode
Author: Hangbin Liu
Date: Wed, 25 Nov 2026 15:21
Date: Wed, 25 Nov 2026 15:21
98 lines
12636 bytes
12636 bytes
On Wed, Nov 25, 2026 at 03:00:37PM +0800, jiangjiehua (A) wrote:
>
> 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.
After a second look, I found we should ignore the updelay based on
bonding doc section 13.1 paragraph 4.
I will revert 45fc134bcfad and prepare another fix.
Thanks
Hangbin
>
> >
> > 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
> > >
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads