mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cen Zhang <zzzccc427@gmail.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, jjzuming@gmail.com, zzzccc427@gmail.com
Subject: [PATCH 1/2] Bluetooth: 6lowpan: Hold RTNL across adapter lookup and use
Date: Sat, 21 Nov 2026 15:11:09 +0800	[thread overview]
Message-ID: <pm-bluetooth-objects-candidate-0228-v10-f6ced931e2322aa5c7b3-1@gmail.com> (raw)
In-Reply-To: <pm-bluetooth-objects-candidate-0228-v10-f6ced931e2322aa5c7b3-0@gmail.com>

lookup_dev() returns a borrowed adapter after dropping RCU. The last
peer's asynchronous deletion can unregister and free its netdevice while
a later ready callback uses that pointer:

  Ready callback                    Deletion worker
  lookup_dev()
  leave RCU
                                    lock RTNL
                                    unregister the netdevice
                                    remove the adapter from the list
  ifup(): wait for RTNL
                                    unlock RTNL and release storage
  open the stale netdevice

Take RTNL before lookup and retain it through peer publication and
device open. Use lowpan_register_netdevice() because registration now
runs with RTNL held, and remove the nested lock from ifup(). Deletion
cannot revoke the adapter between its lookup and last ready-callback use.

The excerpt below retains the headline and stack traces.

KASAN report as below:

    Oops: Oops: 0000 [#1] SMP KASAN NOPTI

    Workqueue: hci1 hci_rx_work
    RIP: 0010:dev_addr_check+0x4e/0x260

    Call Trace:
     <TASK>
     __dev_open+0xa8/0x6d0
     ? __pfx___dev_open+0x10/0x10
     netif_open+0xde/0x140
     ? __pfx_netif_open+0x10/0x10
     dev_open+0xb9/0x180
     chan_ready_cb+0x420/0xf90
     ? __pfx_chan_ready_cb+0x10/0x10
     ? lockdep_init_map_type+0x5c/0x230
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? l2cap_chan_put+0x48/0x3a0
     l2cap_le_connect_req+0xccd/0x11a0
     ? __pfx_l2cap_le_connect_req+0x10/0x10
     l2cap_recv_frame+0x467f/0x8830
     ? kfree_skbmem+0x15e/0x1d0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __mutex_lock+0x182c/0x2590
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_l2cap_recv_frame+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? find_held_lock+0x2b/0x80
     ? l2cap_recv_acldata+0x1eb/0x10e0
     ? __pfx___mutex_lock+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __mutex_unlock_slowpath+0x147/0x920
     ? __pfx_l2cap_conn_hold_unless_zero+0x10/0x10
     ? __pfx_hci_conn_enter_active_mode+0x10/0x10
     ? l2cap_recv_acldata+0x13d/0x10e0
     ? srso_alias_return_thunk+0x5/0xfbef5
     l2cap_recv_acldata+0xe9f/0x10e0
     ? srso_alias_return_thunk+0x5/0xfbef5
     hci_rx_work+0x5a6/0xf00
     ? srso_alias_return_thunk+0x5/0xfbef5
     process_one_work+0x908/0x19c0
     ? __pfx_process_one_work+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_is_held_type+0x8f/0x100
     ? srso_alias_return_thunk+0x5/0xfbef5
     worker_thread+0x65c/0xe40
     ? __pfx_worker_thread+0x10/0x10
     kthread+0x34f/0x460
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_kthread+0x10/0x10
     ret_from_fork+0x659/0x940
     ? __pfx_ret_from_fork+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __switch_to+0x74f/0xf80
     ? __pfx_kthread+0x10/0x10
     ret_from_fork_asm+0x1a/0x30
     </TASK>

    RIP: 0010:dev_addr_check+0x4e/0x260

Fixes: 18722c247023 ("Bluetooth: Enable 6LoWPAN support for BT LE devices")
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
This patch was written with assistance from Codex (OpenAI).

 net/bluetooth/6lowpan.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 68ca2f49dadc9..f01eb68cbf5a9 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -597,11 +597,11 @@ static void ifup(struct net_device *netdev)
 {
 	int err;
 
-	rtnl_lock();
+	ASSERT_RTNL();
+
 	err = dev_open(netdev, NULL);
 	if (err < 0)
 		BT_INFO("iface %s cannot be opened (%d)", netdev->name, err);
-	rtnl_unlock();
 }
 
 static void ifdown(struct net_device *netdev)
@@ -706,7 +706,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)
 	list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
 	spin_unlock(&devices_lock);
 
-	err = lowpan_register_netdev(netdev, LOWPAN_LLTYPE_BTLE);
+	err = lowpan_register_netdevice(netdev, LOWPAN_LLTYPE_BTLE);
 	if (err < 0) {
 		BT_INFO("register_netdev failed %d", err);
 		spin_lock(&devices_lock);
@@ -735,12 +735,16 @@ static inline void chan_ready_cb(struct l2cap_chan *chan)
 	struct lowpan_btle_dev *dev;
 	bool new_netdev = false;
 
+	/* Protect the device lookup and use against unregister. */
+	rtnl_lock();
+
 	dev = lookup_dev(chan->conn);
 
 	BT_DBG("chan %p conn %p dev %p", chan, chan->conn, dev);
 
 	if (!dev) {
 		if (setup_netdev(chan, &dev) < 0) {
+			rtnl_unlock();
 			l2cap_chan_del(chan, -ENOENT);
 			return;
 		}
@@ -748,10 +752,13 @@ static inline void chan_ready_cb(struct l2cap_chan *chan)
 	}
 
 	if (!try_module_get(THIS_MODULE))
-		return;
+		goto out;
 
 	add_peer_chan(chan, dev, new_netdev);
 	ifup(dev->netdev);
+
+out:
+	rtnl_unlock();
 }
 
 static void unregister_dev(struct lowpan_btle_dev *dev)
@@ -763,7 +770,7 @@ static void unregister_dev(struct lowpan_btle_dev *dev)
 	 *
 	 * rtnl_lock -> put_device(parent) -> hci_release_dev ->
 	 * destroy_workqueue -> hci_rx_work -> l2cap_recv_acldata ->
-	 * chan_ready_cb -> ifup -> rtnl_lock
+	 * chan_ready_cb -> rtnl_lock
 	 *
 	 * However, hci_rx_work is disabled in hci_unregister_dev, so this
 	 * should not occur. Make lockdep happy by postponing hdev release after

  reply	other threads:[~2026-11-21  7:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  7:11 [PATCH 0/2] Bluetooth: 6lowpan: Protect adapter use and notification lifetime Cen Zhang
2026-11-21  7:11 ` Cen Zhang [this message]
2026-11-21  7:11 ` [PATCH 2/2] Bluetooth: 6lowpan: Disable notify_peers before netdev deletion Cen Zhang

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=pm-bluetooth-objects-candidate-0228-v10-f6ced931e2322aa5c7b3-1@gmail.com \
    --to=zzzccc427@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=jjzuming@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /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

all inboxes | Powered by JetHome®