[PATCH 1/2] Bluetooth: 6lowpan: publish netdev after registration in setup_netdev()

From: Bin Luo (University of Electronic Science and Technology of China)

Date: Mon Nov 30 2026 - 05:29:12 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@xxxxxxxxx>
---
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