Netdev List
 help / color / mirror / Atom feed
* [PATCH net] bonding: fix use-after-free in slave_kobj_release()
@ 2026-11-20 13:08 Baoli Zhang
  0 siblings, 0 replies; only message in thread
From: Baoli Zhang @ 2026-11-20 13:08 UTC (permalink / raw)
  To: jv, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: jamie.iles, netdev, linux-kernel, Baoli Zhang

slave_kobj_release() dereferences slave->bond to check for 802.3ad mode
before freeing ad_info. The slave kobject's parent is the slave device,
not the bond, so the bond may already be gone when the release runs.

Normally the last reference is put while the bond is still alive, but
with CONFIG_DEBUG_KOBJECT_RELEASE the release is deferred and the bond
can be freed first:

  BUG: KASAN: slab-use-after-free in slave_kobj_release+0xe8/0x100 [bonding]
  Read of size 4 at addr ffff888112c99118 by task kworker/9:1/60681
  Workqueue: events kobject_delayed_cleanup
  ...
  Freed by task 60681:
   kvfree+0x31/0x40
   netdev_release+0x8b/0xc0
   device_release+0xdf/0x2a0
   kobject_delayed_cleanup+0x148/0x520

ad_info is only allocated in 802.3ad mode and is NULL otherwise, since
the slave is allocated with kzalloc(), and the mode cannot be changed
while the bond has slaves. Drop the mode check and free ad_info
unconditionally.

Fixes: b9ad3e9f5a7a ("bonding: wait for sysfs kobject destruction before freeing struct slave")
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
 drivers/net/bonding/bond_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index a1c156c145b2d..0ec5bc838b86e 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1732,11 +1732,10 @@ static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
 static void slave_kobj_release(struct kobject *kobj)
 {
 	struct slave *slave = to_slave(kobj);
-	struct bonding *bond = bond_get_bond_by_slave(slave);
 
 	cancel_delayed_work_sync(&slave->notify_work);
-	if (BOND_MODE(bond) == BOND_MODE_8023AD)
-		kfree(SLAVE_AD_INFO(slave));
+	/* ad_info is only allocated in 802.3ad mode, NULL otherwise */
+	kfree(SLAVE_AD_INFO(slave));
 
 	kfree(slave);
 }

base-commit: bc4c8c146447f71534e80db39c2d1149c6af5fd6
-- 
2.43.0


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

only message in thread, other threads:[~2026-11-20 13:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 13:08 [PATCH net] bonding: fix use-after-free in slave_kobj_release() Baoli Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox