[PATCH net-next 3/6] bonding: complete rollback of bond_enslave() error paths

From: Hangbin Liu

Date: Fri Nov 13 2026 - 09:36:06 EST


From: Hangbin Liu <liuhangbin@xxxxxxxxxx>

The bond_enslave() undo labels are missing three cleanups that the
release path (__bond_release_one) already performs:

- If bond_alb_init_slave() succeeds but a later step fails, the
slave is never passed to bond_alb_deinit_slave(), leaving TLB/RLB
state and a possibly borrowed MAC address behind.

- If the slave is bound into 802.3ad (bond_3ad_bind_slave()) and a
later step fails, bond_3ad_unbind_slave() is never called, so the
port stays attached to its aggregator.

- When fail_over_mac is automatically set to "active" because the
first slave cannot change its MAC address, a subsequent failure
leaves the modified parameter on the bond.

Add undo steps for these 3 cleanups when error out.

Signed-off-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
---
drivers/net/bonding/bond_main.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 80b6c18ee9c2..f696a0d15034 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1890,7 +1890,9 @@ 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;
+ bool alb_initialized = false;
struct sockaddr_storage ss;
int res = 0, i;

@@ -2120,6 +2122,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
res = bond_alb_init_slave(bond, new_slave);
if (res)
goto err_close;
+ alb_initialized = true;
}

res = vlan_vids_add_by_dev(slave_dev, bond_dev);
@@ -2388,6 +2391,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
netdev_rx_handler_unregister(slave_dev);

err_detach:
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
+ bond_3ad_unbind_slave(new_slave);
vlan_vids_del_by_dev(slave_dev, bond_dev);
if (rcu_access_pointer(bond->primary_slave) == new_slave)
RCU_INIT_POINTER(bond->primary_slave, NULL);
@@ -2402,6 +2407,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
slave_disable_netpoll(new_slave);

err_close:
+ if (alb_initialized)
+ bond_alb_deinit_slave(bond, new_slave);
if (!netif_is_bond_master(slave_dev))
slave_dev->priv_flags &= ~IFF_BONDING;
dev_close(slave_dev);
@@ -2427,6 +2434,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
kobject_put(&new_slave->kobj);

err_undo_flags:
+ /* Restore fail_over_mac in case the automatic "active" setting
+ * above was applied and a later step failed.
+ */
+ 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,

--
2.56.0