mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2] bonding: unbind 802.3ad slaves on enslave failure
@ 2026-11-24  2:41 Lin Jiapeng
  0 siblings, 0 replies; only message in thread
From: Lin Jiapeng @ 2026-11-24  2:41 UTC (permalink / raw)
  To: jv, andrew+netdev, davem, edumazet, kuba, pabeni, sfeldma,
	netdev, linux-kernel
  Cc: Lin Jiapeng, TencentOS Corvus AI

From: Lin Jiapeng <jiapenglin@tencent.com>

The 802.3ad enslave path binds a slave before publishing it in the bond's
slave list. The periodic state machine can select the port and attach it to
a LAG while enslavement is in progress, including while NETDEV_CHANGEUPPER
notifiers are running.

If enslavement fails, rollback can free ad_slave_info without unbinding its
port and leave later LAG processing with a dangling pointer. This affects
both a failed upper-link notification and later failures such as
bond_sysfs_slave_add(). A test-only kretprobe forces the latter to return
-ENOMEM, after which KASAN reports:
     BUG: KASAN: slab-use-after-free in ad_agg_selection_logic+0x1a0d/0x1fa0
     Read of size 1 by task kworker/u16:0/13
     Freed by task 110:
       kfree
       slave_kobj_release
       kobject_put
       bond_enslave

Drain the RX handler before unbinding so receive handlers cannot race with
port->slave becoming NULL. Unbind before upper unlink when the link exists,
and also unbind after an upper-link failure without repeating the unlink.
Rebuild the slave array after aggregator changes and leave earlier
unpublished failures unchanged.

Fixes: 07699f9a7c8d ("bonding: add sysfs /slave dir for bond slave devices.")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Link: https://lore.kernel.org/netdev/20261113130454.63032-1-ljp1205831794@gmail.com/
---
v1 -> v2:
  - Drain the RX handler before unbinding to avoid NULL dereferences in the
    802.3ad receive path.
  - Cover NETDEV_CHANGEUPPER failure after transient upper-link publication,
    without repeating upper-dev unlink.
  - Rebuild the 802.3ad slave array after rollback.

 drivers/net/bonding/bond_main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index e9f5e753f677..7ca948bb27d0 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2355,10 +2355,21 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 	bond_sysfs_slave_del(new_slave);
 
 err_upper_unlink:
+	netdev_rx_handler_unregister(slave_dev);
+	if (BOND_MODE(bond) == BOND_MODE_8023AD)
+		bond_3ad_unbind_slave(new_slave);
 	bond_upper_dev_unlink(bond, new_slave);
+	goto err_update_slave_arr;
 
 err_unregister:
 	netdev_rx_handler_unregister(slave_dev);
+	if (BOND_MODE(bond) == BOND_MODE_8023AD)
+		bond_3ad_unbind_slave(new_slave);
+
+err_update_slave_arr:
+	if (BOND_MODE(bond) == BOND_MODE_8023AD &&
+	    bond_update_slave_arr(bond, new_slave))
+		bond_slave_arr_work_rearm(bond, 0);
 
 err_detach:
 	vlan_vids_del_by_dev(slave_dev, bond_dev);

base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
-- 
2.55.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-24  2:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  2:41 [PATCH net v2] bonding: unbind 802.3ad slaves on enslave failure Lin Jiapeng

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®