| 0/0 |
2026/06/01 14:15 |
flow |
assessment-security |
50m
Results: map[DenialOfService:true Explanation:**Bug Analysis:**
The bug is a Use-After-Free (UAF) in the Bluetooth USB driver (`btusb`).
1. **Root Cause:**
The `btusb_data` structure is allocated in `btusb_probe()` and freed in
`btusb_disconnect()`. The driver uses a delayed work item, `rx_work`, to process
incoming Bluetooth packets.
When the USB device is disconnected or the driver is unbound,
`btusb_disconnect()` is invoked. This function calls `hci_unregister_dev()`,
which eventually calls the driver's `btusb_close()` callback.
Inside `btusb_close()`, the driver attempts to cancel the delayed work using
`cancel_delayed_work(&data->rx_work)`. However, `cancel_delayed_work()` only
cancels the timer; if the work item is already executing on a CPU, it does not
wait for it to finish (unlike `cancel_delayed_work_sync()`).
After `btusb_close()` returns, `btusb_disconnect()` proceeds to free the
`btusb_data` structure via `kfree(data)`. If `btusb_rx_work()` is still running
concurrently, it will access the freed `data` object (e.g., `data->acl_q`),
resulting in a Use-After-Free.
2. **Exploitability:**
This bug is highly **Exploitable**. The freed `btusb_data` object is allocated
in the `kmalloc-4k` slab cache. It contains several function pointers (such as
`data->recv_acl`, `data->recv_event`, etc.) and spinlocks. An attacker can
exploit this by spraying the heap with controlled data immediately after the
object is freed. If the attacker successfully overwrites the `recv_acl` function
pointer, they can achieve arbitrary kernel code execution when the still-running
`btusb_rx_work()` executes `data->recv_acl(data->hdev, skb)`.
3. **Trigger Mechanism:**
To trigger this bug, an attacker needs to schedule the `rx_work` (e.g., by
sending Bluetooth events/ACL data from the device) and then abruptly disconnect
the device while the work is executing.
- **Peripheral Trigger:** Yes. An attacker with physical access can plug in a
malicious or standard USB Bluetooth dongle and unplug it at the right time to
win the race condition.
- **Unprivileged / User Namespace:** No. Unprivileged users cannot trigger this
bug purely from software. They lack the permissions to unbind USB drivers via
sysfs (`/sys/bus/usb/drivers/btusb/unbind` is root-only) or to emulate USB
devices via `dummy_hcd` (which requires root/specific capabilities not granted
in user namespaces).
- **Remote Trigger:** No. A remote Bluetooth device can send packets to schedule
the work, but it cannot force the host's USB subsystem to disconnect the device,
which is strictly required to free the object and trigger the UAF.
**Conclusion:**
This is a classic race condition on device disconnect leading to a highly
exploitable Use-After-Free. It poses a severe security risk (Privilege
Escalation and Denial of Service) but is constrained by the requirement of
physical access to plug and unplug a USB device (Peripheral Trigger). Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/06/01 14:15 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/06/01 14:15 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/da92996965d3349c6be15aa096c2eb096593eac9]
|
| 3/1 |
2026/06/01 14:15 |
action |
kernel-builder |
29m
Results: map[KernelObj:/app/workdir/cache/build/ef2e1741890f25a76ced798c85f58abb76b71674]
|
| 4/1 |
2026/06/01 14:44 |
action |
codesearch-prepare |
18m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/06/01 15:03 |
agent |
expert |
2m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
==================================================================
BUG: KASAN: slab-use-after-free in __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:132 [inline]
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x40/0x60 kernel/locking/spinlock.c:166
Read of size 1 at addr ffff888029fc01a8 by task kworker/1:1/10569
CPU: 1 UID: 0 PID: 10569 Comm: kworker/1:1 Tainted: G L syzkaller #0 PREEMPT_{RT,(full)}
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
Workqueue: events btusb_rx_work
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_address_description+0x55/0x1e0 mm/kasan/report.c:378
print_report+0x58/0x70 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
__kasan_check_byte+0x2a/0x40 mm/kasan/common.c:574
kasan_check_byte include/linux/kasan.h:402 [inline]
lock_acquire+0x84/0x350 kernel/locking/lockdep.c:5844
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:132 [inline]
_raw_spin_lock_irqsave+0x40/0x60 kernel/locking/spinlock.c:166
rtlock_slowlock kernel/locking/rtmutex.c:1918 [inline]
rtlock_lock kernel/locking/spinlock_rt.c:43 [inline]
__rt_spin_lock kernel/locking/spinlock_rt.c:49 [inline]
rt_spin_lock+0x157/0x400 kernel/locking/spinlock_rt.c:57
spin_lock include/linux/spinlock_rt.h:45 [inline]
skb_dequeue+0x2d/0x150 net/core/skbuff.c:3943
btusb_rx_work+0x27/0xd0 drivers/bluetooth/btusb.c:2477
process_one_work+0x98b/0x1630 kernel/workqueue.c:3306
process_scheduled_works kernel/workqueue.c:3389 [inline]
worker_thread+0xb49/0x1140 kernel/workqueue.c:3470
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Allocated by task 8189:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x3a6/0x690 mm/slub.c:5432
kmalloc_noprof include/linux/slab.h:950 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
btusb_probe+0x396/0x3050 drivers/bluetooth/btusb.c:4086
usb_probe_interface+0x659/0xc70 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x267/0xaf0 drivers/base/dd.c:707
__driver_probe_device+0x1e2/0x350 drivers/base/dd.c:869
driver_probe_device+0x4f/0x240 drivers/base/dd.c:899
__device_attach_driver+0x270/0x410 drivers/base/dd.c:1027
bus_for_each_drv+0x25b/0x2f0 drivers/base/bus.c:500
__device_attach+0x2c8/0x450 drivers/base/dd.c:1099
device_initial_probe+0xa1/0xd0 drivers/base/dd.c:1154
bus_probe_device+0x12d/0x220 drivers/base/bus.c:620
device_add+0x7ec/0xb90 drivers/base/core.c:3702
usb_set_configuration+0x1a87/0x2110 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8d/0x150 drivers/usb/core/generic.c:250
usb_probe_device+0x1c4/0x3b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x267/0xaf0 drivers/base/dd.c:707
__driver_probe_device+0x1e2/0x350 drivers/base/dd.c:869
driver_probe_device+0x4f/0x240 drivers/base/dd.c:899
__device_attach_driver+0x270/0x410 drivers/base/dd.c:1027
bus_for_each_drv+0x25b/0x2f0 drivers/base/bus.c:500
__device_attach+0x2c8/0x450 drivers/base/dd.c:1099
device_initial_probe+0xa1/0xd0 drivers/base/dd.c:1154
bus_probe_device+0x12d/0x220 drivers/base/bus.c:620
device_add+0x7ec/0xb90 drivers/base/core.c:3702
usb_new_device+0x9f8/0x16e0 drivers/usb/core/hub.c:2695
hub_port_connect drivers/usb/core/hub.c:5567 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x2a49/0x4f60 drivers/usb/core/hub.c:5953
process_one_work+0x98b/0x1630 kernel/workqueue.c:3306
process_scheduled_works kernel/workqueue.c:3389 [inline]
worker_thread+0xb49/0x1140 kernel/workqueue.c:3470
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Freed by task 8189:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x5c/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2700 [inline]
slab_free mm/slub.c:6291 [inline]
kfree+0x1c5/0x6c0 mm/slub.c:6606
usb_unbind_interface+0x26e/0x910 drivers/usb/core/driver.c:458
device_remove drivers/base/dd.c:619 [inline]
__device_release_driver drivers/base/dd.c:1350 [inline]
device_release_driver_internal+0x4d9/0x870 drivers/base/dd.c:1373
bus_remove_device+0x45a/0x570 drivers/base/bus.c:664
device_del+0x52b/0x900 drivers/base/core.c:3891
usb_disable_device+0x3d4/0x8d0 drivers/usb/core/message.c:1478
usb_disconnect+0x315/0x970 drivers/usb/core/hub.c:2345
hub_port_connect drivers/usb/core/hub.c:5407 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x1cf9/0x4f60 drivers/usb/core/hub.c:5953
process_one_work+0x98b/0x1630 kernel/workqueue.c:3306
process_scheduled_works kernel/workqueue.c:3389 [inline]
worker_thread+0xb49/0x1140 kernel/workqueue.c:3470
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Last potentially related work creation:
kasan_save_stack+0x3e/0x60 mm/kasan/common.c:57
kasan_record_aux_stack+0xbd/0xd0 mm/kasan/generic.c:556
insert_work+0x3d/0x330 kernel/workqueue.c:2226
__queue_work+0xcfd/0x1010 kernel/workqueue.c:2381
queue_delayed_work_on+0x11a/0x1e0 kernel/workqueue.c:2600
queue_delayed_work include/linux/workqueue.h:713 [inline]
schedule_delayed_work include/linux/workqueue.h:855 [inline]
btusb_recv_event drivers/bluetooth/btusb.c:1233 [inline]
btusb_recv_intr+0x48a/0x750 drivers/bluetooth/btusb.c:1296
btusb_intr_complete+0x164/0x4c0 drivers/bluetooth/btusb.c:1481
__usb_hcd_giveback_urb+0x3b3/0x5e0 drivers/usb/core/hcd.c:1657
dummy_timer+0x8a9/0x47d0 drivers/usb/gadget/udc/dummy_hcd.c:2005
__run_hrtimer kernel/time/hrtimer.c:2032 [inline]
__hrtimer_run_queues+0x405/0xb10 kernel/time/hrtimer.c:2096
hrtimer_run_softirq+0x18f/0x260 kernel/time/hrtimer.c:2113
handle_softirqs+0x1de/0x6d0 kernel/softirq.c:626
__do_softirq kernel/softirq.c:660 [inline]
run_ktimerd+0x69/0x100 kernel/softirq.c:1155
smpboot_thread_fn+0x541/0xa50 kernel/smpboot.c:160
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff888029fc0000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 424 bytes inside of
freed 4096-byte region [ffff888029fc0000, ffff888029fc1000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x29fc0
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x80000000000040(head|node=0|zone=1)
page_type: f5(slab)
raw: 0080000000000040 ffff88813fea2140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000800040004 00000000f5000000 0000000000000000
head: 0080000000000040 ffff88813fea2140 dead000000000100 dead000000000122
head: 0000000000000000 0000000800040004 00000000f5000000 0000000000000000
head: 0080000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 12506, tgid 12506 (udevd), ts 1311497819285, free_ts 1308795551293
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x1f9/0x250 mm/page_alloc.c:1861
prep_new_page mm/page_alloc.c:1869 [inline]
get_page_from_freelist+0x27d6/0x2850 mm/page_alloc.c:3949
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5292
alloc_slab_page mm/slub.c:3289 [inline]
allocate_slab+0x74/0x5e0 mm/slub.c:3404
new_slab mm/slub.c:3447 [inline]
refill_objects+0x33c/0x3d0 mm/slub.c:7319
refill_sheaf mm/slub.c:2827 [inline]
__pcs_replace_empty_main+0x373/0x720 mm/slub.c:4664
alloc_from_pcs mm/slub.c:4762 [inline]
slab_alloc_node mm/slub.c:4896 [inline]
__do_kmalloc_node mm/slub.c:5307 [inline]
__kmalloc_noprof+0x530/0x7b0 mm/slub.c:5320
kmalloc_noprof include/linux/slab.h:954 [inline]
tomoyo_realpath_from_path+0xe3/0x5d0 security/tomoyo/realpath.c:251
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path2_perm+0x2e7/0x760 security/tomoyo/file.c:928
tomoyo_path_rename+0x14e/0x1b0 security/tomoyo/tomoyo.c:300
security_path_rename+0x248/0x460 security/security.c:1544
filename_renameat2+0x4c1/0x9c0 fs/namei.c:6167
__do_sys_rename fs/namei.c:6216 [inline]
__se_sys_rename+0x55/0x2c0 fs/namei.c:6212
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 14890 tgid 14890 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1405 [inline]
free_pages_prepare+0x900/0xa60 mm/page_alloc.c:1450
__free_contig_range_common+0x174/0x340 mm/page_alloc.c:6883
__free_contig_range mm/page_alloc.c:6928 [inline]
free_pages_bulk+0x48/0x120 mm/page_alloc.c:5245
vfree+0x292/0x390 mm/vmalloc.c:3467
vb2_vmalloc_put+0x68/0xb0 drivers/media/common/videobuf2/videobuf2-vmalloc.c:68
__vb2_buf_mem_free+0x119/0x2d0 drivers/media/common/videobuf2/videobuf2-core.c:275
__vb2_free_mem drivers/media/common/videobuf2/videobuf2-core.c:571 [inline]
__vb2_queue_free+0x414/0xb00 drivers/media/common/videobuf2/videobuf2-core.c:599
vb2_core_reqbufs+0x7a0/0x1410 drivers/media/common/videobuf2/videobuf2-core.c:905
__vb2_cleanup_fileio+0x109/0x1f0 drivers/media/common/videobuf2/videobuf2-core.c:2977
vb2_core_queue_release+0x27/0x150 drivers/media/common/videobuf2/videobuf2-core.c:2676
vb2_queue_release drivers/media/common/videobuf2/videobuf2-v4l2.c:956 [inline]
_vb2_fop_release drivers/media/common/videobuf2/videobuf2-v4l2.c:1159 [inline]
vb2_fop_release+0x171/0x200 drivers/media/common/videobuf2/videobuf2-v4l2.c:1173
v4l2_release+0x1b2/0x370 drivers/media/v4l2-core/v4l2-dev.c:468
__fput+0x461/0xa70 fs/file_table.c:510
task_work_run+0x1d9/0x270 kernel/task_work.c:233
resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
__exit_to_user_mode_loop kernel/entry/common.c:67 [inline]
exit_to_user_mode_loop+0xf3/0x4d0 kernel/entry/common.c:98
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:238 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline]
do_syscall_64+0x33e/0xf80 arch/x86/entry/syscall_64.c:100
Memory state around the buggy address:
ffff888029fc0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888029fc0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888029fc0180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888029fc0200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888029fc0280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Reply: **Bug Analysis:**
The bug is a Use-After-Free (UAF) in the Bluetooth USB driver (`btusb`).
1. **Root Cause:**
The `btusb_data` structure is allocated in `btusb_probe()` and freed in `btusb_disconnect()`. The driver uses a delayed work item, `rx_work`, to process incoming Bluetooth packets.
When the USB device is disconnected or the driver is unbound, `btusb_disconnect()` is invoked. This function calls `hci_unregister_dev()`, which eventually calls the driver's `btusb_close()` callback.
Inside `btusb_close()`, the driver attempts to cancel the delayed work using `cancel_delayed_work(&data->rx_work)`. However, `cancel_delayed_work()` only cancels the timer; if the work item is already executing on a CPU, it does not wait for it to finish (unlike `cancel_delayed_work_sync()`).
After `btusb_close()` returns, `btusb_disconnect()` proceeds to free the `btusb_data` structure via `kfree(data)`. If `btusb_rx_work()` is still running concurrently, it will access the freed `data` object (e.g., `data->acl_q`), resulting in a Use-After-Free.
2. **Exploitability:**
This bug is highly **Exploitable**. The freed `btusb_data` object is allocated in the `kmalloc-4k` slab cache. It contains several function pointers (such as `data->recv_acl`, `data->recv_event`, etc.) and spinlocks. An attacker can exploit this by spraying the heap with controlled data immediately after the object is freed. If the attacker successfully overwrites the `recv_acl` function pointer, they can achieve arbitrary kernel code execution when the still-running `btusb_rx_work()` executes `data->recv_acl(data->hdev, skb)`.
3. **Trigger Mechanism:**
To trigger this bug, an attacker needs to schedule the `rx_work` (e.g., by sending Bluetooth events/ACL data from the device) and then abruptly disconnect the device while the work is executing.
- **Peripheral Trigger:** Yes. An attacker with physical access can plug in a malicious or standard USB Bluetooth dongle and unplug it at the right time to win the race condition.
- **Unprivileged / User Namespace:** No. Unprivileged users cannot trigger this bug purely from software. They lack the permissions to unbind USB drivers via sysfs (`/sys/bus/usb/drivers/btusb/unbind` is root-only) or to emulate USB devices via `dummy_hcd` (which requires root/specific capabilities not granted in user namespaces).
- **Remote Trigger:** No. A remote Bluetooth device can send packets to schedule the work, but it cannot force the host's USB subsystem to disconnect the device, which is strictly required to free the object and trigger the UAF.
**Conclusion:**
This is a classic race condition on device disconnect leading to a highly exploitable Use-After-Free. It poses a severe security risk (Privilege Escalation and Denial of Service) but is constrained by the requirement of physical access to plug and unplug a USB device (Peripheral Trigger).
|
| 6/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 11354
output: 38
thoughts: 407
Thoughts: **Analyzing a KASAN Slab-Use-After-Free Report**
Alright, I've got a KASAN slab-use-after-free report to investigate. The trace indicates the bug is within `__raw_spin_lock_irqsave`, called from `skb_dequeue` which itself is in `btusb_rx_work`. This looks like a classic race condition. The freed object, according to the report, was allocated in `btusb_probe` and freed during the `usb_unbind_interface` process, specifically within the `btusb_disconnect` path (or a similar call that ultimately invokes `kfree`).
Let's dissect this. My initial instinct is to cross-reference the allocation and deallocation paths: `btusb_rx_work` and `btusb_probe` are the prime suspects, along with anything related to unbinding the interface. Okay, confirmed β allocation in `btusb_probe`, freeing in `usb_unbind_interface`.
I need to confirm the allocation and deallocation. Let's see...
```
__kmalloc_cache_noprof+0x3a6/0x690 mm/slub.c:5432
kmalloc_noprof include/linux/slab.h:950 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
btusb_probe+0x396/0x3050 drivers/bluetooth/btusb.c:4086
```
That's the allocation trace. Yep, `btusb_probe` is directly involved, it looks like it is using `kzalloc`.
```
kfree+0x1c5/0x6c0 mm/slub.c:6606
usb_unbind_interface+0x26e/0x910 drivers/usb/core/driver.c:458
```
And the freeing: `usb_unbind_interface` is calling `kfree`. The deallocation is as suspected.
```
skb_dequeue+0x2d/0x150 net/core/skbuff.c:3943
btusb_rx_work+0x27/0xd0 drivers/bluetooth/btusb.c:2477
```
That confirms the use-after-free in `btusb_rx_work`, specifically within `skb_dequeue`.
Time to dive into the code. I'm going to start by examining `drivers/bluetooth/btusb.c`, paying close attention to the interaction between `btusb_probe`, `btusb_rx_work`, and the unbinding process. This should pinpoint where the synchronization is failing.
|
| 7/2 |
2026/06/01 15:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_rx_work]
Results: map[SourceCode:2470: static void btusb_rx_work(struct work_struct *work)
2471: {
2472: struct btusb_data *data = container_of(work, struct btusb_data,
2473: rx_work.work);
2474: struct sk_buff *skb;
2475:
2476: /* Dequeue ACL data received during the interval */
2477: while ((skb = skb_dequeue(&data->acl_q)))
2478: data->recv_acl(data->hdev, skb);
2479: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 8/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 12597
output: 36
thoughts: 46
Thoughts: **Analyzing the Bluetooth USB Driver's Data Structures**
Okay, so the User-After-Free vulnerability, or UAF, is apparently occurring on `data->acl_q`. That's inside `struct btusb_data`. Alright, let's trace this back. Where is `struct btusb_data` being initialized and allocated? I need to go straight to `btusb_probe`. That's the logical place to start digging into the driver's setup and understand the lifespan of that crucial data structure. Let's see how that object is being handled, so I can understand the vulnerability.
|
| 9/2 |
2026/06/01 15:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_probe]
Results: map[SourceCode:4046: static int btusb_probe(struct usb_interface *intf,
4047: const struct usb_device_id *id)
4048: {
4049: struct gpio_desc *reset_gpio;
4050: struct btusb_data *data;
4051: struct hci_dev *hdev;
4052: unsigned ifnum_base;
4053: int err, priv_size;
4054:
4055: BT_DBG("intf %p id %p", intf, id);
4056:
4057: if ((id->driver_info & BTUSB_IFNUM_2) &&
4058: (intf->cur_altsetting->desc.bInterfaceNumber != 0) &&
4059: (intf->cur_altsetting->desc.bInterfaceNumber != 2))
4060: return -ENODEV;
4061:
4062: ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;
4063:
4064: if (!id->driver_info) {
4065: const struct usb_device_id *match;
4066:
4067: match = usb_match_id(intf, quirks_table);
4068: if (match)
4069: id = match;
4070: }
4071:
4072: if (id->driver_info == BTUSB_IGNORE)
4073: return -ENODEV;
4074:
4075: if (id->driver_info & BTUSB_ATH3012) {
4076: struct usb_device *udev = interface_to_usbdev(intf);
4077:
4078: /* Old firmware would otherwise let ath3k driver load
4079: * patch and sysconfig files
4080: */
4081: if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 &&
4082: !btusb_qca_need_patch(udev))
4083: return -ENODEV;
4084: }
4085:
4086: data = kzalloc_obj(*data);
4087: if (!data)
4088: return -ENOMEM;
4089:
4090: err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep,
4091: &data->bulk_tx_ep, &data->intr_ep, NULL);
4092: if (err) {
4093: kfree(data);
4094: return -ENODEV;
4095: }
4096:
4097: if (id->driver_info & BTUSB_AMP) {
4098: data->cmdreq_type = USB_TYPE_CLASS | 0x01;
4099: data->cmdreq = 0x2b;
4100: } else {
4101: data->cmdreq_type = USB_TYPE_CLASS;
4102: data->cmdreq = 0x00;
4103: }
4104:
4105: data->udev = interface_to_usbdev(intf);
4106: data->intf = intf;
4107:
4108: INIT_WORK(&data->work, btusb_work);
4109: INIT_WORK(&data->waker, btusb_waker);
4110: INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
4111:
4112: skb_queue_head_init(&data->acl_q);
4113:
4114: init_usb_anchor(&data->deferred);
4115: init_usb_anchor(&data->tx_anchor);
4116: spin_lock_init(&data->txlock);
4117:
4118: init_usb_anchor(&data->intr_anchor);
4119: init_usb_anchor(&data->bulk_anchor);
4120: init_usb_anchor(&data->isoc_anchor);
4121: init_usb_anchor(&data->diag_anchor);
4122: init_usb_anchor(&data->ctrl_anchor);
4123: spin_lock_init(&data->rxlock);
4124:
4125: priv_size = 0;
4126:
4127: data->recv_event = hci_recv_frame;
4128: data->recv_bulk = btusb_recv_bulk;
4129:
4130: if (id->driver_info & BTUSB_INTEL_COMBINED) {
4131: /* Allocate extra space for Intel device */
4132: priv_size += sizeof(struct btintel_data);
4133:
4134: /* Override the rx handlers */
4135: data->recv_event = btintel_recv_event;
4136: data->recv_bulk = btusb_recv_bulk_intel;
4137: } else if (id->driver_info & BTUSB_REALTEK) {
4138: /* Allocate extra space for Realtek device */
4139: priv_size += sizeof(struct btrealtek_data);
4140:
4141: data->recv_event = btusb_recv_event_realtek;
4142: } else if (id->driver_info & BTUSB_MEDIATEK) {
4143: /* Allocate extra space for Mediatek device */
4144: priv_size += sizeof(struct btmtk_data);
4145: }
4146:
4147: data->recv_acl = hci_recv_frame;
4148:
4149: hdev = hci_alloc_dev_priv(priv_size);
4150: if (!hdev) {
4151: kfree(data);
4152: return -ENOMEM;
4153: }
4154:
4155: hdev->bus = HCI_USB;
4156: hci_set_drvdata(hdev, data);
4157:
4158: data->hdev = hdev;
4159:
4160: SET_HCIDEV_DEV(hdev, &intf->dev);
4161:
4162: reset_gpio = gpiod_get_optional(&data->udev->dev, "reset",
4163: GPIOD_OUT_LOW);
4164: if (IS_ERR(reset_gpio)) {
4165: err = PTR_ERR(reset_gpio);
4166: goto out_free_dev;
4167: } else if (reset_gpio) {
4168: data->reset_gpio = reset_gpio;
4169: }
4170:
4171: hdev->open = btusb_open;
4172: hdev->close = btusb_close;
4173: hdev->flush = btusb_flush;
4174: hdev->send = btusb_send_frame;
4175: hdev->notify = btusb_notify;
4176: hdev->wakeup = btusb_wakeup;
4177: hdev->hci_drv = &btusb_hci_drv;
4178:
4179: #ifdef CONFIG_PM
4180: err = btusb_config_oob_wake(hdev);
4181: if (err)
4182: goto out_free_dev;
4183:
4184: /* Marvell devices may need a specific chip configuration */
4185: if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
4186: err = marvell_config_oob_wake(hdev);
4187: if (err)
4188: goto out_free_dev;
4189: }
4190: #endif
4191: if (id->driver_info & BTUSB_CW6622)
4192: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_STORED_LINK_KEY);
4193:
4194: if (id->driver_info & BTUSB_BCM2045)
4195: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_STORED_LINK_KEY);
4196:
4197: if (id->driver_info & BTUSB_BCM92035)
4198: hdev->setup = btusb_setup_bcm92035;
4199:
4200: if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
4201: (id->driver_info & BTUSB_BCM_PATCHRAM)) {
4202: hdev->manufacturer = 15;
4203: hdev->setup = btbcm_setup_patchram;
4204: hdev->set_diag = btusb_bcm_set_diag;
4205: hdev->set_bdaddr = btbcm_set_bdaddr;
4206:
4207: /* Broadcom LM_DIAG Interface numbers are hardcoded */
4208: data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
4209: }
4210:
4211: if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
4212: (id->driver_info & BTUSB_BCM_APPLE)) {
4213: hdev->manufacturer = 15;
4214: hdev->setup = btbcm_setup_apple;
4215: hdev->set_diag = btusb_bcm_set_diag;
4216:
4217: /* Broadcom LM_DIAG Interface numbers are hardcoded */
4218: data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
4219: }
4220:
4221: /* Combined Intel Device setup to support multiple setup routine */
4222: if (id->driver_info & BTUSB_INTEL_COMBINED) {
4223: err = btintel_configure_setup(hdev, btusb_driver.name);
4224: if (err)
4225: goto out_free_dev;
4226:
4227: /* Transport specific configuration */
4228: hdev->send = btusb_send_frame_intel;
4229: hdev->reset = btusb_intel_reset;
4230:
4231: if (id->driver_info & BTUSB_INTEL_NO_WBS_SUPPORT)
4232: btintel_set_flag(hdev, INTEL_ROM_LEGACY_NO_WBS_SUPPORT);
4233:
4234: if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD)
4235: btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD);
4236:
4237: if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED)
4238: btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED);
4239: }
4240:
4241: if (id->driver_info & BTUSB_MARVELL)
4242: hdev->set_bdaddr = btusb_set_bdaddr_marvell;
4243:
4244: if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) &&
4245: (id->driver_info & BTUSB_MEDIATEK)) {
4246: hdev->setup = btusb_mtk_setup;
4247: hdev->shutdown = btusb_mtk_shutdown;
4248: hdev->manufacturer = 70;
4249: hdev->reset = btmtk_reset_sync;
4250: hdev->set_bdaddr = btmtk_set_bdaddr;
4251: hdev->send = btusb_send_frame_mtk;
4252: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN);
4253: hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP);
4254: data->recv_acl = btmtk_usb_recv_acl;
4255: data->recv_event = btmtk_recv_event;
4256: data->suspend = btmtk_usb_suspend;
4257: data->resume = btmtk_usb_resume;
4258: data->disconnect = btusb_mtk_disconnect;
4259: }
4260:
4261: if (id->driver_info & BTUSB_SWAVE) {
4262: hci_set_quirk(hdev, HCI_QUIRK_FIXUP_INQUIRY_MODE);
4263: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_LOCAL_COMMANDS);
4264: }
4265:
4266: if (id->driver_info & BTUSB_INTEL_BOOT) {
4267: hdev->manufacturer = 2;
4268: hci_set_quirk(hdev, HCI_QUIRK_RAW_DEVICE);
4269: }
4270:
4271: if (id->driver_info & BTUSB_ATH3012) {
4272: data->setup_on_usb = btusb_setup_qca;
4273: hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
4274: hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
4275: hci_set_quirk(hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER);
4276: }
4277:
4278: if (id->driver_info & BTUSB_QCA_ROME) {
4279: data->setup_on_usb = btusb_setup_qca;
4280: hdev->shutdown = btusb_shutdown_qca;
4281: hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
4282: hdev->reset = btusb_qca_reset;
4283: hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
4284: btusb_check_needs_reset_resume(intf);
4285: }
4286:
4287: if (id->driver_info & BTUSB_QCA_WCN6855) {
4288: data->qca_dump.id_vendor = id->idVendor;
4289: data->qca_dump.id_product = id->idProduct;
4290: data->recv_event = btusb_recv_evt_qca;
4291: data->recv_acl = btusb_recv_acl_qca;
4292: hci_devcd_register(hdev, btusb_coredump_qca, btusb_dump_hdr_qca, NULL);
4293: data->setup_on_usb = btusb_setup_qca;
4294: hdev->classify_pkt_type = btusb_classify_qca_pkt_type;
4295: hdev->shutdown = btusb_shutdown_qca;
4296: hdev->set_bdaddr = btusb_set_bdaddr_wcn6855;
4297: hdev->reset = btusb_qca_reset;
4298: hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
4299: hci_set_msft_opcode(hdev, 0xFD70);
4300: }
4301:
4302: if (id->driver_info & BTUSB_AMP) {
4303: /* AMP controllers do not support SCO packets */
4304: data->isoc = NULL;
4305: } else {
4306: /* Interface orders are hardcoded in the specification */
4307: data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
4308: data->isoc_ifnum = ifnum_base + 1;
4309: }
4310:
4311: if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
4312: (id->driver_info & BTUSB_REALTEK)) {
4313: btrtl_set_driver_name(hdev, btusb_driver.name);
4314: hdev->setup = btusb_setup_realtek;
4315: hdev->shutdown = btrtl_shutdown_realtek;
4316: hdev->reset = btusb_rtl_reset;
4317: hdev->hw_error = btusb_rtl_hw_error;
4318:
4319: /* Realtek devices need to set remote wakeup on auto-suspend */
4320: set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags);
4321: set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags);
4322: }
4323:
4324: if (id->driver_info & BTUSB_ACTIONS_SEMI) {
4325: /* Support is advertised, but not implemented */
4326: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ERR_DATA_REPORTING);
4327: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER);
4328: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT);
4329: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_SCAN);
4330: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE);
4331: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_CREATE_CONN);
4332: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT);
4333: }
4334:
4335: if (!reset)
4336: hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE);
4337:
4338: if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
4339: if (!disable_scofix)
4340: hci_set_quirk(hdev, HCI_QUIRK_FIXUP_BUFFER_SIZE);
4341: }
4342:
4343: if (id->driver_info & BTUSB_BROKEN_ISOC)
4344: data->isoc = NULL;
4345:
4346: if (id->driver_info & BTUSB_WIDEBAND_SPEECH)
4347: hci_set_quirk(hdev, HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED);
4348:
4349: if (id->driver_info & BTUSB_INVALID_LE_STATES)
4350: hci_set_quirk(hdev, HCI_QUIRK_BROKEN_LE_STATES);
4351:
4352: if (id->driver_info & BTUSB_DIGIANSWER) {
4353: data->cmdreq_type = USB_TYPE_VENDOR;
4354: hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE);
4355: }
4356:
4357: if (id->driver_info & BTUSB_CSR) {
4358: struct usb_device *udev = data->udev;
4359: u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
4360:
4361: /* Old firmware would otherwise execute USB reset */
4362: if (bcdDevice < 0x117)
4363: hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE);
4364:
4365: /* This must be set first in case we disable it for fakes */
4366: hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
4367:
4368: /* Fake CSR devices with broken commands */
4369: if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 &&
4370: le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
4371: hdev->setup = btusb_setup_csr;
4372: }
4373:
4374: if (id->driver_info & BTUSB_SNIFFER) {
4375: struct usb_device *udev = data->udev;
4376:
4377: /* New sniffer firmware has crippled HCI interface */
4378: if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
4379: hci_set_quirk(hdev, HCI_QUIRK_RAW_DEVICE);
4380: }
4381:
4382: if (id->driver_info & BTUSB_INTEL_BOOT) {
4383: /* A bug in the bootloader causes that interrupt interface is
4384: * only enabled after receiving SetInterface(0, AltSetting=0).
4385: */
4386: err = usb_set_interface(data->udev, 0, 0);
4387: if (err < 0) {
4388: BT_ERR("failed to set interface 0, alt 0 %d", err);
4389: goto out_free_dev;
4390: }
4391: }
4392:
4393: if (data->isoc) {
4394: err = usb_driver_claim_interface(&btusb_driver,
4395: data->isoc, data);
4396: if (err < 0)
4397: goto out_free_dev;
4398: }
4399:
4400: if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) {
4401: if (!usb_driver_claim_interface(&btusb_driver,
4402: data->diag, data))
4403: __set_diag_interface(hdev);
4404: else
4405: data->diag = NULL;
4406: }
4407:
4408: if (enable_autosuspend)
4409: usb_enable_autosuspend(data->udev);
4410:
4411: data->poll_sync = enable_poll_sync;
4412:
4413: err = hci_register_dev(hdev);
4414: if (err < 0)
4415: goto out_free_dev;
4416:
4417: usb_set_intfdata(intf, data);
4418:
4419: debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data,
4420: &force_poll_sync_fops);
4421:
4422: return 0;
4423:
4424: out_free_dev:
4425: if (data->reset_gpio)
4426: gpiod_put(data->reset_gpio);
4427: hci_free_dev(hdev);
4428: kfree(data);
4429: return err;
4430: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 10/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 19550
output: 36
thoughts: 91
Thoughts: Here's my understanding of the relevant code, presented as a series of connected thoughts:
**Bluetooth USB Driver Analysis: Receiving Work and Data Structures**
Okay, so I'm digging into the Bluetooth USB driver's receive path. The `btusb_rx_work` is crucial β that's where the incoming data is actually processed. Looking at `btusb_probe`, that's where it's set up: `INIT_DELAYED_WORK` is used to initialize the `rx_work` and tie it to the function `btusb_rx_work`. Good. That's the entry point for handling incoming packets.
I also see that an important queue, `data->acl_q`, is initialized with `skb_queue_head_init`. Right. That's likely where the received packets are temporarily stored, probably ACL (Asynchronous Connection-Less) packets, before being further processed. Now I need to see how these elements are cleaned up at disconnect to avoid memory leaks. Let me check the `btusb_disconnect` function to see how the data structures, particularly `data` which likely contains `rx_work` and `acl_q`, are properly freed during device removal. That's the key to understanding the entire life-cycle of these workqueues and buffers.
|
| 11/2 |
2026/06/01 15:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_disconnect]
Results: map[SourceCode:4432: static void btusb_disconnect(struct usb_interface *intf)
4433: {
4434: struct btusb_data *data = usb_get_intfdata(intf);
4435: struct hci_dev *hdev;
4436:
4437: BT_DBG("intf %p", intf);
4438:
4439: if (!data)
4440: return;
4441:
4442: hdev = data->hdev;
4443: usb_set_intfdata(data->intf, NULL);
4444:
4445: if (data->isoc)
4446: usb_set_intfdata(data->isoc, NULL);
4447:
4448: if (data->diag)
4449: usb_set_intfdata(data->diag, NULL);
4450:
4451: if (data->disconnect)
4452: data->disconnect(hdev);
4453:
4454: hci_unregister_dev(hdev);
4455:
4456: if (data->oob_wake_irq)
4457: device_init_wakeup(&data->udev->dev, false);
4458: if (data->reset_gpio)
4459: gpiod_put(data->reset_gpio);
4460:
4461: if (intf == data->intf) {
4462: if (data->isoc)
4463: usb_driver_release_interface(&btusb_driver, data->isoc);
4464: if (data->diag)
4465: usb_driver_release_interface(&btusb_driver, data->diag);
4466: } else if (intf == data->isoc) {
4467: if (data->diag)
4468: usb_driver_release_interface(&btusb_driver, data->diag);
4469: usb_driver_release_interface(&btusb_driver, data->intf);
4470: } else if (intf == data->diag) {
4471: if (data->isoc)
4472: usb_driver_release_interface(&btusb_driver, data->isoc);
4473: usb_driver_release_interface(&btusb_driver, data->intf);
4474: }
4475:
4476: hci_free_dev(hdev);
4477: kfree(data);
4478: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 12/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 20687
output: 36
thoughts: 113
Thoughts: **Investigating a Potential Memory Leak in btusb_disconnect**
Okay, so I'm looking at `btusb_disconnect`, and it seems like `kfree(data)` is freeing the `data` structure directly. But hold on a second... `data->rx_work` is a delayed work item. My immediate concern is, is that work item properly cancelled before `data` is freed? That would be a nasty memory corruption bug, especially if the delayed work attempts to access already freed memory.
Let's quickly check the related functions. I need to make sure `hci_unregister_dev(hdev)` and `hci_free_dev(hdev)` don't inadvertently create a problem. However, my primary focus is: does `btusb_disconnect` handle cancelling `data->rx_work` itself?
Actually, let me step back and think... perhaps `btusb_close` handles this cancellation? That's more likely the cleanup point. I need to go back and check the implementation of `btusb_close` to see if it cancels `data->rx_work`. That seems like the more logical place for it to be handled.
|
| 13/2 |
2026/06/01 15:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_close]
Results: map[SourceCode:2047: static int btusb_close(struct hci_dev *hdev)
2048: {
2049: struct btusb_data *data = hci_get_drvdata(hdev);
2050: int err;
2051:
2052: BT_DBG("%s", hdev->name);
2053:
2054: cancel_delayed_work(&data->rx_work);
2055: cancel_work_sync(&data->work);
2056: cancel_work_sync(&data->waker);
2057:
2058: skb_queue_purge(&data->acl_q);
2059:
2060: clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2061: clear_bit(BTUSB_BULK_RUNNING, &data->flags);
2062: clear_bit(BTUSB_INTR_RUNNING, &data->flags);
2063: clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
2064:
2065: btusb_stop_traffic(data);
2066: btusb_free_frags(data);
2067:
2068: err = usb_autopm_get_interface(data->intf);
2069: if (err < 0)
2070: goto failed;
2071:
2072: data->intf->needs_remote_wakeup = 0;
2073:
2074: /* Enable remote wake up for auto-suspend */
2075: if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags))
2076: data->intf->needs_remote_wakeup = 1;
2077:
2078: usb_autopm_put_interface(data->intf);
2079:
2080: failed:
2081: usb_scuttle_anchored_urbs(&data->deferred);
2082: return 0;
2083: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 14/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 21680
output: 37
thoughts: 128
|
| 15/2 |
2026/06/01 15:03 |
tool |
grepper |
0m
Args: map[Expression:cancel_delayed_work.*rx_work PathPrefix:drivers/bluetooth/btusb.c]
Results: map[Output:drivers/bluetooth/btusb.c=2047=static int btusb_close(struct hci_dev *hdev)
--
drivers/bluetooth/btusb.c-2053-
drivers/bluetooth/btusb.c:2054: cancel_delayed_work(&data->rx_work);
drivers/bluetooth/btusb.c-2055- cancel_work_sync(&data->work);
--
drivers/bluetooth/btusb.c=2085=static int btusb_flush(struct hci_dev *hdev)
--
drivers/bluetooth/btusb.c-2090-
drivers/bluetooth/btusb.c:2091: cancel_delayed_work(&data->rx_work);
drivers/bluetooth/btusb.c-2092-
]
|
| 16/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 22050
output: 38
thoughts: 308
Thoughts: **Race Condition Alert! Bluetooth USB Driver.**
Okay, let's break this down. My initial observation is that `cancel_delayed_work(&data->rx_work)` pops up in both `btusb_close` and `btusb_flush`. Makes sense, standard cleanup. The crucial bit is that if `rx_work` is *already* running, `cancel_delayed_work` will return false. The work continues. Right, so far, so good, textbook.
Then, things get interesting. `btusb_disconnect` gets called, which, as expected, frees `data`. Now, I recall, `btusb_disconnect` has the unfortunate habit of calling `hci_unregister_dev(hdev)`. And that makes me think, does `hci_unregister_dev` call `btusb_close`? Yes! Turns out, `hci_unregister_dev` calls `hci_dev_do_close(hdev)` which in turn invokes `hdev->close(hdev)`. And guess what `hdev->close` does? It uses `cancel_delayed_work(&data->rx_work)`.
So, the nasty race condition is rearing its ugly head: If `rx_work` is *already* running, it will continue running even as `data` is freed in `btusb_disconnect`. Thatβs a memory access after free situation waiting to happen. This is incredibly dangerous.
Now, where is `rx_work` being queued? I have the trace hereβ¦it's being queued from `btusb_recv_intr` and `btusb_intr_complete`. Alright, let's dive into those functions right now to see if we can understand the conditions under which that delayed work is being enqueued, and see how to prevent this race condition. I need to understand the timing of the interrupt processing and the disconnect sequence. This smells like a classic interrupt vs. main thread problem, and a potential double free if not handled properly. I need to check the exact circumstances when this is a real problem.
|
| 17/2 |
2026/06/01 15:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_recv_event]
Results: map[SourceCode:1229: static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
1230: {
1231: if (data->intr_interval) {
1232: /* Trigger dequeue immediately if an event is received */
1233: schedule_delayed_work(&data->rx_work, 0);
1234: }
1235:
1236: return data->recv_event(data->hdev, skb);
1237: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 18/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 23004
output: 31
thoughts: 186
Thoughts: **UAF Vulnerability in Bluetooth USB Driver**
Okay, so I'm looking at this Bluetooth USB driver code and something's not right. The `schedule_delayed_work(&data->rx_work, 0)` function gets called, which seems normal enough for handling receive work. But then, if the device gets disconnected, `btusb_disconnect` is invoked, right? And that, in turn, calls `hci_unregister_dev(hdev)`. `hci_unregister_dev` then calls `hci_dev_do_close`, which eventually leads to a call to `btusb_close`.
Here's where it gets interesting: `btusb_close` then calls `cancel_delayed_work(&data->rx_work)`. The problem is that `cancel_delayed_work` doesn't wait for the work to finish if it's already executing. Crucially, `btusb_disconnect` *immediately* frees the `data` structure after the `cancel_delayed_work` call. This means that if `rx_work` is still running when `btusb_disconnect` frees `data`, the work will eventually access freed memory, specifically `data->acl_q`, resulting in a Use-After-Free (UAF) vulnerability. This is a critical bug.
Wait a second... does `cancel_delayed_work_sync` need to be used instead? If so, this problem goes away because the function blocks until the work is complete. I need to make sure `rx_work` is cancelled correctly in this scenario. I have to check the codebase to ensure `rx_work` is cancelled at other places and is always done properly.
|
| 19/2 |
2026/06/01 15:03 |
tool |
grepper |
0m
Args: map[Expression:rx_work PathPrefix:drivers/bluetooth/btusb.c]
Results: map[Output:drivers/bluetooth/btusb.c=952=struct btusb_data {
--
drivers/bluetooth/btusb.c-965- struct work_struct waker;
drivers/bluetooth/btusb.c:966: struct delayed_work rx_work;
drivers/bluetooth/btusb.c-967-
--
drivers/bluetooth/btusb.c=1229=static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
--
drivers/bluetooth/btusb.c-1232- /* Trigger dequeue immediately if an event is received */
drivers/bluetooth/btusb.c:1233: schedule_delayed_work(&data->rx_work, 0);
drivers/bluetooth/btusb.c-1234- }
--
drivers/bluetooth/btusb.c=1307=static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb)
--
drivers/bluetooth/btusb.c-1315- skb_queue_tail(&data->acl_q, skb);
drivers/bluetooth/btusb.c:1316: schedule_delayed_work(&data->rx_work, data->intr_interval);
drivers/bluetooth/btusb.c-1317-
--
drivers/bluetooth/btusb.c=2047=static int btusb_close(struct hci_dev *hdev)
--
drivers/bluetooth/btusb.c-2053-
drivers/bluetooth/btusb.c:2054: cancel_delayed_work(&data->rx_work);
drivers/bluetooth/btusb.c-2055- cancel_work_sync(&data->work);
--
drivers/bluetooth/btusb.c=2085=static int btusb_flush(struct hci_dev *hdev)
--
drivers/bluetooth/btusb.c-2090-
drivers/bluetooth/btusb.c:2091: cancel_delayed_work(&data->rx_work);
drivers/bluetooth/btusb.c-2092-
--
drivers/bluetooth/btusb.c=2458=static void btusb_waker(struct work_struct *work)
--
drivers/bluetooth/btusb.c-2469-
drivers/bluetooth/btusb.c:2470:static void btusb_rx_work(struct work_struct *work)
drivers/bluetooth/btusb.c-2471-{
drivers/bluetooth/btusb.c-2472- struct btusb_data *data = container_of(work, struct btusb_data,
drivers/bluetooth/btusb.c:2473: rx_work.work);
drivers/bluetooth/btusb.c-2474- struct sk_buff *skb;
--
drivers/bluetooth/btusb.c=4046=static int btusb_probe(struct usb_interface *intf,
--
drivers/bluetooth/btusb.c-4109- INIT_WORK(&data->waker, btusb_waker);
drivers/bluetooth/btusb.c:4110: INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
drivers/bluetooth/btusb.c-4111-
]
|
| 20/2 |
2026/06/01 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 24406
output: 36
thoughts: 978
Thoughts: **UAF Vulnerability in `btusb` Driver Analysis**
Okay, so I've been digging into this `btusb` driver and found a potential use-after-free (UAF) bug. The code uses `cancel_delayed_work(&data->rx_work)` which is concerning. If `rx_work` is still running when `btusb_disconnect` proceeds, `cancel_delayed_work` returns false without waiting, and then `data` gets freed before `rx_work` completes. That's the UAF. The fix looks straightforward: replace that with `cancel_delayed_work_sync(&data->rx_work)` in either `btusb_close` or `btusb_disconnect` to ensure the work is cancelled before the memory is released.
Wait, `btusb_close` seems like it's called with some lock held, maybe `hdev->req_lock` via `hci_dev_do_close` which is called by `hci_unregister_dev`. So maybe `cancel_delayed_work_sync` would be best in `btusb_close` itself to avoid any potential lock issues.
Now, let's nail down the impact. The UAF is in `btusb_rx_work`. The object `data` is freed, and then `btusb_rx_work` tries to access `data->acl_q` and `data->hdev`. Specifically, `skb_dequeue(&data->acl_q)` will try to take a spinlock on `data->acl_q.lock`. Since `data` is freed, `data->acl_q.lock` is now in freed memory. This means we're dealing with a slab-use-after-free situation on `data`.
Is this actually exploitable? Yes, it's a UAF on a 4K object! The attacker would need to either plug in a malicious USB device or use something like `dummy_hcd` to emulate one. This suggests a peripheral trigger. Can this be triggered remotely? No, it requires a USB disconnect.
The syzkaller trace confirms this uses `dummy_hcd`. While this usually requires root or specific permissions to interact with gadgetfs or `dummy_hcd`, if an unprivileged user can physically plug and unplug a USB device, they can trigger this. So it *is* a peripheral trigger.
What about other ways to trigger this? Are there any userspace interfaces for USB disconnect? Maybe through sysfs `bind`/`unbind`? No, unprivileged users can't write to `/sys/bus/usb/drivers/.../unbind`. They can't trigger this unless they have physical access. What if it's a virtual USB device in a VM? A guest VM can trigger it if the host passes through a USB device, but the bug is in the guest kernel. But can a VM guest trigger this in the host kernel? No, the host kernel won't be running `btusb` for the devices passed to the guest. But, what if the bug is in the host kernel, and the guest is a malicious USB device? If the host kernel is configured to attach `btusb` to a USB device emulated by the guest, then yes, the guest can trigger it in the host. But usually, USB devices are not emulated by the guest to the host.
Now, let's assess the exploitability dimensions. It is definitely exploitable! The attacker can spray 4K objects to potentially control `data->acl_q.lock` and `data->hdev`. `skb_dequeue` uses `spin_lock_irqsave`, which could be exploited if the lock is overwritten. Also, the potentially vulnerable code can call `data->recv_acl(data->hdev, skb)`, which, wait, is a *function pointer*! This is huge! Let me check `struct btusb_data`...
|
| 21/2 |
2026/06/01 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_data]
Results: map[SourceCode: 952: struct btusb_data {
953: struct hci_dev *hdev;
954: struct usb_device *udev;
955: struct usb_interface *intf;
956: struct usb_interface *isoc;
957: struct usb_interface *diag;
958: unsigned isoc_ifnum;
959:
960: unsigned long flags;
961:
962: bool poll_sync;
963: int intr_interval;
964: struct work_struct work;
965: struct work_struct waker;
966: struct delayed_work rx_work;
967:
968: struct sk_buff_head acl_q;
969:
970: struct usb_anchor deferred;
971: struct usb_anchor tx_anchor;
972: int tx_in_flight;
973: spinlock_t txlock;
974:
975: struct usb_anchor intr_anchor;
976: struct usb_anchor bulk_anchor;
977: struct usb_anchor isoc_anchor;
978: struct usb_anchor diag_anchor;
979: struct usb_anchor ctrl_anchor;
980: spinlock_t rxlock;
981:
982: struct sk_buff *evt_skb;
983: struct sk_buff *acl_skb;
984: struct sk_buff *sco_skb;
985:
986: struct usb_endpoint_descriptor *intr_ep;
987: struct usb_endpoint_descriptor *bulk_tx_ep;
988: struct usb_endpoint_descriptor *bulk_rx_ep;
989: struct usb_endpoint_descriptor *isoc_tx_ep;
990: struct usb_endpoint_descriptor *isoc_rx_ep;
991: struct usb_endpoint_descriptor *diag_tx_ep;
992: struct usb_endpoint_descriptor *diag_rx_ep;
993:
994: struct gpio_desc *reset_gpio;
995:
996: __u8 cmdreq_type;
997: __u8 cmdreq;
998:
999: unsigned int sco_num;
1000: unsigned int air_mode;
1001: bool usb_alt6_packet_flow;
1002: int isoc_altsetting;
1003: int suspend_count;
1004:
1005: int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
1006: int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb);
1007: int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
1008:
1009: int (*setup_on_usb)(struct hci_dev *hdev);
1010:
1011: int (*suspend)(struct hci_dev *hdev);
1012: int (*resume)(struct hci_dev *hdev);
1013: int (*disconnect)(struct hci_dev *hdev);
1014:
1015: int oob_wake_irq; /* irq for out-of-band wake-on-bt */
1016:
1017: struct qca_dump_info qca_dump;
1018: };
SourceFile:drivers/bluetooth/btusb.c]
|
| 22/2 |
2026/06/01 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 27263
output: 38
thoughts: 862
Thoughts: **UAF Vulnerability in `btusb` Driver**
Okay, so I've confirmed it. `data->recv_acl` is indeed a function pointer, and the `btusb_rx_work` function dequeues and calls it within a loop. The key here is the potential for a Use-After-Free vulnerability. If an attacker can manipulate the system to free the `4K` object that contains this function pointer and then spray memory to overwrite it, they can control both `data->recv_acl` with an arbitrary kernel address *and* `data->hdev`, which becomes the first argument. This is a classic recipe for arbitrary code execution. Trivial, even.
Let me run through the exploitability assessment:
* **Exploitable:** Absolutely, yes.
* **Denial of Service:** Yes, definitely. Triggering a UAF is going to crash something.
* **Privilege:** It requires physical USB access or root privileges to interact with `sysfs` or the dummy HCD, so no, it's not accessible from unprivileged processes.
* **User Namespaces:** No, USB devices and sysfs unbind actions are not accessible in user namespaces.
* **VM Guest Trigger:** Initially, I thought no, but the context here matters. The question is "Can a typical KVM guest trigger this in the host?". No. This is a USB driver and not a typical VM setup.
* **Confidential Computing Context Host Trigger:** No.
* **Network Trigger:** No.
* **Remote Trigger:** No.
* **Peripheral Trigger:** Bingo. An attacker can connect a malicious USB Bluetooth dongle, send events that schedule `rx_work`, then unplug it at just the right moment. That is a direct peripheral trigger.
* **Malicious Filesystem Trigger:** No.
Now, I was curious about the code's design. The code uses `cancel_delayed_work`, not `cancel_delayed_work_sync`, in `btusb_close`. A brief investigation into the code reveals this is probably an oversight. `btusb_close` is called from `hci_dev_do_close`, which holds a mutex, `hdev->req_lock`, allowing for sleeping. `cancel_work_sync` is called right after `cancel_delayed_work`, which also sleeps. Therefore, the argument that sleeping is not allowed is invalidated. The only reason I can see that `cancel_delayed_work` was used is that the developer might not have been aware of the semantics. The function `btusb_rx_work` does call `data->recv_acl` within a loop. Usually, `data->recv_acl` is `hci_recv_frame`.
|
| 23/2 |
2026/06/01 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_core.c Name:hci_recv_frame]
Results: map[SourceCode:2917: /* Receive frame from HCI drivers */
2918: int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
2919: {
2920: u8 dev_pkt_type;
2921:
2922: if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
2923: && !test_bit(HCI_INIT, &hdev->flags))) {
2924: kfree_skb(skb);
2925: return -ENXIO;
2926: }
2927:
2928: /* Check if the driver agree with packet type classification */
2929: dev_pkt_type = hci_dev_classify_pkt_type(hdev, skb);
2930: if (hci_skb_pkt_type(skb) != dev_pkt_type) {
2931: hci_skb_pkt_type(skb) = dev_pkt_type;
2932: }
2933:
2934: switch (hci_skb_pkt_type(skb)) {
2935: case HCI_EVENT_PKT:
2936: break;
2937: case HCI_ACLDATA_PKT:
2938: /* Detect if ISO packet has been sent as ACL */
2939: if (hci_conn_num(hdev, CIS_LINK) ||
2940: hci_conn_num(hdev, BIS_LINK) ||
2941: hci_conn_num(hdev, PA_LINK)) {
2942: __u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
2943: __u8 type;
2944:
2945: type = hci_conn_lookup_type(hdev, hci_handle(handle));
2946: if (type == CIS_LINK || type == BIS_LINK ||
2947: type == PA_LINK)
2948: hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
2949: }
2950: break;
2951: case HCI_SCODATA_PKT:
2952: break;
2953: case HCI_ISODATA_PKT:
2954: break;
2955: case HCI_DRV_PKT:
2956: break;
2957: default:
2958: kfree_skb(skb);
2959: return -EINVAL;
2960: }
2961:
2962: /* Incoming skb */
2963: bt_cb(skb)->incoming = 1;
2964:
2965: /* Time stamp */
2966: __net_timestamp(skb);
2967:
2968: skb_queue_tail(&hdev->rx_q, skb);
2969: queue_work(hdev->workqueue, &hdev->rx_work);
2970:
2971: return 0;
2972: }
SourceFile:net/bluetooth/hci_core.c]
|
| 24/2 |
2026/06/01 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 29651
output: 36
thoughts: 357
Thoughts: **Analyzing Potential Race Conditions in `btusb_close`**
Okay, so `hci_recv_frame` just throws the skb onto `hdev->rx_q` and schedules `hdev->rx_work`. That's straightforward, and it doesn't touch any of the locks that `btusb_close` uses. Therefore, `cancel_delayed_work_sync` shouldn't deadlock, which is a relief.
But wait, I need to be completely sure. Is *anywhere* else `rx_work` getting scheduled? Yes, I see it: `schedule_delayed_work(&data->rx_work, 0);` So if `btusb_close` calls `cancel_delayed_work_sync(&data->rx_work)`, could an interrupt still sneak in and schedule it after that?
Let me review `btusb_close`. Aha, here it is:
```c
clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
clear_bit(BTUSB_BULK_RUNNING, &data->flags);
clear_bit(BTUSB_INTR_RUNNING, &data->flags);
clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
btusb_stop_traffic(data);
```
Right, `btusb_stop_traffic` kills all the URBs. Therefore, no more interrupts should come after that call, which is good. But...hang on a minute! The code calls `cancel_delayed_work(&data->rx_work)` *before* `btusb_stop_traffic(data)`. That's a potential race condition! If an interrupt happens between `cancel_delayed_work` and `btusb_stop_traffic`, it could schedule `rx_work` again! I need to go over `btusb_close` again to make sure I haven't missed anything.
|
| 25/2 |
2026/06/01 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_close]
Results: map[SourceCode:2047: static int btusb_close(struct hci_dev *hdev)
2048: {
2049: struct btusb_data *data = hci_get_drvdata(hdev);
2050: int err;
2051:
2052: BT_DBG("%s", hdev->name);
2053:
2054: cancel_delayed_work(&data->rx_work);
2055: cancel_work_sync(&data->work);
2056: cancel_work_sync(&data->waker);
2057:
2058: skb_queue_purge(&data->acl_q);
2059:
2060: clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2061: clear_bit(BTUSB_BULK_RUNNING, &data->flags);
2062: clear_bit(BTUSB_INTR_RUNNING, &data->flags);
2063: clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
2064:
2065: btusb_stop_traffic(data);
2066: btusb_free_frags(data);
2067:
2068: err = usb_autopm_get_interface(data->intf);
2069: if (err < 0)
2070: goto failed;
2071:
2072: data->intf->needs_remote_wakeup = 0;
2073:
2074: /* Enable remote wake up for auto-suspend */
2075: if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags))
2076: data->intf->needs_remote_wakeup = 1;
2077:
2078: usb_autopm_put_interface(data->intf);
2079:
2080: failed:
2081: usb_scuttle_anchored_urbs(&data->deferred);
2082: return 0;
2083: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 26/2 |
2026/06/01 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 31062
output: 38
thoughts: 107
Thoughts: **Analyzing the Race Condition in btusb Shutdown**
Okay, so I'm digging into this `btusb` module and a potential race condition. My initial thought was, "Aha! `cancel_delayed_work` is called *before* `btusb_stop_traffic`." That rang alarm bells. If we switched that `cancel_delayed_work` to a `cancel_delayed_work_sync`, and an interrupt hits right after, we could inadvertently reschedule `rx_work`. That's a classic concurrency problem. The interrupt can occur even during shutdown, causing the rx_work to still be scheduled on the CPU, and then to contend with further cleanup that occurs during the later stages of shutdown.
So, I was thinking, the fix seems obvious: `cancel_delayed_work_sync` *must* be called *after* `btusb_stop_traffic(data)`. That seems logically sound, right? But then, hang on... `btusb_stop_traffic` is responsible for killing those URBs, doesn't it? That changes the game. I need to be absolutely certain of what happens in that function. Before I get any further, I need to go over the `btusb_stop_traffic` function and review the URB cleanup procedures. This is all about ensuring the right order of operations, preventing dangling references, and making sure we don't end up in an unrecoverable state. I'll check `btusb_stop_traffic` to see if my assumption is correct.
|
| 27/2 |
2026/06/01 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_stop_traffic]
Results: map[SourceCode:2038: static void btusb_stop_traffic(struct btusb_data *data)
2039: {
2040: usb_kill_anchored_urbs(&data->intr_anchor);
2041: usb_kill_anchored_urbs(&data->bulk_anchor);
2042: usb_kill_anchored_urbs(&data->isoc_anchor);
2043: usb_kill_anchored_urbs(&data->diag_anchor);
2044: usb_kill_anchored_urbs(&data->ctrl_anchor);
2045: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 28/2 |
2026/06/01 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 31711
output: 38
thoughts: 1265
Thoughts: **UAF Vulnerability in btusb Driver: Analysis and Implications**
Okay, let's break this down. My initial thought process was: `usb_kill_anchored_urbs` ensures all URBs are complete, preventing resubmission. Therefore, after `btusb_stop_traffic`, no more completion handlers will be active. Thus, `cancel_delayed_work_sync(&data->rx_work)` *should* be called after `btusb_stop_traffic` to ensure we don't have a race condition with the `rx_work` scheduled by the interrupt or bulk endpoints.
But then I had to account for `btusb_disconnect` calling `hci_unregister_dev(hdev)`. Does `hci_unregister_dev` call `btusb_close`? Yes, it does. But, what if `btusb_disconnect` is called when the device is already "closed"? In that case, `btusb_close` might not get called by `hci_unregister_dev`, and more importantly, `btusb_stop_traffic` would've already been called in a pre-existing close (like via `hciconfig`). And if the device is already closed, then `rx_work` should not be running.
However, the scenario arises: `rx_work` is scheduled *before* the device closes. `btusb_close` will indeed call `cancel_delayed_work(&data->rx_work)`. If `rx_work` is still running, it continues execution. The device closes, and `btusb_close` finishes. Then, and this is critical, `btusb_disconnect` gets called immediately (e.g., if the device is physically unplugged). If `rx_work` *was* still running when the device was unplugged, `btusb_disconnect` is called and `data` is about to be freed, but `rx_work` is going to touch freed memory.
Therefore, the fix is either to add `cancel_delayed_work_sync(&data->rx_work)` to `btusb_disconnect` *before* the `kfree`, or to change `cancel_delayed_work` to `cancel_delayed_work_sync` and move it *after* the `btusb_stop_traffic` call. Let's make sure there aren't other places `data` is freed.
Checked `btusb_probe` and it frees `data` on error, but `rx_work` hasn't been scheduled yet. So, `btusb_disconnect` is the only place. In the `btusb_disconnect` function: `hci_unregister_dev(hdev); ... hci_free_dev(hdev); kfree(data);`. Adding `cancel_delayed_work_sync(&data->rx_work)` before `kfree(data)` will perfectly prevent the UAF. It seems like the bug is *precisely* that `rx_work` can be running when `data` is freed.
Now, let's categorize this. This is *exploitable*. The UAF is on a 4K slab object (`struct btusb_data`), containing function pointers (like `recv_acl`, `recv_event`, and spinlocks). An attacker could overwrite these pointers and trigger them via `btusb_rx_work`. This could result in a Denial of Service. It's *not* accessible from unprivileged processes, user namespaces, or any remote triggers. It's a *Peripheral Trigger* - it's triggered by physically unplugging the device.
Now, could an unprivileged user exploit this? Can they trigger a disconnect by default? Nope, an unprivileged user cannot unbind drivers or reset USB devices. Can they trigger `btusb_close`? No, because that requires `hciconfig hci0 down` which requires `CAP_NET_ADMIN`. Only physically unplugging the device, or by having root privileges to unbind the driver or bring the interface down, will cause this UAF.
If `hciconfig hci0 down` *is* called, `btusb_close` is executed. If `rx_work` is running, `cancel_delayed_work` returns false. And then `btusb_close` finishes, but does `data` get freed there? No, `data` is only freed in `btusb_disconnect`. So, `hciconfig hci0 down` *alone* does *not* cause a UAF! It *only* happens when `btusb_disconnect` is called. It *strictly* requires a USB disconnect and is thus a Peripheral Trigger.
Finally, to be sure, can `data->rx_work` be scheduled by anything else? Yes, in `btusb_recv_event` and `btusb_
|
| 29/2 |
2026/06/01 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_recv_intr]
Results: map[SourceCode:1239: static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
1240: {
1241: struct sk_buff *skb;
1242: unsigned long flags;
1243: int err = 0;
1244:
1245: spin_lock_irqsave(&data->rxlock, flags);
1246: skb = data->evt_skb;
1247:
1248: while (count) {
1249: int len;
1250:
1251: if (!skb) {
1252: skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
1253: if (!skb) {
1254: err = -ENOMEM;
1255: break;
1256: }
1257:
1258: hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
1259: hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE;
1260: }
1261:
1262: len = min_t(uint, hci_skb_expect(skb), count);
1263: skb_put_data(skb, buffer, len);
1264:
1265: count -= len;
1266: buffer += len;
1267: hci_skb_expect(skb) -= len;
1268:
1269: if (skb->len == HCI_EVENT_HDR_SIZE) {
1270: /* Complete event header */
1271: hci_skb_expect(skb) = hci_event_hdr(skb)->plen;
1272:
1273: if (skb_tailroom(skb) < hci_skb_expect(skb)) {
1274: kfree_skb(skb);
1275: skb = NULL;
1276:
1277: err = -EILSEQ;
1278: break;
1279: }
1280: }
1281:
1282: if (!hci_skb_expect(skb)) {
1283: /* Each chunk should correspond to at least 1 or more
1284: * events so if there are still bytes left that doesn't
1285: * constitute a new event this is likely a bug in the
1286: * controller.
1287: */
1288: if (count && count < HCI_EVENT_HDR_SIZE) {
1289: bt_dev_warn(data->hdev,
1290: "Unexpected continuation: %d bytes",
1291: count);
1292: count = 0;
1293: }
1294:
1295: /* Complete frame */
1296: btusb_recv_event(data, skb);
1297: skb = NULL;
1298: }
1299: }
1300:
1301: data->evt_skb = skb;
1302: spin_unlock_irqrestore(&data->rxlock, flags);
1303:
1304: return err;
1305: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 30/2 |
2026/06/01 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 34996
output: 38
thoughts: 21
Thoughts: Here's my understanding of the thought process, summarized as you requested:
**Deconstructing the Interrupt Handling Flow in btusb**
Okay, so I'm digging into this `btusb` code again. I need to understand how these interrupts are handled, and it looks like `btusb_recv_intr` is called from `btusb_intr_complete`. This is important because it means the interrupt completion routine directly triggers the reception of data from the interrupt endpoint. So, the interrupt *completes*, then the function to *receive* is called. Makes sense. It's the standard way of handling such things. Gotta keep this relationship in mind while troubleshooting. The interrupt completion is the cue to start receiving. I'll need to double-check that this ordering is consistent across all potential interrupt scenarios.
|
| 31/2 |
2026/06/01 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_intr_complete]
Results: map[SourceCode:1466: static void btusb_intr_complete(struct urb *urb)
1467: {
1468: struct hci_dev *hdev = urb->context;
1469: struct btusb_data *data = hci_get_drvdata(hdev);
1470: int err;
1471:
1472: BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1473: urb->actual_length);
1474:
1475: if (!test_bit(HCI_RUNNING, &hdev->flags))
1476: return;
1477:
1478: if (urb->status == 0) {
1479: hdev->stat.byte_rx += urb->actual_length;
1480:
1481: if (btusb_recv_intr(data, urb->transfer_buffer,
1482: urb->actual_length) < 0) {
1483: bt_dev_err(hdev, "corrupted event packet");
1484: hdev->stat.err_rx++;
1485: }
1486: } else if (urb->status == -ENOENT) {
1487: /* Avoid suspend failed when usb_kill_urb */
1488: return;
1489: }
1490:
1491: if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
1492: return;
1493:
1494: usb_mark_last_busy(data->udev);
1495: usb_anchor_urb(urb, &data->intr_anchor);
1496:
1497: err = usb_submit_urb(urb, GFP_ATOMIC);
1498: if (err < 0) {
1499: /* -EPERM: urb is being killed;
1500: * -ENODEV: device got disconnected
1501: */
1502: if (err != -EPERM && err != -ENODEV)
1503: bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1504: urb, -err);
1505: if (err != -EPERM)
1506: hci_cmd_sync_cancel(hdev, -err);
1507: usb_unanchor_urb(urb);
1508: }
1509: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 32/2 |
2026/06/01 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 35939
output: 40
thoughts: 1056
Thoughts: **Analysis of the btusb UAF Vulnerability**
Okay, so here's the breakdown of this btusb UAF vulnerability as I understand it. The core issue revolves around a classic race condition triggered by a USB device disconnect. My thinking goes something like this:
First, I see that the code has a few checks for `urb->status`, handling `-ENOENT` and `-ESHUTDOWN` differently. The key is that `rx_work` isn't always scheduled on disconnect, which is important. This is crucial because it means `rx_work` might be *already* scheduled when the disconnect happens. `btusb_close` uses `cancel_delayed_work` which doesn't wait for completion. Then, the `btusb_disconnect` frees `data`, and now `rx_work` is free to access freed memory, *boom* UAF.
Specifically, the bug manifests when: `rx_work` is scheduled; then the USB device is unplugged; then `btusb_disconnect` is called which in turn calls `btusb_close` which cancels the scheduled `rx_work` without waiting; and then `btusb_disconnect` frees the `data` which has the relevant memory.
This is a peripheral trigger, requiring a physical device to be plugged and then unplugged while `rx_work` is running.
Now, let's explore trigger mechanisms. Can an unprivileged user exploit this? The `unbind` interface looks promising. I think: Can I trigger `btusb_disconnect` via `echo "1-1:1.0" > /sys/bus/usb/drivers/btusb/unbind`? Yes, but root is required, which eliminates this as an unprivileged vector.
What about user namespaces? I know that, no, users in a namespace can't unbind a USB driver. USB devices are not namespaced and the `/sys/bus/usb/drivers/btusb/unbind` file is owned by root.
Now, let's consider a VM guest trigger. If a VM guest has a virtual USB controller, can it be plugged/unplugged to cause the race? But wait, this would be triggering the bug *in the guest kernel*, not the host. The question is aimed at the host. Since `btusb` is a USB driver, it isn't part of the standard paravirtualized feature set like virtio-blk or virtio-net. If the host passes through a USB device to the guest, the host doesn't run `btusb` for it. If the host runs `btusb`, the guest has no control. So, that's not it.
What about a confidential computing scenario? Can the host trigger this in a confidential VM? The host *could* emulate a USB device and plug/unplug it. But, again, `btusb` isn't a typical paravirtualized feature, so the focus is more on the host's ability to emulate the hardware. While a confidential VM could *hypothetically* use USB, it's not the normal setup and the host already has a lot of control in such a scenario. I'll mark this as false because it's not a standard paravirtualized feature.
No on Malicious Filesystem, Network, or other remote triggers.
Could a remote Bluetooth device trigger a disconnect that way? I think: A remote Bluetooth device *can* schedule `rx_work`. But, can it also *cause* a disconnect? I need to check the error handling paths. Does an error in `btusb_recv_intr` or `btusb_recv_acl` or some other function reset the device? No, it just drops the packet or increments counters. I'll need to dig deeper into the code to check error paths.
|
| 33/2 |
2026/06/01 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/btusb.c Name:btusb_rtl_hw_error]
Results: map[SourceCode:1147: static void btusb_rtl_hw_error(struct hci_dev *hdev, u8 code)
1148: {
1149: struct rtk_dev_coredump_hdr hdr = {
1150: .type = RTK_DEVCOREDUMP_CODE_HW_ERR,
1151: .code = code,
1152: };
1153:
1154: bt_dev_err(hdev, "RTL: hw err, trigger devcoredump (%d)", code);
1155:
1156: btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0);
1157: }
SourceFile:drivers/bluetooth/btusb.c]
|
| 34/2 |
2026/06/01 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 38057
output: 66
thoughts: 575
Thoughts: **My Analysis of This Bluetooth Use-After-Free Vulnerability**
Okay, so I'm looking at this and my initial thought is, it looks like this is triggering a kernel panic, a devcoredump specifically. Let's see if we can trace this, let's look for how `hci_reset_dev` or something similar is called anywhere? No, it looks like `btusb_disconnect` is only called by the USB core when a device is physically unplugged or unbound. That rules out any remote trigger from a Bluetooth connection.
Right, time to re-evaluate the attack surface. So, is it exploitable? Yes, definitely. Denial of service? Absolutely. Unprivileged processes? No, it requires more permissions. User namespaces? Nope. Can it be triggered in a VM guest? No. Host in the Confidential Computing Context? No again. Ethernet network trigger? Negative. Other Remote trigger? Doesn't seem so. Peripheral trigger? Bingo. Malicious filesystem trigger? No.
Alright, let's break this down. The core issue is this use-after-free in `btusb_rx_work`. The `btusb_data` struct is allocated when the device is probed, and then freed in `btusb_disconnect`. So, `btusb_rx_work` is a delayed work item that accesses `btusb_data`. The device is disconnected, then `btusb_disconnect` is called, which calls `hci_unregister_dev`. This leads to `btusb_close` which calls `cancel_delayed_work(&data->rx_work)`. Here's the kicker: `cancel_delayed_work` doesn't wait for the work to finish if it's already running.
So, `btusb_close` returns, but then `btusb_disconnect` goes ahead and frees that `data` struct via `kfree(data)`. If `btusb_rx_work` is still running, it's accessing this already freed memory. Boom, use-after-free.
This freed object is a 4K slab, a kmalloc-4k, and it contains things like function pointers, which are critical, like `data->recv_acl`, and spinlocks. An attacker can really abuse this by heap spraying after the object is freed, overwriting those function pointers with controlled data. This then opens the door to arbitrary code execution when `btusb_rx_work` calls `data->recv_acl(data->hdev, skb)`.
The trigger is interesting. The attacker needs to plug in a malicious Bluetooth USB device, send events to schedule `rx_work`, and then unplug the device at the right time to cause that race condition. It's a peripheral trigger because it needs physical access to plug and unplug the USB device. So, unprivileged users can't trigger this without physical access because they can't unbind USB drivers or reset USB devices via sysfs. This is not remotely exploitable, a remote Bluetooth device cannot force a USB disconnect.
|
| 35/2 |
2026/06/01 15:05 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 36/2 |
2026/06/01 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 39403
output: 711
thoughts: 107
Thoughts: **Final Assessment & Vulnerability Summary**
Okay, here's the definitive rundown. The analysis is complete, and the response is ready. The reasoning holds; I've covered all the key angles.
The bottom line is: this is exploitable. We're looking at a User-After-Free vulnerability within a struct containing function pointers. It has the potential to cause a denial-of-service condition β a full kernel crash.
However, exploitation isn't trivial. It's not an unprivileged attack; root or physical access would be required. Itβs not a UserNamespace bypass, either. No VMGuest, VMHost, Network, or Remote triggering is possible. The only trigger vector I've been able to confirm is PeripheralTrigger. FilesystemTrigger is not possible.
|
| 37/1 |
2026/06/01 15:05 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis:**
The bug is a Use-After-Free (UAF) in the Bluetooth USB driver (`btusb`).
1. **Root Cause:**
The `btusb_data` structure is allocated in `btusb_probe()` and freed in
`btusb_disconnect()`. The driver uses a delayed work item, `rx_work`, to process
incoming Bluetooth packets.
When the USB device is disconnected or the driver is unbound,
`btusb_disconnect()` is invoked. This function calls `hci_unregister_dev()`,
which eventually calls the driver's `btusb_close()` callback.
Inside `btusb_close()`, the driver attempts to cancel the delayed work using
`cancel_delayed_work(&data->rx_work)`. However, `cancel_delayed_work()` only
cancels the timer; if the work item is already executing on a CPU, it does not
wait for it to finish (unlike `cancel_delayed_work_sync()`).
After `btusb_close()` returns, `btusb_disconnect()` proceeds to free the
`btusb_data` structure via `kfree(data)`. If `btusb_rx_work()` is still running
concurrently, it will access the freed `data` object (e.g., `data->acl_q`),
resulting in a Use-After-Free.
2. **Exploitability:**
This bug is highly **Exploitable**. The freed `btusb_data` object is allocated
in the `kmalloc-4k` slab cache. It contains several function pointers (such as
`data->recv_acl`, `data->recv_event`, etc.) and spinlocks. An attacker can
exploit this by spraying the heap with controlled data immediately after the
object is freed. If the attacker successfully overwrites the `recv_acl` function
pointer, they can achieve arbitrary kernel code execution when the still-running
`btusb_rx_work()` executes `data->recv_acl(data->hdev, skb)`.
3. **Trigger Mechanism:**
To trigger this bug, an attacker needs to schedule the `rx_work` (e.g., by
sending Bluetooth events/ACL data from the device) and then abruptly disconnect
the device while the work is executing.
- **Peripheral Trigger:** Yes. An attacker with physical access can plug in a
malicious or standard USB Bluetooth dongle and unplug it at the right time to
win the race condition.
- **Unprivileged / User Namespace:** No. Unprivileged users cannot trigger this
bug purely from software. They lack the permissions to unbind USB drivers via
sysfs (`/sys/bus/usb/drivers/btusb/unbind` is root-only) or to emulate USB
devices via `dummy_hcd` (which requires root/specific capabilities not granted
in user namespaces).
- **Remote Trigger:** No. A remote Bluetooth device can send packets to schedule
the work, but it cannot force the host's USB subsystem to disconnect the device,
which is strictly required to free the object and trigger the UAF.
**Conclusion:**
This is a classic race condition on device disconnect leading to a highly
exploitable Use-After-Free. It poses a severe security risk (Privilege
Escalation and Denial of Service) but is constrained by the requirement of
physical access to plug and unplug a USB device (Peripheral Trigger).]
|