Hi Willem,
On Wed, Dec 02, 2026 at 09:02:01PM -0500, will…@google.com wrote:
> Hangbin Liu wrote:
> > From: Hangbin Liu <liuh…@kylinos.cn>
>
> > bond_enslave() can change bond->params.fail_over_mac as a side
> > effect: when the first slave cannot set its own MAC address and the
> > bond is in active-backup mode, fail_over_mac is forced to "active" so
> > bonding never writes the slave MAC. If enslave fails later, the
> > forced value stays behind, silently changing a user-configured
> > option after a failed operation and affecting subsequent failover
> > behaviour.
>
> > Snapshot fail_over_mac on entry and restore it on the error path.
>
> > Signed-off-by: Hangbin Liu <liuh…@kylinos.cn>
>
> When respinning, please fold the discovery context and the WireGuard +
> XDP
> reproducer from your reply to Paolo into the commit message (per sinfo),
> and consider adding:
>
> Fixes: 3915c1e8634a ("bonding: Add "follow" option to fail_over_mac")
>
> Also if targeting net-next.
Sometimes I'm a little confused whether the small/corner fix should be target
to net or next. Usually we post all fix to net. But last time I was told
to post none critical, small fix to net-next.
>
> > ---
> > drivers/net/bonding/bond_main.c | 2 ++
> > 1 file changed, 2 insertions(+)
>
> > diff --git a/drivers/net/bonding/bond_main.c
> > b/drivers/net/bonding/bond_main.c
> > index 9249a79a168e..3817c82e89e2 100644
> > --- a/drivers/net/bonding/bond_main.c
> > +++ b/drivers/net/bonding/bond_main.c
> > @@ -1890,6 +1890,7 @@ int bond_enslave(struct net_device *bond_dev,
> > struct net_device *slave_dev,
> > {
> > struct bonding *bond = netdev_priv(bond_dev);
> > const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
> > + int orig_fail_over_mac = bond->params.fail_over_mac;
> > struct slave *new_slave = NULL, *prev_slave;
> > struct sockaddr_storage ss;
> > int res = 0, i;
> > @@ -2412,6 +2413,7 @@ int bond_enslave(struct net_device *bond_dev,
> > struct net_device *slave_dev,
> > kobject_put(&new_slave->kobj);
>
> > err_undo_flags:
> > + bond->params.fail_over_mac = orig_fail_over_mac;
>
> Since commits 4dc5a40b3bc9 ("bonding: annotate data-races in sysfs and
> procfs") and 317cefdcaacc ("bonding: no longer rely on RTNL in
> bond_fill_info()"), bond->params.fail_over_mac is read without RTNL via
> READ_ONCE() in bonding_show_fail_over_mac() (bond_sysfs.c:268),
> bond_info_show_master() (bond_procfs.c:71), and bond_fill_info()
> (bond_netlink.c:804), paired with WRITE_ONCE() in
> bond_option_fail_over_mac_set() (bond_options.c:1587).
>
> Doing an unannotated plain store here — unconditionally on every failed
> bond_enslave(), even when fail_over_mac did not change — introduces a
> KCSAN data race against those lockless readers. Guard the restore and
> use WRITE_ONCE():
>
> if (bond->params.fail_over_mac != orig_fail_over_mac)
> WRITE_ONCE(bond->params.fail_over_mac, orig_fail_over_mac);
>
> (The pre-existing `bond->params.fail_over_mac = BOND_FOM_ACTIVE;` store
> earlier in bond_enslave() at line 2018 is also missing WRITE_ONCE() and
> is worth annotating in the same patch.)
Thanks, I will update with this change.
---
pw-bot: cr