Linux bluetooth development
 help / color / mirror / Atom feed
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 1/2] Bluetooth: 6lowpan: publish netdev after registration in setup_netdev()
Date: Mon, 30 Nov 2026 18:28:53 +0800	[thread overview]
Message-ID: <20261130102854.1553-2-luob87709@gmail.com> (raw)
In-Reply-To: <20261130102854.1553-1-luob87709@gmail.com>

setup_netdev() adds (*dev)->list to bt_6lowpan_devices before calling
lowpan_register_netdev(). If lowpan_register_netdev() fails after
NETDEV_REGISTER notifiers have run (for example, -ENOMEM during
addrconf_notify/snmp6_register_dev), register_netdevice() rolls back
and emits NETDEV_UNREGISTER. device_event() then removes (*dev)->list
via list_del_rcu() (poisoning prev with LIST_POISON2), after which
setup_netdev()'s error path calls list_del_rcu(&(*dev)->list) a second
time, causing a general protection fault on 0xdead000000000122.

Publishing the device before registration also exposes an unregistered
net_device on bt_6lowpan_devices to concurrent readers.

Move list_add_rcu(&(*dev)->list, &bt_6lowpan_devices) after
lowpan_register_netdev() succeeds, and simply call free_netdev(netdev)
on registration failure.

Found by static call-chain audit and reproduced under QEMU/KASAN with
hci_vhci.

Fixes: 18722c247023 ("Bluetooth: Enable 6LoWPAN support for BT LE devices")
Cc: stable@vger.kernel.org
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
 net/bluetooth/6lowpan.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 68ca2f4..96cb652 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -701,22 +701,19 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)
 	(*dev)->hdev = chan->conn->hcon->hdev;
 	INIT_LIST_HEAD(&(*dev)->peers);
 
-	spin_lock(&devices_lock);
 	INIT_LIST_HEAD(&(*dev)->list);
-	list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
-	spin_unlock(&devices_lock);
 
 	err = lowpan_register_netdev(netdev, LOWPAN_LLTYPE_BTLE);
 	if (err < 0) {
 		BT_INFO("register_netdev failed %d", err);
-		spin_lock(&devices_lock);
-		list_del_rcu(&(*dev)->list);
-		spin_unlock(&devices_lock);
-		synchronize_rcu();
 		free_netdev(netdev);
 		goto out;
 	}
 
+	spin_lock(&devices_lock);
+	list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
+	spin_unlock(&devices_lock);
+
 	BT_DBG("ifindex %d peer bdaddr %pMR type %d my addr %pMR type %d",
 	       netdev->ifindex, &chan->dst, chan->dst_type,
 	       &chan->src, chan->src_type);
-- 
2.51.0.windows.1


  reply	other threads:[~2026-11-30 10:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:28 [PATCH 0/2] Bluetooth: 6lowpan: fix netdev teardown UAF and registration rollback GPF Bin Luo (University of Electronic Science and Technology of China)
2026-11-30 10:28 ` Bin Luo (University of Electronic Science and Technology of China) [this message]
2026-11-30 10:28 ` [PATCH 2/2] Bluetooth: 6lowpan: unlink closing device and protect RCU lookups Bin Luo (University of Electronic Science and Technology of China)

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=20261130102854.1553-2-luob87709@gmail.com \
    --to=luob87709@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=stable@vger.kernel.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