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 2/2] Bluetooth: 6lowpan: Disable notify_peers before netdev deletion
Date: Sat, 21 Nov 2026 15:11:10 +0800 [thread overview]
Message-ID: <pm-bluetooth-objects-candidate-0228-v10-f6ced931e2322aa5c7b3-2@gmail.com> (raw)
In-Reply-To: <pm-bluetooth-objects-candidate-0228-v10-f6ced931e2322aa5c7b3-0@gmail.com>
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@gmail.com>
---
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);
prev parent 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 ` [PATCH 1/2] Bluetooth: 6lowpan: Hold RTNL across adapter lookup and use Cen Zhang
2026-11-21 7:11 ` Cen Zhang [this message]
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-2@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®