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.
Annotate the stores with WRITE_ONCE() for lockless readers.
Also add the missing WRITE_ONCE() for the existing fail_over_mac
assignment in bond_enslave.
Fixes: 3915c1e8634a ("bonding: Add "follow" option to fail_over_mac")
Signed-off-by: Hangbin Liu <liuh…@kylinos.cn>
---
The issue is discovered when I tried to restruct bond_enslave().
It could be reproduced via
bash-5.3# ip link add wg0 type wireguard
bash-5.3# ip link add bond0 type bond mode active-backup
bash-5.3# ip link set bond0 xdpdrv obj xdp_dummy.bpf.o sec xdp
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "none",
bash-5.3# ip link set wg0 master bond0
Error: Slave does not support XDP.
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "active",
After the patch, the fail_over_mac will not be changed by a failed enslave.
bash-5.3# ip -d -j -p link show bond0 | grep fail_over_mac
"fail_over_mac": "none",
---
Changes in v2:
- Annotate the stores with WRITE_ONCE() for lockless readers. (Willem de Bruijn)
- Link to v1: https://patch.msgid.link/2026…@kylinos.cn
---
drivers/net/bonding/bond_main.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 754048ef4835..a1ee406a7d46 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1894,6 +1894,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;
@@ -2014,7 +2015,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
if (!bond_has_slaves(bond)) {
- bond->params.fail_over_mac = BOND_FOM_ACTIVE;
+ WRITE_ONCE(bond->params.fail_over_mac, BOND_FOM_ACTIVE);
slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n");
} else {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
@@ -2420,6 +2421,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
kobject_put(&new_slave->kobj);
err_undo_flags:
+ if (bond->params.fail_over_mac != orig_fail_over_mac)
+ WRITE_ONCE(bond->params.fail_over_mac, orig_fail_over_mac);
/* Enslave of first slave has failed and we need to fix master's mac */
if (!bond_has_slaves(bond)) {
if (ether_addr_equal_64bits(bond_dev->dev_addr,
---
base-commit: c63b67b946fcd4efb24439f70ee081dfa485dc40
change-id: 20261124-bond_fail_over_mac-e7952797e80b
Best regards,
--
Hangbin Liu <liuh…@kylinos.cn>
[PATCH net-next v2] bonding: roll back fail_over_mac if enslave fails
- From
- hang…@linux.dev (Hangbin Liu)
- Organization
- Usenet Network
- Message-ID
- <2026…@kylinos.cn>
- Date
- Newsgroups
- linux.kernel.netdev