Netdev List
 help / color / mirror / Atom feed
From: Baoli Zhang <baoli.zhang@linux.intel.com>
To: jv@jvosburgh.net, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
Cc: jamie.iles@oss.qualcomm.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Baoli Zhang <baoli.zhang@linux.intel.com>
Subject: [PATCH net] bonding: fix use-after-free in slave_kobj_release()
Date: Fri, 20 Nov 2026 21:08:14 +0800	[thread overview]
Message-ID: <20261120130814.2131659-1-baoli.zhang@linux.intel.com> (raw)

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


                 reply	other threads:[~2026-11-20 13:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120130814.2131659-1-baoli.zhang@linux.intel.com \
    --to=baoli.zhang@linux.intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jamie.iles@oss.qualcomm.com \
    --cc=jv@jvosburgh.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox