[PATCH 2/2] Bluetooth: 6lowpan: Disable notify_peers before netdev deletion

From: Cen Zhang

Date: Sat Nov 21 2026 - 02:11:31 EST


The last-peer close path cancels notify_peers and queues adapter
deletion. Before deletion removes the adapter from the list, another
ready callback can find it and queue the embedded delayed work again:

Last-peer close Later ready / deletion work
cancel notify_peers
queue delete_netdev
add_peer_chan()
requeue notify_peers
unregister and free the adapter
notification timer uses freed work

Disable the delayed work synchronously instead of only cancelling it.
This both drains an existing callback and rejects later queue attempts
for the adapter which is already being deleted.

The excerpt below retains the headline and stack traces.

Use disable_delayed_work_sync() before teardown, as commit
d236517c264e4 ("Bluetooth: coredump: Quiesce dump work on unregister")
does before freeing the Bluetooth coredump state.

KASAN report as below:

BUG: KASAN: slab-use-after-free in do_notify_peers+0x63/0x70
Read of size 8 at addr ffff888117711030 by task kworker/3:1/50

Workqueue: events do_notify_peers
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? do_notify_peers+0x63/0x70
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? do_notify_peers+0x63/0x70
kasan_report+0xe0/0x110
? do_notify_peers+0x63/0x70
do_notify_peers+0x63/0x70
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x175/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __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>

Allocated by task 500:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kvmalloc_node_noprof+0x353/0x930
alloc_netdev_mqs+0xa0/0x1250
chan_ready_cb+0x4ec/0xeb0
l2cap_le_connect_req+0xccd/0x11a0
l2cap_recv_frame+0x467f/0x8830
l2cap_recv_acldata+0xe9f/0x10e0
hci_rx_work+0x5a6/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30

Freed by task 11:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
device_release+0xd7/0x280
kobject_put+0x1ad/0x610
netdev_run_todo+0x91c/0x13a0
unregister_dev+0x82/0x280
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30

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

net/bluetooth/6lowpan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index f01eb68cbf5a9..f3f4e4b2c5f46 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -824,7 +824,8 @@ static void chan_close_cb(struct l2cap_chan *chan)
if (!err && last && dev && !atomic_read(&dev->peer_count)) {
spin_unlock(&devices_lock);

- cancel_delayed_work_sync(&dev->notify_peers);
+ /* Prevent a later ready callback from requeueing work. */
+ disable_delayed_work_sync(&dev->notify_peers);

ifdown(dev->netdev);