| 0/0 |
2026/05/31 09:26 |
flow |
assessment-security |
59m
Results: map[DenialOfService:false Explanation:**Analysis:**
The bug report indicates a hung task in `hci_dev_open`, specifically blocked at
`flush_workqueue(hdev->req_workqueue)`. This happens when a thread waits for all
currently executing and queued work items on the Bluetooth device's
`req_workqueue` to finish.
By examining the source code, we can see that `hci_dev_open` is only called from
two places in the kernel:
1. `hci_sock_ioctl` when handling the `HCIDEVUP` command.
2. `hci_sock_bind` when binding a socket to `HCI_CHANNEL_USER`.
In both cases, the kernel explicitly checks for the `CAP_NET_ADMIN` capability
in the initial user namespace using `capable(CAP_NET_ADMIN)`:
```c
// In hci_sock_ioctl:
case HCIDEVUP:
if (!capable(CAP_NET_ADMIN))
return -EPERM;
return hci_dev_open(arg);
// In hci_sock_bind:
case HCI_CHANNEL_USER:
...
if (!capable(CAP_NET_ADMIN)) {
err = -EPERM;
goto done;
}
...
err = hci_dev_open(hdev->id);
```
Because `capable()` checks the init namespace (unlike `ns_capable()`), these
operations are strictly inaccessible to unprivileged users, even if they create
a new user namespace.
The hung task itself is caused by the `req_workqueue` being busy for an extended
period (e.g., > 120 seconds). This can be artificially triggered by a root user
(like the syzkaller fuzzer) by creating a virtual Bluetooth device (`vhci`) and
either not reading from its character device or queuing many operations (like
`add_device` or `set_powered` via the `mgmt` interface) that end up timing out
sequentially (each HCI command timeout is typically 2 seconds). When the root
user subsequently calls `HCIDEVUP`, the `flush_workqueue` call blocks until all
those timeouts expire, triggering the kernel's hung task watchdog.
A malicious physical Bluetooth peripheral could intentionally ignore
initialization commands to delay its own `hci_power_on` work item (which runs on
`req_workqueue`). However, this would only block the workqueue for that specific
device. It would not cause a system-wide denial of service or hang system
daemons, because standard daemons (like `bluetoothd`) use the asynchronous
`mgmt` interface (e.g., `MGMT_OP_SET_POWERED`), which queues work but does not
call `flush_workqueue`. The hang only occurs if a privileged process explicitly
invokes the legacy `HCIDEVUP` ioctl or binds a `HCI_CHANNEL_USER` socket while
the workqueue is stalled.
**Conclusion:**
Since triggering the bug requires global `CAP_NET_ADMIN` privileges to both
stall the workqueue and invoke the blocking `hci_dev_open` path, it crosses no
privilege boundaries. It is not accessible to unprivileged users, user
namespaces, or remote attackers, and a malicious peripheral cannot force a
privileged process to execute the blocking code path. Therefore, this bug has no
security impact. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/31 09:26 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
uint64_t r[2] = {0xffffffffffffffff, 0x0};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// socket arguments: [
// domain: socket_domain = 0x10 (8 bytes)
// type: socket_type = 0x3 (8 bytes)
// proto: int32 = 0x0 (4 bytes)
// ]
// returns sock
res = syscall(__NR_socket, /*domain=AF_NETLINK*/0x10ul, /*type=SOCK_RAW*/3ul, /*proto=*/0);
if (res != -1)
r[0] = res;
// ioctl$sock_SIOCGIFINDEX arguments: [
// fd: sock (resource)
// cmd: const = 0x8933 (4 bytes)
// arg: ptr[out, ifreq_dev_t[devnames, ifindex]] {
// ifreq_dev_t[devnames, ifindex] {
// ifr_ifrn: buffer: {6c 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// elem: ifindex (resource)
// pad = 0x0 (20 bytes)
// }
// }
// ]
memcpy((void*)0x200000000240, "lo\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16);
res = syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x8933, /*arg=*/0x200000000240ul);
if (res != -1)
r[1] = *(uint32_t*)0x200000000250;
// sendmsg$nl_route_sched arguments: [
// fd: sock_nl_route (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_route_sched]] {
// msghdr_netlink[netlink_msg_route_sched] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_route_sched]] {
// iovec[in, netlink_msg_route_sched] {
// addr: ptr[in, netlink_msg_route_sched] {
// union netlink_msg_route_sched {
// newqdisc: netlink_msg_t[const[RTM_NEWQDISC, int16], tcmsg[AF_UNSPEC], rtm_tca_policy] {
// len: len = 0x15c (4 bytes)
// type: const = 0x24 (2 bytes)
// flags: netlink_msg_flags = 0xd0f (2 bytes)
// seq: int32 = 0x0 (4 bytes)
// pid: int32 = 0x0 (4 bytes)
// payload: tcmsg[AF_UNSPEC] {
// family: const = 0x60 (1 bytes)
// tcm__pad1: const = 0x0 (1 bytes)
// tcm__pad2: const = 0x0 (2 bytes)
// ifindex: ifindex (resource)
// tcm_handle: tcm_handle {
// minor: tcm_handle_offsets = 0x0 (2 bytes)
// major: tcm_handle_offsets = 0x0 (2 bytes)
// }
// tcm_parent: tcm_handle {
// minor: tcm_handle_offsets = 0xffff (2 bytes)
// major: tcm_handle_offsets = 0xffff (2 bytes)
// }
// tcm_info: tcm_handle {
// minor: tcm_handle_offsets = 0x0 (2 bytes)
// major: tcm_handle_offsets = 0x0 (2 bytes)
// }
// }
// attrs: array[rtm_tca_policy] {
// union rtm_tca_policy {
// qdisc_kind_options: union qdisc_kind_options {
// q_cake: tca_kind_options_t["cake", array[cake_policy]] {
// TCA_KIND: nlattr_t[const[TCA_KIND, int16], string["cake"]] {
// nla_len: offsetof = 0x9 (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: buffer: {63 61 6b 65 00} (length 0x5)
// size: buffer: {} (length 0x0)
// pad = 0x0 (3 bytes)
// }
// TCA_OPTIONS: nlattr_t[const[TCA_OPTIONS, int16], array[cake_policy]] {
// nla_len: offsetof = 0x14 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[cake_policy] {
// union cake_policy {
// TCA_CAKE_DIFFSERV_MODE: nlattr_t[const[TCA_CAKE_DIFFSERV_MODE, int16], flags[tc_cake_diffserv_mode, int32]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x3 (2 bytes)
// payload: tc_cake_diffserv_mode = 0x1 (4 bytes)
// size: buffer: {} (length 0x0)
// }
// }
// union cake_policy {
// TCA_CAKE_RTT: nlattr_t[const[TCA_CAKE_RTT, int16], int32] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x7 (2 bytes)
// payload: int32 = 0x401 (4 bytes)
// size: buffer: {} (length 0x0)
// }
// }
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// }
// union rtm_tca_policy {
// TCA_STAB: nlattr_tt[const[TCA_STAB, int16:14], 0, 1, array[stab_policy]] {
// nla_len: offsetof = 0x118 (2 bytes)
// nla_type: const = 0x8 (1 bytes)
// NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes)
// NLA_F_NESTED: const = 0x1 (1 bytes)
// payload: array[stab_policy] {
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x0 (1 bytes)
// size_log: int8 = 0x2 (1 bytes)
// cell_align: int16 = 0x98b4 (2 bytes)
// overhead: int32 = 0x5 (4 bytes)
// linklayer: linklayer = 0x1 (4 bytes)
// mpu: int32 = 0x6 (4 bytes)
// mtu: int32 = 0x9 (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x5 (1 bytes)
// size_log: int8 = 0x80 (1 bytes)
// cell_align: int16 = 0x3 (2 bytes)
// overhead: int32 = 0x0 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0x80000001 (4 bytes)
// mtu: int32 = 0x1ff (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x1 (1 bytes)
// size_log: int8 = 0x1c (1 bytes)
// cell_align: int16 = 0x9 (2 bytes)
// overhead: int32 = 0x40000 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0x200 (4 bytes)
// mtu: int32 = 0x80000001 (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x51 (1 bytes)
// size_log: int8 = 0x4 (1 bytes)
// cell_align: int16 = 0x1000 (2 bytes)
// overhead: int32 = 0xfffffff8 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0x2 (4 bytes)
// mtu: int32 = 0x3 (4 bytes)
// tsize: len = 0x1 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x6 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0xdac (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x4 (1 bytes)
// size_log: int8 = 0x16 (1 bytes)
// cell_align: int16 = 0x8 (2 bytes)
// overhead: int32 = 0x0 (4 bytes)
// linklayer: linklayer = 0x1 (4 bytes)
// mpu: int32 = 0x401 (4 bytes)
// mtu: int32 = 0x4 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x40 (2 bytes)
// int16 = 0x9 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x3 (1 bytes)
// size_log: int8 = 0x11 (1 bytes)
// cell_align: int16 = 0x40ba (2 bytes)
// overhead: int32 = 0x8 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0x9 (4 bytes)
// mtu: int32 = 0x2 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x1 (2 bytes)
// int16 = 0x1 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0xc (1 bytes)
// size_log: int8 = 0x1 (1 bytes)
// cell_align: int16 = 0x7 (2 bytes)
// overhead: int32 = 0x7 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0xb (4 bytes)
// mtu: int32 = 0xbb (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x7 (2 bytes)
// int16 = 0x5 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x1 (1 bytes)
// size_log: int8 = 0x0 (1 bytes)
// cell_align: int16 = 0x3 (2 bytes)
// overhead: int32 = 0x26c99bf7 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0xffff8262 (4 bytes)
// mtu: int32 = 0x8001 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x4 (2 bytes)
// int16 = 0x1a73 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// len: len = 0x15c (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x40 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000000 = 0;
*(uint32_t*)0x200000000008 = 0;
*(uint64_t*)0x200000000010 = 0x200000000780;
*(uint64_t*)0x200000000780 = 0x200000009040;
*(uint32_t*)0x200000009040 = 0x15c;
*(uint16_t*)0x200000009044 = 0x24;
*(uint16_t*)0x200000009046 = 0xd0f;
*(uint32_t*)0x200000009048 = 0;
*(uint32_t*)0x20000000904c = 0;
*(uint8_t*)0x200000009050 = 0x60;
*(uint8_t*)0x200000009051 = 0;
*(uint16_t*)0x200000009052 = 0;
*(uint32_t*)0x200000009054 = r[1];
*(uint16_t*)0x200000009058 = 0;
*(uint16_t*)0x20000000905a = 0;
*(uint16_t*)0x20000000905c = -1;
*(uint16_t*)0x20000000905e = -1;
*(uint16_t*)0x200000009060 = 0;
*(uint16_t*)0x200000009062 = 0;
*(uint16_t*)0x200000009064 = 9;
*(uint16_t*)0x200000009066 = 1;
memcpy((void*)0x200000009068, "cake\000", 5);
*(uint16_t*)0x200000009070 = 0x14;
*(uint16_t*)0x200000009072 = 2;
*(uint16_t*)0x200000009074 = 8;
*(uint16_t*)0x200000009076 = 3;
*(uint32_t*)0x200000009078 = 1;
*(uint16_t*)0x20000000907c = 8;
*(uint16_t*)0x20000000907e = 7;
*(uint32_t*)0x200000009080 = 0x401;
*(uint16_t*)0x200000009084 = 0x118;
STORE_BY_BITMASK(uint16_t, , 0x200000009086, 8, 0, 14);
STORE_BY_BITMASK(uint16_t, , 0x200000009087, 0, 6, 1);
STORE_BY_BITMASK(uint16_t, , 0x200000009087, 1, 7, 1);
*(uint16_t*)0x200000009088 = 0x1c;
*(uint16_t*)0x20000000908a = 1;
*(uint8_t*)0x20000000908c = 0;
*(uint8_t*)0x20000000908d = 2;
*(uint16_t*)0x20000000908e = 0x98b4;
*(uint32_t*)0x200000009090 = 5;
*(uint32_t*)0x200000009094 = 1;
*(uint32_t*)0x200000009098 = 6;
*(uint32_t*)0x20000000909c = 9;
*(uint32_t*)0x2000000090a0 = 0;
*(uint16_t*)0x2000000090a4 = 4;
*(uint16_t*)0x2000000090a6 = 2;
*(uint16_t*)0x2000000090a8 = 0x1c;
*(uint16_t*)0x2000000090aa = 1;
*(uint8_t*)0x2000000090ac = 5;
*(uint8_t*)0x2000000090ad = 0x80;
*(uint16_t*)0x2000000090ae = 3;
*(uint32_t*)0x2000000090b0 = 0;
*(uint32_t*)0x2000000090b4 = 0;
*(uint32_t*)0x2000000090b8 = 0x80000001;
*(uint32_t*)0x2000000090bc = 0x1ff;
*(uint32_t*)0x2000000090c0 = 0;
*(uint16_t*)0x2000000090c4 = 4;
*(uint16_t*)0x2000000090c6 = 2;
*(uint16_t*)0x2000000090c8 = 0x1c;
*(uint16_t*)0x2000000090ca = 1;
*(uint8_t*)0x2000000090cc = 1;
*(uint8_t*)0x2000000090cd = 0x1c;
*(uint16_t*)0x2000000090ce = 9;
*(uint32_t*)0x2000000090d0 = 0x40000;
*(uint32_t*)0x2000000090d4 = 2;
*(uint32_t*)0x2000000090d8 = 0x200;
*(uint32_t*)0x2000000090dc = 0x80000001;
*(uint32_t*)0x2000000090e0 = 0;
*(uint16_t*)0x2000000090e4 = 4;
*(uint16_t*)0x2000000090e6 = 2;
*(uint16_t*)0x2000000090e8 = 0x1c;
*(uint16_t*)0x2000000090ea = 1;
*(uint8_t*)0x2000000090ec = 0x51;
*(uint8_t*)0x2000000090ed = 4;
*(uint16_t*)0x2000000090ee = 0x1000;
*(uint32_t*)0x2000000090f0 = 0xfffffff8;
*(uint32_t*)0x2000000090f4 = 2;
*(uint32_t*)0x2000000090f8 = 2;
*(uint32_t*)0x2000000090fc = 3;
*(uint32_t*)0x200000009100 = 1;
*(uint16_t*)0x200000009104 = 6;
*(uint16_t*)0x200000009106 = 2;
*(uint16_t*)0x200000009108 = 0xdac;
*(uint16_t*)0x20000000910c = 0x1c;
*(uint16_t*)0x20000000910e = 1;
*(uint8_t*)0x200000009110 = 4;
*(uint8_t*)0x200000009111 = 0x16;
*(uint16_t*)0x200000009112 = 8;
*(uint32_t*)0x200000009114 = 0;
*(uint32_t*)0x200000009118 = 1;
*(uint32_t*)0x20000000911c = 0x401;
*(uint32_t*)0x200000009120 = 4;
*(uint32_t*)0x200000009124 = 2;
*(uint16_t*)0x200000009128 = 8;
*(uint16_t*)0x20000000912a = 2;
*(uint16_t*)0x20000000912c = 0x40;
*(uint16_t*)0x20000000912e = 9;
*(uint16_t*)0x200000009130 = 0x1c;
*(uint16_t*)0x200000009132 = 1;
*(uint8_t*)0x200000009134 = 3;
*(uint8_t*)0x200000009135 = 0x11;
*(uint16_t*)0x200000009136 = 0x40ba;
*(uint32_t*)0x200000009138 = 8;
*(uint32_t*)0x20000000913c = 0;
*(uint32_t*)0x200000009140 = 9;
*(uint32_t*)0x200000009144 = 2;
*(uint32_t*)0x200000009148 = 2;
*(uint16_t*)0x20000000914c = 8;
*(uint16_t*)0x20000000914e = 2;
*(uint16_t*)0x200000009150 = 1;
*(uint16_t*)0x200000009152 = 1;
*(uint16_t*)0x200000009154 = 0x1c;
*(uint16_t*)0x200000009156 = 1;
*(uint8_t*)0x200000009158 = 0xc;
*(uint8_t*)0x200000009159 = 1;
*(uint16_t*)0x20000000915a = 7;
*(uint32_t*)0x20000000915c = 7;
*(uint32_t*)0x200000009160 = 0;
*(uint32_t*)0x200000009164 = 0xb;
*(uint32_t*)0x200000009168 = 0xbb;
*(uint32_t*)0x20000000916c = 2;
*(uint16_t*)0x200000009170 = 8;
*(uint16_t*)0x200000009172 = 2;
*(uint16_t*)0x200000009174 = 7;
*(uint16_t*)0x200000009176 = 5;
*(uint16_t*)0x200000009178 = 0x1c;
*(uint16_t*)0x20000000917a = 1;
*(uint8_t*)0x20000000917c = 1;
*(uint8_t*)0x20000000917d = 0;
*(uint16_t*)0x20000000917e = 3;
*(uint32_t*)0x200000009180 = 0x26c99bf7;
*(uint32_t*)0x200000009184 = 2;
*(uint32_t*)0x200000009188 = 0xffff8262;
*(uint32_t*)0x20000000918c = 0x8001;
*(uint32_t*)0x200000009190 = 2;
*(uint16_t*)0x200000009194 = 8;
*(uint16_t*)0x200000009196 = 2;
*(uint16_t*)0x200000009198 = 4;
*(uint16_t*)0x20000000919a = 0x1a73;
*(uint64_t*)0x200000000788 = 0x15c;
*(uint64_t*)0x200000000018 = 1;
*(uint64_t*)0x200000000020 = 0;
*(uint64_t*)0x200000000028 = 0;
*(uint32_t*)0x200000000030 = 0x40;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000000ul, /*f=*/0ul);
return 0;
}
]
|
| 2/1 |
2026/05/31 09:26 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/5577f9bca9e8082fb6a56d78a9a4b18df6a1a69c]
|
| 3/1 |
2026/05/31 09:28 |
action |
kernel-builder |
24m
Results: map[KernelObj:/app/workdir/cache/build/08903232766294828720facf29ee47f142d9e9fc]
|
| 4/1 |
2026/05/31 09:52 |
action |
codesearch-prepare |
22m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/31 10:15 |
agent |
expert |
10m
Model:
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false 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:
INFO: task syz-executor:6137 blocked for more than 152 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz-executor state:D stack:25432 pid:6137 tgid:6137 ppid:1 task_flags:0x400140 flags:0x00080000
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5256 [inline]
__schedule+0x14bc/0x5000 kernel/sched/core.c:6863
__schedule_loop kernel/sched/core.c:6945 [inline]
schedule+0x165/0x360 kernel/sched/core.c:6960
schedule_timeout+0x9a/0x270 kernel/time/sleep_timeout.c:75
do_wait_for_common kernel/sched/completion.c:100 [inline]
__wait_for_common kernel/sched/completion.c:121 [inline]
wait_for_common kernel/sched/completion.c:132 [inline]
wait_for_completion+0x2bf/0x5d0 kernel/sched/completion.c:153
__flush_workqueue+0x6f7/0x14b0 kernel/workqueue.c:4033
hci_dev_open+0x145/0x300 net/bluetooth/hci_core.c:474
sock_do_ioctl+0xdc/0x300 net/socket.c:1245
sock_ioctl+0x576/0x790 net/socket.c:1366
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
uint64_t r[2] = {0xffffffffffffffff, 0x0};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// socket arguments: [
// domain: socket_domain = 0x10 (8 bytes)
// type: socket_type = 0x3 (8 bytes)
// proto: int32 = 0x0 (4 bytes)
// ]
// returns sock
res = syscall(__NR_socket, /*domain=AF_NETLINK*/0x10ul, /*type=SOCK_RAW*/3ul, /*proto=*/0);
if (res != -1)
r[0] = res;
// ioctl$sock_SIOCGIFINDEX arguments: [
// fd: sock (resource)
// cmd: const = 0x8933 (4 bytes)
// arg: ptr[out, ifreq_dev_t[devnames, ifindex]] {
// ifreq_dev_t[devnames, ifindex] {
// ifr_ifrn: buffer: {6c 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// elem: ifindex (resource)
// pad = 0x0 (20 bytes)
// }
// }
// ]
memcpy((void*)0x200000000240, "lo\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16);
res = syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x8933, /*arg=*/0x200000000240ul);
if (res != -1)
r[1] = *(uint32_t*)0x200000000250;
// sendmsg$nl_route_sched arguments: [
// fd: sock_nl_route (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_route_sched]] {
// msghdr_netlink[netlink_msg_route_sched] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_route_sched]] {
// iovec[in, netlink_msg_route_sched] {
// addr: ptr[in, netlink_msg_route_sched] {
// union netlink_msg_route_sched {
// newqdisc: netlink_msg_t[const[RTM_NEWQDISC, int16], tcmsg[AF_UNSPEC], rtm_tca_policy] {
// len: len = 0x15c (4 bytes)
// type: const = 0x24 (2 bytes)
// flags: netlink_msg_flags = 0xd0f (2 bytes)
// seq: int32 = 0x0 (4 bytes)
// pid: int32 = 0x0 (4 bytes)
// payload: tcmsg[AF_UNSPEC] {
// family: const = 0x60 (1 bytes)
// tcm__pad1: const = 0x0 (1 bytes)
// tcm__pad2: const = 0x0 (2 bytes)
// ifindex: ifindex (resource)
// tcm_handle: tcm_handle {
// minor: tcm_handle_offsets = 0x0 (2 bytes)
// major: tcm_handle_offsets = 0x0 (2 bytes)
// }
// tcm_parent: tcm_handle {
// minor: tcm_handle_offsets = 0xffff (2 bytes)
// major: tcm_handle_offsets = 0xffff (2 bytes)
// }
// tcm_info: tcm_handle {
// minor: tcm_handle_offsets = 0x0 (2 bytes)
// major: tcm_handle_offsets = 0x0 (2 bytes)
// }
// }
// attrs: array[rtm_tca_policy] {
// union rtm_tca_policy {
// qdisc_kind_options: union qdisc_kind_options {
// q_cake: tca_kind_options_t["cake", array[cake_policy]] {
// TCA_KIND: nlattr_t[const[TCA_KIND, int16], string["cake"]] {
// nla_len: offsetof = 0x9 (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: buffer: {63 61 6b 65 00} (length 0x5)
// size: buffer: {} (length 0x0)
// pad = 0x0 (3 bytes)
// }
// TCA_OPTIONS: nlattr_t[const[TCA_OPTIONS, int16], array[cake_policy]] {
// nla_len: offsetof = 0x14 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[cake_policy] {
// union cake_policy {
// TCA_CAKE_DIFFSERV_MODE: nlattr_t[const[TCA_CAKE_DIFFSERV_MODE, int16], flags[tc_cake_diffserv_mode, int32]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x3 (2 bytes)
// payload: tc_cake_diffserv_mode = 0x1 (4 bytes)
// size: buffer: {} (length 0x0)
// }
// }
// union cake_policy {
// TCA_CAKE_RTT: nlattr_t[const[TCA_CAKE_RTT, int16], int32] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x7 (2 bytes)
// payload: int32 = 0x401 (4 bytes)
// size: buffer: {} (length 0x0)
// }
// }
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// }
// union rtm_tca_policy {
// TCA_STAB: nlattr_tt[const[TCA_STAB, int16:14], 0, 1, array[stab_policy]] {
// nla_len: offsetof = 0x118 (2 bytes)
// nla_type: const = 0x8 (1 bytes)
// NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes)
// NLA_F_NESTED: const = 0x1 (1 bytes)
// payload: array[stab_policy] {
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x0 (1 bytes)
// size_log: int8 = 0x2 (1 bytes)
// cell_align: int16 = 0x98b4 (2 bytes)
// overhead: int32 = 0x5 (4 bytes)
// linklayer: linklayer = 0x1 (4 bytes)
// mpu: int32 = 0x6 (4 bytes)
// mtu: int32 = 0x9 (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x5 (1 bytes)
// size_log: int8 = 0x80 (1 bytes)
// cell_align: int16 = 0x3 (2 bytes)
// overhead: int32 = 0x0 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0x80000001 (4 bytes)
// mtu: int32 = 0x1ff (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x1 (1 bytes)
// size_log: int8 = 0x1c (1 bytes)
// cell_align: int16 = 0x9 (2 bytes)
// overhead: int32 = 0x40000 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0x200 (4 bytes)
// mtu: int32 = 0x80000001 (4 bytes)
// tsize: len = 0x0 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x4 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x51 (1 bytes)
// size_log: int8 = 0x4 (1 bytes)
// cell_align: int16 = 0x1000 (2 bytes)
// overhead: int32 = 0xfffffff8 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0x2 (4 bytes)
// mtu: int32 = 0x3 (4 bytes)
// tsize: len = 0x1 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x6 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0xdac (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x4 (1 bytes)
// size_log: int8 = 0x16 (1 bytes)
// cell_align: int16 = 0x8 (2 bytes)
// overhead: int32 = 0x0 (4 bytes)
// linklayer: linklayer = 0x1 (4 bytes)
// mpu: int32 = 0x401 (4 bytes)
// mtu: int32 = 0x4 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x40 (2 bytes)
// int16 = 0x9 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x3 (1 bytes)
// size_log: int8 = 0x11 (1 bytes)
// cell_align: int16 = 0x40ba (2 bytes)
// overhead: int32 = 0x8 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0x9 (4 bytes)
// mtu: int32 = 0x2 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x1 (2 bytes)
// int16 = 0x1 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0xc (1 bytes)
// size_log: int8 = 0x1 (1 bytes)
// cell_align: int16 = 0x7 (2 bytes)
// overhead: int32 = 0x7 (4 bytes)
// linklayer: linklayer = 0x0 (4 bytes)
// mpu: int32 = 0xb (4 bytes)
// mtu: int32 = 0xbb (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x7 (2 bytes)
// int16 = 0x5 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// stab_policy {
// TCA_STAB_BASE: nlattr_t[const[TCA_STAB_BASE, int16], tc_sizespec] {
// nla_len: offsetof = 0x1c (2 bytes)
// nla_type: const = 0x1 (2 bytes)
// payload: tc_sizespec {
// cell_log: int8 = 0x1 (1 bytes)
// size_log: int8 = 0x0 (1 bytes)
// cell_align: int16 = 0x3 (2 bytes)
// overhead: int32 = 0x26c99bf7 (4 bytes)
// linklayer: linklayer = 0x2 (4 bytes)
// mpu: int32 = 0xffff8262 (4 bytes)
// mtu: int32 = 0x8001 (4 bytes)
// tsize: len = 0x2 (4 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// TCA_STAB_DATA: nlattr_t[const[TCA_STAB_DATA, int16], array[int16]] {
// nla_len: offsetof = 0x8 (2 bytes)
// nla_type: const = 0x2 (2 bytes)
// payload: array[int16] {
// int16 = 0x4 (2 bytes)
// int16 = 0x1a73 (2 bytes)
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// size: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// len: len = 0x15c (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x40 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000000 = 0;
*(uint32_t*)0x200000000008 = 0;
*(uint64_t*)0x200000000010 = 0x200000000780;
*(uint64_t*)0x200000000780 = 0x200000009040;
*(uint32_t*)0x200000009040 = 0x15c;
*(uint16_t*)0x200000009044 = 0x24;
*(uint16_t*)0x200000009046 = 0xd0f;
*(uint32_t*)0x200000009048 = 0;
*(uint32_t*)0x20000000904c = 0;
*(uint8_t*)0x200000009050 = 0x60;
*(uint8_t*)0x200000009051 = 0;
*(uint16_t*)0x200000009052 = 0;
*(uint32_t*)0x200000009054 = r[1];
*(uint16_t*)0x200000009058 = 0;
*(uint16_t*)0x20000000905a = 0;
*(uint16_t*)0x20000000905c = -1;
*(uint16_t*)0x20000000905e = -1;
*(uint16_t*)0x200000009060 = 0;
*(uint16_t*)0x200000009062 = 0;
*(uint16_t*)0x200000009064 = 9;
*(uint16_t*)0x200000009066 = 1;
memcpy((void*)0x200000009068, "cake\000", 5);
*(uint16_t*)0x200000009070 = 0x14;
*(uint16_t*)0x200000009072 = 2;
*(uint16_t*)0x200000009074 = 8;
*(uint16_t*)0x200000009076 = 3;
*(uint32_t*)0x200000009078 = 1;
*(uint16_t*)0x20000000907c = 8;
*(uint16_t*)0x20000000907e = 7;
*(uint32_t*)0x200000009080 = 0x401;
*(uint16_t*)0x200000009084 = 0x118;
STORE_BY_BITMASK(uint16_t, , 0x200000009086, 8, 0, 14);
STORE_BY_BITMASK(uint16_t, , 0x200000009087, 0, 6, 1);
STORE_BY_BITMASK(uint16_t, , 0x200000009087, 1, 7, 1);
*(uint16_t*)0x200000009088 = 0x1c;
*(uint16_t*)0x20000000908a = 1;
*(uint8_t*)0x20000000908c = 0;
*(uint8_t*)0x20000000908d = 2;
*(uint16_t*)0x20000000908e = 0x98b4;
*(uint32_t*)0x200000009090 = 5;
*(uint32_t*)0x200000009094 = 1;
*(uint32_t*)0x200000009098 = 6;
*(uint32_t*)0x20000000909c = 9;
*(uint32_t*)0x2000000090a0 = 0;
*(uint16_t*)0x2000000090a4 = 4;
*(uint16_t*)0x2000000090a6 = 2;
*(uint16_t*)0x2000000090a8 = 0x1c;
*(uint16_t*)0x2000000090aa = 1;
*(uint8_t*)0x2000000090ac = 5;
*(uint8_t*)0x2000000090ad = 0x80;
*(uint16_t*)0x2000000090ae = 3;
*(uint32_t*)0x2000000090b0 = 0;
*(uint32_t*)0x2000000090b4 = 0;
*(uint32_t*)0x2000000090b8 = 0x80000001;
*(uint32_t*)0x2000000090bc = 0x1ff;
*(uint32_t*)0x2000000090c0 = 0;
*(uint16_t*)0x2000000090c4 = 4;
*(uint16_t*)0x2000000090c6 = 2;
*(uint16_t*)0x2000000090c8 = 0x1c;
*(uint16_t*)0x2000000090ca = 1;
*(uint8_t*)0x2000000090cc = 1;
*(uint8_t*)0x2000000090cd = 0x1c;
*(uint16_t*)0x2000000090ce = 9;
*(uint32_t*)0x2000000090d0 = 0x40000;
*(uint32_t*)0x2000000090d4 = 2;
*(uint32_t*)0x2000000090d8 = 0x200;
*(uint32_t*)0x2000000090dc = 0x80000001;
*(uint32_t*)0x2000000090e0 = 0;
*(uint16_t*)0x2000000090e4 = 4;
*(uint16_t*)0x2000000090e6 = 2;
*(uint16_t*)0x2000000090e8 = 0x1c;
*(uint16_t*)0x2000000090ea = 1;
*(uint8_t*)0x2000000090ec = 0x51;
*(uint8_t*)0x2000000090ed = 4;
*(uint16_t*)0x2000000090ee = 0x1000;
*(uint32_t*)0x2000000090f0 = 0xfffffff8;
*(uint32_t*)0x2000000090f4 = 2;
*(uint32_t*)0x2000000090f8 = 2;
*(uint32_t*)0x2000000090fc = 3;
*(uint32_t*)0x200000009100 = 1;
*(uint16_t*)0x200000009104 = 6;
*(uint16_t*)0x200000009106 = 2;
*(uint16_t*)0x200000009108 = 0xdac;
*(uint16_t*)0x20000000910c = 0x1c;
*(uint16_t*)0x20000000910e = 1;
*(uint8_t*)0x200000009110 = 4;
*(uint8_t*)0x200000009111 = 0x16;
*(uint16_t*)0x200000009112 = 8;
*(uint32_t*)0x200000009114 = 0;
*(uint32_t*)0x200000009118 = 1;
*(uint32_t*)0x20000000911c = 0x401;
*(uint32_t*)0x200000009120 = 4;
*(uint32_t*)0x200000009124 = 2;
*(uint16_t*)0x200000009128 = 8;
*(uint16_t*)0x20000000912a = 2;
*(uint16_t*)0x20000000912c = 0x40;
*(uint16_t*)0x20000000912e = 9;
*(uint16_t*)0x200000009130 = 0x1c;
*(uint16_t*)0x200000009132 = 1;
*(uint8_t*)0x200000009134 = 3;
*(uint8_t*)0x200000009135 = 0x11;
*(uint16_t*)0x200000009136 = 0x40ba;
*(uint32_t*)0x200000009138 = 8;
*(uint32_t*)0x20000000913c = 0;
*(uint32_t*)0x200000009140 = 9;
*(uint32_t*)0x200000009144 = 2;
*(uint32_t*)0x200000009148 = 2;
*(uint16_t*)0x20000000914c = 8;
*(uint16_t*)0x20000000914e = 2;
*(uint16_t*)0x200000009150 = 1;
*(uint16_t*)0x200000009152 = 1;
*(uint16_t*)0x200000009154 = 0x1c;
*(uint16_t*)0x200000009156 = 1;
*(uint8_t*)0x200000009158 = 0xc;
*(uint8_t*)0x200000009159 = 1;
*(uint16_t*)0x20000000915a = 7;
*(uint32_t*)0x20000000915c = 7;
*(uint32_t*)0x200000009160 = 0;
*(uint32_t*)0x200000009164 = 0xb;
*(uint32_t*)0x200000009168 = 0xbb;
*(uint32_t*)0x20000000916c = 2;
*(uint16_t*)0x200000009170 = 8;
*(uint16_t*)0x200000009172 = 2;
*(uint16_t*)0x200000009174 = 7;
*(uint16_t*)0x200000009176 = 5;
*(uint16_t*)0x200000009178 = 0x1c;
*(uint16_t*)0x20000000917a = 1;
*(uint8_t*)0x20000000917c = 1;
*(uint8_t*)0x20000000917d = 0;
*(uint16_t*)0x20000000917e = 3;
*(uint32_t*)0x200000009180 = 0x26c99bf7;
*(uint32_t*)0x200000009184 = 2;
*(uint32_t*)0x200000009188 = 0xffff8262;
*(uint32_t*)0x20000000918c = 0x8001;
*(uint32_t*)0x200000009190 = 2;
*(uint16_t*)0x200000009194 = 8;
*(uint16_t*)0x200000009196 = 2;
*(uint16_t*)0x200000009198 = 4;
*(uint16_t*)0x20000000919a = 0x1a73;
*(uint64_t*)0x200000000788 = 0x15c;
*(uint64_t*)0x200000000018 = 1;
*(uint64_t*)0x200000000020 = 0;
*(uint64_t*)0x200000000028 = 0;
*(uint32_t*)0x200000000030 = 0x40;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000000ul, /*f=*/0ul);
return 0;
}
Reply: **Analysis:**
The bug report indicates a hung task in `hci_dev_open`, specifically blocked at `flush_workqueue(hdev->req_workqueue)`. This happens when a thread waits for all currently executing and queued work items on the Bluetooth device's `req_workqueue` to finish.
By examining the source code, we can see that `hci_dev_open` is only called from two places in the kernel:
1. `hci_sock_ioctl` when handling the `HCIDEVUP` command.
2. `hci_sock_bind` when binding a socket to `HCI_CHANNEL_USER`.
In both cases, the kernel explicitly checks for the `CAP_NET_ADMIN` capability in the initial user namespace using `capable(CAP_NET_ADMIN)`:
```c
// In hci_sock_ioctl:
case HCIDEVUP:
if (!capable(CAP_NET_ADMIN))
return -EPERM;
return hci_dev_open(arg);
// In hci_sock_bind:
case HCI_CHANNEL_USER:
...
if (!capable(CAP_NET_ADMIN)) {
err = -EPERM;
goto done;
}
...
err = hci_dev_open(hdev->id);
```
Because `capable()` checks the init namespace (unlike `ns_capable()`), these operations are strictly inaccessible to unprivileged users, even if they create a new user namespace.
The hung task itself is caused by the `req_workqueue` being busy for an extended period (e.g., > 120 seconds). This can be artificially triggered by a root user (like the syzkaller fuzzer) by creating a virtual Bluetooth device (`vhci`) and either not reading from its character device or queuing many operations (like `add_device` or `set_powered` via the `mgmt` interface) that end up timing out sequentially (each HCI command timeout is typically 2 seconds). When the root user subsequently calls `HCIDEVUP`, the `flush_workqueue` call blocks until all those timeouts expire, triggering the kernel's hung task watchdog.
A malicious physical Bluetooth peripheral could intentionally ignore initialization commands to delay its own `hci_power_on` work item (which runs on `req_workqueue`). However, this would only block the workqueue for that specific device. It would not cause a system-wide denial of service or hang system daemons, because standard daemons (like `bluetoothd`) use the asynchronous `mgmt` interface (e.g., `MGMT_OP_SET_POWERED`), which queues work but does not call `flush_workqueue`. The hang only occurs if a privileged process explicitly invokes the legacy `HCIDEVUP` ioctl or binds a `HCI_CHANNEL_USER` socket while the workqueue is stalled.
**Conclusion:**
Since triggering the bug requires global `CAP_NET_ADMIN` privileges to both stall the workqueue and invoke the blocking `hci_dev_open` path, it crosses no privilege boundaries. It is not accessible to unprivileged users, user namespaces, or remote attackers, and a malicious peripheral cannot force a privileged process to execute the blocking code path. Therefore, this bug has no security impact.
|
| 6/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 15731
output: 38
thoughts: 536
Thoughts: **Analyzing a Syzkaller Hang Report**
Okay, so I've got a syzkaller report here, and the first thing that jumps out is that a task, specifically the syz-executor, has been blocked for over 152 seconds. That's a serious problem β we're looking at a pretty significant hang. The call trace points directly to `__flush_workqueue`, which is being called from `hci_dev_open`. That's interesting, and it looks like it's in `net/bluetooth/hci_core.c`. My immediate thought is, "Alright, let's dive into that `hci_dev_open` function and the workqueue flushing logic." I need to understand why this task is getting hung up waiting for completion in the workqueue within the Bluetooth HCI device opening. There's a potential concurrency issue here, or perhaps a resource contention or deadlock within Bluetooth's HCI device management. This is definitely worth a deep dive into that section of the Bluetooth code.
|
| 7/2 |
2026/05/31 10:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c Name:hci_dev_open]
Results: map[SourceCode: 438: int hci_dev_open(__u16 dev)
439: {
440: struct hci_dev *hdev;
441: int err;
442:
443: hdev = hci_dev_get(dev);
444: if (!hdev)
445: return -ENODEV;
446:
447: /* Devices that are marked as unconfigured can only be powered
448: * up as user channel. Trying to bring them up as normal devices
449: * will result into a failure. Only user channel operation is
450: * possible.
451: *
452: * When this function is called for a user channel, the flag
453: * HCI_USER_CHANNEL will be set first before attempting to
454: * open the device.
455: */
456: if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&
457: !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
458: err = -EOPNOTSUPP;
459: goto done;
460: }
461:
462: /* We need to ensure that no other power on/off work is pending
463: * before proceeding to call hci_dev_do_open. This is
464: * particularly important if the setup procedure has not yet
465: * completed.
466: */
467: if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF))
468: cancel_delayed_work(&hdev->power_off);
469:
470: /* After this call it is guaranteed that the setup procedure
471: * has finished. This means that error conditions like RFKILL
472: * or no valid public or static random address apply.
473: */
474: flush_workqueue(hdev->req_workqueue);
475:
476: /* For controllers not using the management interface and that
477: * are brought up using legacy ioctl, set the HCI_BONDABLE bit
478: * so that pairing works for them. Once the management interface
479: * is in use this bit will be cleared again and userspace has
480: * to explicitly enable it.
481: */
482: if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
483: !hci_dev_test_flag(hdev, HCI_MGMT))
484: hci_dev_set_flag(hdev, HCI_BONDABLE);
485:
486: err = hci_dev_do_open(hdev);
487:
488: done:
489: hci_dev_put(hdev);
490: return err;
491: }
SourceFile:net/bluetooth/hci_core.c]
|
| 8/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 17372
output: 54
thoughts: 69
Thoughts: **Analyzing a Blocked Workqueue**
Okay, so I'm hitting a snag β the code's getting hung up at `flush_workqueue(hdev->req_workqueue);` on line 474. My immediate thought is, "Why?" This is where things get interesting. Is there a potential deadlock lurking in the shadows, or perhaps a work item that's been started but for some reason, isn't completing as it should? I need to understand what's currently active or waiting within that specific workqueue, `hdev->req_workqueue`. Let's delve into the queue's contents to get some clarity on the blockage.
|
| 9/2 |
2026/05/31 10:15 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:net/bluetooth/hci_core.c IncludeSnippetLines:2 Name:req_workqueue SourceTreePrefix:net/bluetooth/]
Results: map[References:<nil> TruncatedOutput:false]
|
| 10/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 17658
output: 28
thoughts: 23
Thoughts: Here's my thought process, as if I were considering this search:
**Diving into the Bluetooth HCI Core**
Alright, let's get down to brass tacks. I'm going to start by looking for `req_workqueue` within the `net/bluetooth/hci_core.c` file. This is where the core handling of the Bluetooth HCI (Host Controller Interface) happens. `req_workqueue` sounds like it might relate to some kind of request queuing or management within the HCI driver. Given my expertise, I'm expecting to see something related to handling incoming HCI commands, events, or perhaps even asynchronous operations within the kernel's workqueue mechanism. I'm keen to see how the HCI interacts with the workqueue, looking for things like deferred processing of data, scheduling of tasks, or handling of interrupts. Let's see what we can dig up. I'm anticipating finding where the workqueue is initialized, where tasks are added to it, and how the results are processed.
|
| 11/2 |
2026/05/31 10:15 |
tool |
grepper |
0m
Args: map[Expression:req_workqueue PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_core.c=438=int hci_dev_open(__u16 dev)
--
net/bluetooth/hci_core.c-473- */
net/bluetooth/hci_core.c:474: flush_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-475-
--
net/bluetooth/hci_core.c=943=static void hci_power_on(struct work_struct *work)
--
net/bluetooth/hci_core.c-977- } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
net/bluetooth/hci_core.c:978: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/hci_core.c-979- HCI_AUTO_OFF_TIMEOUT);
--
net/bluetooth/hci_core.c=2584=int hci_register_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2609-
net/bluetooth/hci_core.c:2610: hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI,
net/bluetooth/hci_core.c-2611- hdev->name);
net/bluetooth/hci_core.c:2612: if (!hdev->req_workqueue) {
net/bluetooth/hci_core.c-2613- destroy_workqueue(hdev->workqueue);
--
net/bluetooth/hci_core.c-2670-
net/bluetooth/hci_core.c:2671: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/hci_core.c-2672-
--
net/bluetooth/hci_core.c-2680- destroy_workqueue(hdev->workqueue);
net/bluetooth/hci_core.c:2681: destroy_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-2682-err:
--
net/bluetooth/hci_core.c=2743=void hci_release_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2749- destroy_workqueue(hdev->workqueue);
net/bluetooth/hci_core.c:2750: destroy_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-2751-
--
net/bluetooth/hci_event.c=4411=static void hci_hardware_error_evt(struct hci_dev *hdev, void *data,
--
net/bluetooth/hci_event.c-4419-
net/bluetooth/hci_event.c:4420: queue_work(hdev->req_workqueue, &hdev->error_reset);
net/bluetooth/hci_event.c-4421-}
--
net/bluetooth/hci_sync.c=586=static void interleave_scan_work(struct work_struct *work)
--
net/bluetooth/hci_sync.c-621- if (is_interleave_scanning(hdev))
net/bluetooth/hci_sync.c:622: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-623- &hdev->interleave_scan, timeout);
--
net/bluetooth/hci_sync.c=702=int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
--
net/bluetooth/hci_sync.c-726-
net/bluetooth/hci_sync.c:727: queue_work(hdev->req_workqueue, &hdev->cmd_sync_work);
net/bluetooth/hci_sync.c-728-
--
net/bluetooth/hci_sync.c=1954=int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
--
net/bluetooth/hci_sync.c-1991- hdev->adv_instance_timeout = timeout;
net/bluetooth/hci_sync.c:1992: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-1993- &hdev->adv_instance_expire,
--
net/bluetooth/hci_sync.c=2252=static void hci_start_interleave_scan(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-2254- hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
net/bluetooth/hci_sync.c:2255: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-2256- &hdev->interleave_scan, 0);
--
net/bluetooth/hci_sync.c=5397=static int hci_power_on_sync(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-5422- } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
net/bluetooth/hci_sync.c:5423: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/hci_sync.c-5424- HCI_AUTO_OFF_TIMEOUT);
--
net/bluetooth/hci_sync.c=6038=int hci_start_discovery_sync(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-6082-
net/bluetooth/hci_sync.c:6083: queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable,
net/bluetooth/hci_sync.c-6084- timeout);
--
net/bluetooth/mgmt.c=1528=static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1550- int to = secs_to_jiffies(hdev->discov_timeout);
net/bluetooth/mgmt.c:1551: queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to);
net/bluetooth/mgmt.c-1552- }
--
net/bluetooth/mgmt.c=1572=static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1661- int to = secs_to_jiffies(hdev->discov_timeout);
net/bluetooth/mgmt.c:1662: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/mgmt.c-1663- &hdev->discov_off, to);
--
net/bluetooth/mgmt.c=2298=static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err)
--
net/bluetooth/mgmt.c-2314- mesh_send_interval = msecs_to_jiffies((send->cnt) * 25);
net/bluetooth/mgmt.c:2315: queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done,
net/bluetooth/mgmt.c-2316- mesh_send_interval);
--
net/bluetooth/mgmt.c=8050=static int set_external_config(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-8093-
net/bluetooth/mgmt.c:8094: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/mgmt.c-8095- } else {
--
net/bluetooth/mgmt.c=8106=static int set_public_address(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-8149-
net/bluetooth/mgmt.c:8150: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/mgmt.c-8151- }
]
|
| 12/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 20079
output: 55
thoughts: 746
Thoughts: **Debugging a Bluetooth HCI Device Open Hang**
Okay, so I'm looking at this issue where `hci_dev_open` is getting stuck, specifically when it calls `flush_workqueue(hdev->req_workqueue)`. I see a bunch of work items queued on `hdev->req_workqueue`: `power_on`, `power_off`, `error_reset`, `interleave_scan`, `cmd_sync_work`, `adv_instance_expire`, `le_scan_disable`, `discov_off`, and `mesh_send_done`. The problem is that `flush_workqueue` will hang indefinitely if a work item is currently running and blocked.
The trace is showing the block in `hci_dev_open`, which is normal, but the cause is where I'm getting lost.
Let's check the syzkaller reproducer to see what's leading up to this state. The reproducer calls `socket(AF_NETLINK)`, does an `ioctl(SIOCGIFINDEX)` on "lo", and then does a `sendmsg`. The `ioctl` gets the ifindex of "lo". The syzkaller program then sends a `RTM_NEWQDISC` message with `cake` qdisc on the netlink socket.
That doesn't immediately suggest what's happening. How does a netlink operation trigger `hci_dev_open`? The call trace seems a bit misleading, because it's showing `sock_ioctl` calling into `hci_dev_open`. I'm seeing:
```
hci_dev_open+0x145/0x300 net/bluetooth/hci_core.c:474
sock_do_ioctl+0xdc/0x300 net/socket.c:1245
sock_ioctl+0x576/0x790 net/socket.c:1366
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
```
This must mean the reproducer is incomplete, or the syzkaller program is doing something I haven't tracked yet, because `hci_sock_ioctl` isn't in this trace. The reproducer only explicitly does `socket`, `ioctl`, and `sendmsg`. Wait, am I misinterpreting the trace? `hci_dev_open` is *not* called from `hci_sock_ioctl`, which is in the Bluetooth netlink code. I must have misread it. I'll need to go back and trace the interactions more thoroughly, or review the syzkaller code more closely to see what else it might be doing. This netlink interaction *must* be indirectly affecting something that's leading to `hci_dev_open`.
|
| 13/2 |
2026/05/31 10:15 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c IncludeSnippetLines:2 Name:hci_dev_open SourceTreePrefix:net/bluetooth/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hci_sock_bind SourceFile:net/bluetooth/hci_sock.c SourceLine:1318 SourceSnippet:1316: hci_dev_unlock(hdev);
1317:
1318: err = hci_dev_open(hdev->id);
1319: if (err) {
1320: if (err == -EALREADY) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hci_sock_ioctl SourceFile:net/bluetooth/hci_sock.c SourceLine:1130 SourceSnippet:1128: if (!capable(CAP_NET_ADMIN))
1129: return -EPERM;
1130: return hci_dev_open(arg);
1131:
1132: case HCIDEVDOWN:
]] TruncatedOutput:false]
|
| 14/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 21798
output: 40
thoughts: 257
Thoughts: **Debugging a Bluetooth Kernel Hang**
Okay, so I'm looking at this kernel issue, and it seems related to Bluetooth device bring-up (`HCIDEVUP`). The function `hci_sock_ioctl` handles this, calling `hci_dev_open` in the process. The reproducer itself doesn't explicitly create a Bluetooth socket or call `ioctl(HCIDEVUP)`. Hmm, that's odd. But this could be part of a larger Syzkaller execution, or perhaps the reproducer is only a fragment of the full scenario.
Let's trace this back. `hci_dev_open` gets called from within `sock_ioctl`, which itself comes from `sock_do_ioctl`, which then points back to `hci_sock_ioctl`. Right, `sock_do_ioctl` calls either `sk->sk_prot->ioctl` or `sock->ops->ioctl`, depending on the situation.
If a task is blocked in `hci_dev_open` for over two and a half minutes, that screams `flush_workqueue` hanging to me. So why would `flush_workqueue(hdev->req_workqueue)` be hanging? My initial thought is either a work item is running and blocked within that queue, or, perhaps, the workqueue itself is in some kind of deadlock. Time to investigate what work items are actually queued on `req_workqueue`. The most prevalent one appears to be `cmd_sync_work`, which in turn executes `hci_cmd_sync_work`. Okay, that's where I need to focus my attention.
|
| 15/2 |
2026/05/31 10:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_cmd_sync_work]
Results: map[SourceCode: 305: static void hci_cmd_sync_work(struct work_struct *work)
306: {
307: struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work);
308:
309: bt_dev_dbg(hdev, "");
310:
311: /* Dequeue all entries and run them */
312: while (1) {
313: struct hci_cmd_sync_work_entry *entry;
314:
315: mutex_lock(&hdev->cmd_sync_work_lock);
316: entry = list_first_entry_or_null(&hdev->cmd_sync_work_list,
317: struct hci_cmd_sync_work_entry,
318: list);
319: if (entry)
320: list_del(&entry->list);
321: mutex_unlock(&hdev->cmd_sync_work_lock);
322:
323: if (!entry)
324: break;
325:
326: bt_dev_dbg(hdev, "entry %p", entry);
327:
328: if (entry->func) {
329: int err;
330:
331: hci_req_sync_lock(hdev);
332: err = entry->func(hdev, entry->data);
333: if (entry->destroy)
334: entry->destroy(hdev, entry->data, err);
335: hci_req_sync_unlock(hdev);
336: }
337:
338: kfree(entry);
339: }
340: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 16/2 |
2026/05/31 10:15 |
llm |
expert |
0m
Model:
Tokens:
input: 22970
output: 40
thoughts: 94
Thoughts: **Analyzing the HCI Command Synchronization**
Okay, so I'm looking at this `hci_cmd_sync_work` function, and the first thing it does is call `hci_req_sync_lock(hdev)`. Right, that's expected for synchronization. But hang on, `hci_req_sync_lock`... that's a mutex, isn't it? Okay, yeah, it's a mutex. So if another process or thread already has a hold on `hdev->req_sync_lock`, then `hci_cmd_sync_work` is going to block, waiting for the lock to be released.
Now the critical question: who *is* holding `hdev->req_sync_lock`? What part of the system has it? I need to trace this back. Let me go check on that `hci_req_sync_lock` variable and figure out the possible contention sources. I need to understand the locking hierarchy here to determine potential bottlenecks and race conditions.
|
| 17/2 |
2026/05/31 10:16 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_req_sync_lock]
Results: map[SourceCode: SourceFile:]
|
| 18/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 23340
output: 31
thoughts: 14
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Investigating a Synchronization Point in HCI Request Handling**
Alright, so the first thing I'm doing is zeroing in on a specific point of interest: `hci_req_sync_lock`. This suggests I'm diving into the kernel's handling of HCI requests, likely related to Bluetooth or similar protocols. The presence of "sync_lock" immediately tells me this is about managing concurrent access and protecting critical sections, likely around request processing. I'm probably looking at a potential contention point, a performance bottleneck, or perhaps even a source of subtle race conditions within the HCI request flow. My goal is to understand precisely *what* this lock protects, *how* it's acquired and released, and *when* it's held. I want to see if this is an expected lock, a problem, or just where the action is. I need to understand the implications for parallel processing and overall throughput in the HCI layer. Understanding the locking behavior here is crucial for comprehending the underlying synchronization mechanisms and performance characteristics of this portion of the system.
|
| 19/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Args: map[Expression:hci_req_sync_lock PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_core.c=325=int hci_inquiry(void __user *arg)
--
net/bluetooth/hci_core.c-369- if (do_inquiry) {
net/bluetooth/hci_core.c:370: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-371- err = hci_inquiry_sync(hdev, ir.length, ir.num_rsp);
--
net/bluetooth/hci_core.c=422=static int hci_dev_do_open(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-427-
net/bluetooth/hci_core.c:428: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-429-
--
net/bluetooth/hci_core.c=493=int hci_dev_do_close(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-498-
net/bluetooth/hci_core.c:499: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-500-
--
net/bluetooth/hci_core.c=533=static int hci_dev_do_reset(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-538-
net/bluetooth/hci_core.c:539: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-540-
--
net/bluetooth/hci_core.c=887=static int hci_dev_do_poweroff(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-892-
net/bluetooth/hci_core.c:893: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-894-
--
net/bluetooth/hci_core.c=1894=void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
--
net/bluetooth/hci_core.c-1917- * also attempts to forward the request to the controller.
net/bluetooth/hci_core.c:1918: * This function requires the caller holds hci_req_sync_lock.
net/bluetooth/hci_core.c-1919- */
net/bluetooth/hci_core.c=1920=int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
--
net/bluetooth/hci_core.c-1963- * controller doesn't have a corresponding handle, remove anyway.
net/bluetooth/hci_core.c:1964: * This function requires the caller holds hci_req_sync_lock.
net/bluetooth/hci_core.c-1965- */
net/bluetooth/hci_core.c=1966=static int hci_remove_adv_monitor(struct hci_dev *hdev,
--
net/bluetooth/hci_core.c-2000-
net/bluetooth/hci_core.c:2001:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/hci_core.c-2002-int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle)
--
net/bluetooth/hci_core.c-2011-
net/bluetooth/hci_core.c:2012:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/hci_core.c-2013-int hci_remove_all_adv_monitor(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c=2830=int hci_suspend_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2847-
net/bluetooth/hci_core.c:2848: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-2849- ret = hci_suspend_sync(hdev);
--
net/bluetooth/hci_core.c=2861=int hci_resume_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2875-
net/bluetooth/hci_core.c:2876: hci_req_sync_lock(hdev);
net/bluetooth/hci_core.c-2877- ret = hci_resume_sync(hdev);
--
net/bluetooth/hci_debugfs.c=1287=static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
--
net/bluetooth/hci_debugfs.c-1304-
net/bluetooth/hci_debugfs.c:1305: hci_req_sync_lock(hdev);
net/bluetooth/hci_debugfs.c-1306- if (enable)
--
net/bluetooth/hci_debugfs.c=1343=static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,
--
net/bluetooth/hci_debugfs.c-1363-
net/bluetooth/hci_debugfs.c:1364: hci_req_sync_lock(hdev);
net/bluetooth/hci_debugfs.c-1365- err = hdev->set_diag(hdev, enable);
--
net/bluetooth/hci_sync.c=228=struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
--
net/bluetooth/hci_sync.c-237-
net/bluetooth/hci_sync.c:238: hci_req_sync_lock(hdev);
net/bluetooth/hci_sync.c-239- skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout);
--
net/bluetooth/hci_sync.c=292=int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
--
net/bluetooth/hci_sync.c-296-
net/bluetooth/hci_sync.c:297: hci_req_sync_lock(hdev);
net/bluetooth/hci_sync.c-298- err = __hci_cmd_sync_status(hdev, opcode, plen, param, timeout);
--
net/bluetooth/hci_sync.c=305=static void hci_cmd_sync_work(struct work_struct *work)
--
net/bluetooth/hci_sync.c-330-
net/bluetooth/hci_sync.c:331: hci_req_sync_lock(hdev);
net/bluetooth/hci_sync.c-332- err = entry->func(hdev, entry->data);
--
net/bluetooth/mgmt.c=4780=static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-4805-
net/bluetooth/mgmt.c:4806: hci_req_sync_lock(hdev);
net/bluetooth/mgmt.c-4807-
--
net/bluetooth/msft.c=258=static int msft_le_monitor_advertisement_cb(struct hci_dev *hdev, u16 opcode,
--
net/bluetooth/msft.c-301-
net/bluetooth/msft.c:302:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-303-static void msft_remove_addr_filters_sync(struct hci_dev *hdev, u8 handle)
--
net/bluetooth/msft.c=366=static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev,
--
net/bluetooth/msft.c-421-
net/bluetooth/msft.c:422:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-423-static int msft_remove_monitor_sync(struct hci_dev *hdev,
--
net/bluetooth/msft.c-447-
net/bluetooth/msft.c:448:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-449-int msft_suspend_sync(struct hci_dev *hdev)
--
net/bluetooth/msft.c=505=static int msft_add_monitor_sync(struct hci_dev *hdev,
--
net/bluetooth/msft.c-580-
net/bluetooth/msft.c:581:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-582-static void reregister_monitor(struct hci_dev *hdev)
--
net/bluetooth/msft.c-606-
net/bluetooth/msft.c:607:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-608-int msft_resume_sync(struct hci_dev *hdev)
--
net/bluetooth/msft.c-629-
net/bluetooth/msft.c:630:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-631-void msft_do_open(struct hci_dev *hdev)
--
net/bluetooth/msft.c=833=static int msft_add_address_filter_sync(struct hci_dev *hdev, void *data)
--
net/bluetooth/msft.c-854- * not been added by now.
net/bluetooth/msft.c:855: * And all other functions that requiring hci_req_sync_lock wouldn't
net/bluetooth/msft.c-856- * touch this filter before this func completes because it's protected
net/bluetooth/msft.c:857: * by hci_req_sync_lock.
net/bluetooth/msft.c-858- */
--
net/bluetooth/msft.c=1123=static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev,
--
net/bluetooth/msft.c-1150-
net/bluetooth/msft.c:1151:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-1152-int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor)
--
net/bluetooth/msft.c-1164-
net/bluetooth/msft.c:1165:/* This function requires the caller holds hci_req_sync_lock */
net/bluetooth/msft.c-1166-int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
]
|
| 20/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 26453
output: 40
thoughts: 52
Thoughts: Here's my analysis of the situation:
**Synchronization in HCI Device Opening**
Okay, so `hci_dev_do_open` is the critical function here. My immediate thought is, let's trace this back to the relevant locking mechanism. The function call tree tells me that `hci_dev_do_open` is making a call to `hci_req_sync_lock(hdev)`. That's my starting point. Now I need to see what's happening within `hci_dev_do_open`. I'll look at the code within `net/bluetooth/hci_core.c` and focus on the purpose and application of the lock. I'm especially interested in how this lock impacts concurrency and potential race conditions when opening a HCI device. Is it protecting access to the `hdev` structure or related resources? What are the implications for simultaneous operations? Time to dig in and understand the details.
|
| 21/2 |
2026/05/31 10:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c Name:hci_dev_do_open]
Results: map[SourceCode: 422: static int hci_dev_do_open(struct hci_dev *hdev)
423: {
424: int ret = 0;
425:
426: BT_DBG("%s %p", hdev->name, hdev);
427:
428: hci_req_sync_lock(hdev);
429:
430: ret = hci_dev_open_sync(hdev);
431:
432: hci_req_sync_unlock(hdev);
433: return ret;
434: }
SourceFile:net/bluetooth/hci_core.c]
|
| 22/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 26947
output: 38
thoughts: 336
Thoughts: **Analyzing the Threading in `hci_dev_open`**
Okay, let's break this down. My initial thought was that `hci_dev_open` might be mishandling the lock, but let's retrace our steps. First, the code clearly shows that `flush_workqueue(hdev->req_workqueue)` is called *before* `hci_dev_do_open`. I need to ensure that the workqueue is flushed at the right time.
Now, let's confirm the sequence in `hci_dev_open`. We see the `flush_workqueue` call, followed by some flag setting based on channel and management interface usage. Then, *finally*, it calls `hci_dev_do_open`. Critically, `hci_dev_open` *does not* hold `hci_req_sync_lock` when calling `flush_workqueue`. That's the key. This is the race condition I suspect.
So, who calls `hci_dev_open`? It's `hci_sock_ioctl`. Right. Now, does `hci_sock_ioctl` hold `hci_req_sync_lock`? No, it's a socket ioctl, not directly associated. This is getting interesting. Now, is there any lock contention on the hci_dev struct? I need to check `hci_sock_ioctl` and more closely. The other possibility is that `hci_dev_open` somehow acquires `hdev->lock` before `flush_workqueue`. Let's confirm.
|
| 23/2 |
2026/05/31 10:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sock.c Name:hci_sock_ioctl]
Results: map[SourceCode:1043: static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
1044: unsigned long arg)
1045: {
1046: void __user *argp = (void __user *)arg;
1047: struct sock *sk = sock->sk;
1048: int err;
1049:
1050: BT_DBG("cmd %x arg %lx", cmd, arg);
1051:
1052: /* Make sure the cmd is valid before doing anything */
1053: switch (cmd) {
1054: case HCIGETDEVLIST:
1055: case HCIGETDEVINFO:
1056: case HCIGETCONNLIST:
1057: case HCIDEVUP:
1058: case HCIDEVDOWN:
1059: case HCIDEVRESET:
1060: case HCIDEVRESTAT:
1061: case HCISETSCAN:
1062: case HCISETAUTH:
1063: case HCISETENCRYPT:
1064: case HCISETPTYPE:
1065: case HCISETLINKPOL:
1066: case HCISETLINKMODE:
1067: case HCISETACLMTU:
1068: case HCISETSCOMTU:
1069: case HCIINQUIRY:
1070: case HCISETRAW:
1071: case HCIGETCONNINFO:
1072: case HCIGETAUTHINFO:
1073: case HCIBLOCKADDR:
1074: case HCIUNBLOCKADDR:
1075: break;
1076: default:
1077: return -ENOIOCTLCMD;
1078: }
1079:
1080: lock_sock(sk);
1081:
1082: if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
1083: err = -EBADFD;
1084: goto done;
1085: }
1086:
1087: /* When calling an ioctl on an unbound raw socket, then ensure
1088: * that the monitor gets informed. Ensure that the resulting event
1089: * is only send once by checking if the cookie exists or not. The
1090: * socket cookie will be only ever generated once for the lifetime
1091: * of a given socket.
1092: */
1093: if (hci_sock_gen_cookie(sk)) {
1094: struct sk_buff *skb;
1095:
1096: /* Perform careful checks before setting the HCI_SOCK_TRUSTED
1097: * flag. Make sure that not only the current task but also
1098: * the socket opener has the required capability, since
1099: * privileged programs can be tricked into making ioctl calls
1100: * on HCI sockets, and the socket should not be marked as
1101: * trusted simply because the ioctl caller is privileged.
1102: */
1103: if (sk_capable(sk, CAP_NET_ADMIN))
1104: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1105:
1106: /* Send event to monitor */
1107: skb = create_monitor_ctrl_open(sk);
1108: if (skb) {
1109: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1110: HCI_SOCK_TRUSTED, NULL);
1111: kfree_skb(skb);
1112: }
1113: }
1114:
1115: release_sock(sk);
1116:
1117: switch (cmd) {
1118: case HCIGETDEVLIST:
1119: return hci_get_dev_list(argp);
1120:
1121: case HCIGETDEVINFO:
1122: return hci_get_dev_info(argp);
1123:
1124: case HCIGETCONNLIST:
1125: return hci_get_conn_list(argp);
1126:
1127: case HCIDEVUP:
1128: if (!capable(CAP_NET_ADMIN))
1129: return -EPERM;
1130: return hci_dev_open(arg);
1131:
1132: case HCIDEVDOWN:
1133: if (!capable(CAP_NET_ADMIN))
1134: return -EPERM;
1135: return hci_dev_close(arg);
1136:
1137: case HCIDEVRESET:
1138: if (!capable(CAP_NET_ADMIN))
1139: return -EPERM;
1140: return hci_dev_reset(arg);
1141:
1142: case HCIDEVRESTAT:
1143: if (!capable(CAP_NET_ADMIN))
1144: return -EPERM;
1145: return hci_dev_reset_stat(arg);
1146:
1147: case HCISETSCAN:
1148: case HCISETAUTH:
1149: case HCISETENCRYPT:
1150: case HCISETPTYPE:
1151: case HCISETLINKPOL:
1152: case HCISETLINKMODE:
1153: case HCISETACLMTU:
1154: case HCISETSCOMTU:
1155: if (!capable(CAP_NET_ADMIN))
1156: return -EPERM;
1157: return hci_dev_cmd(cmd, argp);
1158:
1159: case HCIINQUIRY:
1160: return hci_inquiry(argp);
1161: }
1162:
1163: lock_sock(sk);
1164:
1165: err = hci_sock_bound_ioctl(sk, cmd, arg);
1166:
1167: done:
1168: release_sock(sk);
1169: return err;
1170: }
SourceFile:net/bluetooth/hci_sock.c]
|
| 24/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 29412
output: 38
thoughts: 387
Thoughts: **Deconstructing the Reproducer's Actions**
Okay, so I'm looking at this syzkaller reproducer and immediately, a flag goes up: it mentions `HCIDEVUP`, which usually needs `CAP_NET_ADMIN`. But the reproducer *doesn't* seem to be directly calling `HCIDEVUP`. It's doing an `ioctl` on a socket, specifically `ioctl(fd, 0x8933, arg)`. And looking at the constants, `0x8933` is `SIOCGIFINDEX`. Hmm, so not directly `HCIDEVUP`.
Let's break down that section of the reproducer: It creates a `AF_NETLINK` socket (syscall `socket`), then copies "lo" into a buffer at `0x200000000240`, and finally uses an `ioctl` on that socket and the buffer to call `SIOCGIFINDEX`.
Now, `sock_ioctl` handles `SIOCGIFINDEX`, which leads into `dev_ioctl`. So, that's what's happening on the `AF_NETLINK` socket with `SIOCGIFINDEX` and this "lo" interface.
But the real question is how does `hci_dev_open` get triggered? It's not directly in this code. It seems like it isn't called from `hci_sock_ioctl`. Wait a minute, could `hci_dev_open` be called from `hci_sock_bind`? That's the next avenue to explore. I'll need to check the code there to see if that's the path.
|
| 25/2 |
2026/05/31 10:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sock.c Name:hci_sock_bind]
Results: map[SourceCode:1188: static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
1189: int addr_len)
1190: {
1191: struct sockaddr_hci haddr;
1192: struct sock *sk = sock->sk;
1193: struct hci_dev *hdev = NULL;
1194: struct sk_buff *skb;
1195: int len, err = 0;
1196:
1197: BT_DBG("sock %p sk %p", sock, sk);
1198:
1199: if (!addr)
1200: return -EINVAL;
1201:
1202: memset(&haddr, 0, sizeof(haddr));
1203: len = min_t(unsigned int, sizeof(haddr), addr_len);
1204: memcpy(&haddr, addr, len);
1205:
1206: if (haddr.hci_family != AF_BLUETOOTH)
1207: return -EINVAL;
1208:
1209: lock_sock(sk);
1210:
1211: /* Allow detaching from dead device and attaching to alive device, if
1212: * the caller wants to re-bind (instead of close) this socket in
1213: * response to hci_sock_dev_event(HCI_DEV_UNREG) notification.
1214: */
1215: hdev = hci_pi(sk)->hdev;
1216: if (hdev && hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
1217: hci_pi(sk)->hdev = NULL;
1218: sk->sk_state = BT_OPEN;
1219: hci_dev_put(hdev);
1220: }
1221: hdev = NULL;
1222:
1223: if (sk->sk_state == BT_BOUND) {
1224: err = -EALREADY;
1225: goto done;
1226: }
1227:
1228: switch (haddr.hci_channel) {
1229: case HCI_CHANNEL_RAW:
1230: if (hci_pi(sk)->hdev) {
1231: err = -EALREADY;
1232: goto done;
1233: }
1234:
1235: if (haddr.hci_dev != HCI_DEV_NONE) {
1236: hdev = hci_dev_get(haddr.hci_dev);
1237: if (!hdev) {
1238: err = -ENODEV;
1239: goto done;
1240: }
1241:
1242: atomic_inc(&hdev->promisc);
1243: }
1244:
1245: hci_pi(sk)->channel = haddr.hci_channel;
1246:
1247: if (!hci_sock_gen_cookie(sk)) {
1248: /* In the case when a cookie has already been assigned,
1249: * then there has been already an ioctl issued against
1250: * an unbound socket and with that triggered an open
1251: * notification. Send a close notification first to
1252: * allow the state transition to bounded.
1253: */
1254: skb = create_monitor_ctrl_close(sk);
1255: if (skb) {
1256: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1257: HCI_SOCK_TRUSTED, NULL);
1258: kfree_skb(skb);
1259: }
1260: }
1261:
1262: if (capable(CAP_NET_ADMIN))
1263: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1264:
1265: hci_pi(sk)->hdev = hdev;
1266:
1267: /* Send event to monitor */
1268: skb = create_monitor_ctrl_open(sk);
1269: if (skb) {
1270: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1271: HCI_SOCK_TRUSTED, NULL);
1272: kfree_skb(skb);
1273: }
1274: break;
1275:
1276: case HCI_CHANNEL_USER:
1277: if (hci_pi(sk)->hdev) {
1278: err = -EALREADY;
1279: goto done;
1280: }
1281:
1282: if (haddr.hci_dev == HCI_DEV_NONE) {
1283: err = -EINVAL;
1284: goto done;
1285: }
1286:
1287: if (!capable(CAP_NET_ADMIN)) {
1288: err = -EPERM;
1289: goto done;
1290: }
1291:
1292: hdev = hci_dev_get(haddr.hci_dev);
1293: if (!hdev) {
1294: err = -ENODEV;
1295: goto done;
1296: }
1297:
1298: if (test_bit(HCI_INIT, &hdev->flags) ||
1299: hci_dev_test_flag(hdev, HCI_SETUP) ||
1300: hci_dev_test_flag(hdev, HCI_CONFIG) ||
1301: (!hci_dev_test_flag(hdev, HCI_AUTO_OFF) &&
1302: test_bit(HCI_UP, &hdev->flags))) {
1303: err = -EBUSY;
1304: hci_dev_put(hdev);
1305: goto done;
1306: }
1307:
1308: if (hci_dev_test_and_set_flag(hdev, HCI_USER_CHANNEL)) {
1309: err = -EUSERS;
1310: hci_dev_put(hdev);
1311: goto done;
1312: }
1313:
1314: hci_dev_lock(hdev);
1315: mgmt_index_removed(hdev);
1316: hci_dev_unlock(hdev);
1317:
1318: err = hci_dev_open(hdev->id);
1319: if (err) {
1320: if (err == -EALREADY) {
1321: /* In case the transport is already up and
1322: * running, clear the error here.
1323: *
1324: * This can happen when opening a user
1325: * channel and HCI_AUTO_OFF grace period
1326: * is still active.
1327: */
1328: err = 0;
1329: } else {
1330: hci_dev_clear_flag(hdev, HCI_USER_CHANNEL);
1331: mgmt_index_added(hdev);
1332: hci_dev_put(hdev);
1333: goto done;
1334: }
1335: }
1336:
1337: hci_pi(sk)->channel = haddr.hci_channel;
1338:
1339: if (!hci_sock_gen_cookie(sk)) {
1340: /* In the case when a cookie has already been assigned,
1341: * this socket will transition from a raw socket into
1342: * a user channel socket. For a clean transition, send
1343: * the close notification first.
1344: */
1345: skb = create_monitor_ctrl_close(sk);
1346: if (skb) {
1347: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1348: HCI_SOCK_TRUSTED, NULL);
1349: kfree_skb(skb);
1350: }
1351: }
1352:
1353: /* The user channel is restricted to CAP_NET_ADMIN
1354: * capabilities and with that implicitly trusted.
1355: */
1356: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1357:
1358: hci_pi(sk)->hdev = hdev;
1359:
1360: /* Send event to monitor */
1361: skb = create_monitor_ctrl_open(sk);
1362: if (skb) {
1363: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1364: HCI_SOCK_TRUSTED, NULL);
1365: kfree_skb(skb);
1366: }
1367:
1368: atomic_inc(&hdev->promisc);
1369: break;
1370:
1371: case HCI_CHANNEL_MONITOR:
1372: if (haddr.hci_dev != HCI_DEV_NONE) {
1373: err = -EINVAL;
1374: goto done;
1375: }
1376:
1377: if (!capable(CAP_NET_RAW)) {
1378: err = -EPERM;
1379: goto done;
1380: }
1381:
1382: hci_pi(sk)->channel = haddr.hci_channel;
1383:
1384: /* The monitor interface is restricted to CAP_NET_RAW
1385: * capabilities and with that implicitly trusted.
1386: */
1387: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1388:
1389: send_monitor_note(sk, "Linux version %s (%s)",
1390: init_utsname()->release,
1391: init_utsname()->machine);
1392: send_monitor_note(sk, "Bluetooth subsystem version %u.%u",
1393: BT_SUBSYS_VERSION, BT_SUBSYS_REVISION);
1394: send_monitor_replay(sk);
1395: send_monitor_control_replay(sk);
1396:
1397: atomic_inc(&monitor_promisc);
1398: break;
1399:
1400: case HCI_CHANNEL_LOGGING:
1401: if (haddr.hci_dev != HCI_DEV_NONE) {
1402: err = -EINVAL;
1403: goto done;
1404: }
1405:
1406: if (!capable(CAP_NET_ADMIN)) {
1407: err = -EPERM;
1408: goto done;
1409: }
1410:
1411: hci_pi(sk)->channel = haddr.hci_channel;
1412: break;
1413:
1414: default:
1415: if (!hci_mgmt_chan_find(haddr.hci_channel)) {
1416: err = -EINVAL;
1417: goto done;
1418: }
1419:
1420: if (haddr.hci_dev != HCI_DEV_NONE) {
1421: err = -EINVAL;
1422: goto done;
1423: }
1424:
1425: /* Users with CAP_NET_ADMIN capabilities are allowed
1426: * access to all management commands and events. For
1427: * untrusted users the interface is restricted and
1428: * also only untrusted events are sent.
1429: */
1430: if (capable(CAP_NET_ADMIN))
1431: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1432:
1433: hci_pi(sk)->channel = haddr.hci_channel;
1434:
1435: /* At the moment the index and unconfigured index events
1436: * are enabled unconditionally. Setting them on each
1437: * socket when binding keeps this functionality. They
1438: * however might be cleared later and then sending of these
1439: * events will be disabled, but that is then intentional.
1440: *
1441: * This also enables generic events that are safe to be
1442: * received by untrusted users. Example for such events
1443: * are changes to settings, class of device, name etc.
1444: */
1445: if (hci_pi(sk)->channel == HCI_CHANNEL_CONTROL) {
1446: if (!hci_sock_gen_cookie(sk)) {
1447: /* In the case when a cookie has already been
1448: * assigned, this socket will transition from
1449: * a raw socket into a control socket. To
1450: * allow for a clean transition, send the
1451: * close notification first.
1452: */
1453: skb = create_monitor_ctrl_close(sk);
1454: if (skb) {
1455: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1456: HCI_SOCK_TRUSTED, NULL);
1457: kfree_skb(skb);
1458: }
1459: }
1460:
1461: /* Send event to monitor */
1462: skb = create_monitor_ctrl_open(sk);
1463: if (skb) {
1464: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1465: HCI_SOCK_TRUSTED, NULL);
1466: kfree_skb(skb);
1467: }
1468:
1469: hci_sock_set_flag(sk, HCI_MGMT_INDEX_EVENTS);
1470: hci_sock_set_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS);
1471: hci_sock_set_flag(sk, HCI_MGMT_OPTION_EVENTS);
1472: hci_sock_set_flag(sk, HCI_MGMT_SETTING_EVENTS);
1473: hci_sock_set_flag(sk, HCI_MGMT_DEV_CLASS_EVENTS);
1474: hci_sock_set_flag(sk, HCI_MGMT_LOCAL_NAME_EVENTS);
1475: }
1476: break;
1477: }
1478:
1479: /* Default MTU to HCI_MAX_FRAME_SIZE if not set */
1480: if (!hci_pi(sk)->mtu)
1481: hci_pi(sk)->mtu = HCI_MAX_FRAME_SIZE;
1482:
1483: sk->sk_state = BT_BOUND;
1484:
1485: done:
1486: release_sock(sk);
1487: return err;
1488: }
SourceFile:net/bluetooth/hci_sock.c]
|
| 26/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 34533
output: 34
thoughts: 231
Thoughts: **Tracing the HCI Device Open Call**
Okay, so `hci_dev_open` gets called from `hci_sock_bind` when dealing with the `HCI_CHANNEL_USER` channel. But something doesn't feel right. Let's look at this call trace: I'm seeing `hci_dev_open` from `sock_ioctl`, which goes through `sock_do_ioctl` first. That's a bit strange.
Right, `sock_do_ioctl` can call either `sk->sk_prot->ioctl` or `sock->ops->ioctl`. Now I remember: for Bluetooth sockets with `AF_BLUETOOTH`, `sock->ops->ioctl` is going to be `bt_sock_ioctl`. The problem here is that `bt_sock_ioctl` doesn't include a call to `hci_dev_open`.
I think I need to dig deeper into `sock_do_ioctl` in `net/socket.c` and figure out how this is happening. Let's check that code.
|
| 27/2 |
2026/05/31 10:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/socket.c Name:sock_do_ioctl]
Results: map[SourceCode:1235: static long sock_do_ioctl(struct net *net, struct socket *sock,
1236: unsigned int cmd, unsigned long arg)
1237: {
1238: const struct proto_ops *ops = READ_ONCE(sock->ops);
1239: struct ifreq ifr;
1240: bool need_copyout;
1241: int err;
1242: void __user *argp = (void __user *)arg;
1243: void __user *data;
1244:
1245: err = ops->ioctl(sock, cmd, arg);
1246:
1247: /*
1248: * If this ioctl is unknown try to hand it down
1249: * to the NIC driver.
1250: */
1251: if (err != -ENOIOCTLCMD)
1252: return err;
1253:
1254: if (!is_socket_ioctl_cmd(cmd))
1255: return -ENOTTY;
1256:
1257: if (get_user_ifreq(&ifr, &data, argp))
1258: return -EFAULT;
1259: err = dev_ioctl(net, cmd, &ifr, data, &need_copyout);
1260: if (!err && need_copyout)
1261: if (put_user_ifreq(&ifr, argp))
1262: return -EFAULT;
1263:
1264: return err;
1265: }
SourceFile:net/socket.c]
|
| 28/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 35487
output: 28
thoughts: 731
Thoughts: **Dissecting This Conundrum: IOCTL, Netlink, and HCI**
Okay, so I'm looking at this call trace and immediately my attention is drawn to `ops->ioctl(sock, cmd, arg)`. The intriguing bit is when `ops->ioctl` resolves to `hci_sock_ioctl`, which, as I recall, handles `HCIDEVUP` and subsequently calls `hci_dev_open`. But hold on... the reproducer is calling `ioctl(fd, 0x8933, arg)`. `0x8933` is `SIOCGIFINDEX`, which, typically, deals with network interface indices. That's a red flag! Then, I recalled that `HCIDEVUP` is a completely different IOCTL code: `_IOW('H', 201, int)`, which translates to `0x400448c9`. Definitely not `0x8933`.
I'm examining the provided reproducer, it's making a `SIOCGIFINDEX` call on a netlink socket, which is set up using `syscall(__NR_socket, /*domain=AF_NETLINK*/0x10ul, /*type=SOCK_RAW*/3ul, /*proto=*/0);`. I can see the reproducer then calling `ioctl` on this socket. The perplexing part is that the call trace shows `hci_dev_open` originating from `sock_do_ioctl`, which handles IOCTL calls on a socket. How is `SIOCGIFINDEX` on a netlink socket even remotely connected to `hci_dev_open`?
Ah! Let me think... the code handles `SIOCGIFINDEX` through `dev_ioctl`, but this shouldn't lead to `hci_dev_open`. I'm starting to suspect something. Maybe the provided reproducer isn't the whole story. Syzkaller is a powerful fuzzer, and it often executes multiple programs concurrently. Perhaps another program is running in parallel and is independently triggering `ioctl(HCIDEVUP)` on an HCI socket. The reproducer in hand could be the one that triggered the bug, but perhaps it is a deadlock that is a result of both `hci_dev_open` and another related call that is now blocked.
Okay, let's consider another angle. The trace is suggesting the lock is within `hci_dev_open` and, specifically, maybe blocked on `flush_workqueue(hdev->req_workqueue)`. This implies a work item is running and blocked, which could be the key. What is that work item? I'm going back to the syzkaller reproducer for clues. It's sending a netlink message to configure the `cake` qdisc. Could this `cake` qdisc configuration be blocking something critical that `hci_cmd_sync_work` or another work item on `req_workqueue` is waiting for? Or, is `hci_cmd_sync_work` itself getting blocked on `rtnl_lock`?
I need to figure out if `rtnl_lock` is involved. Let me check the code associated with `hci_cmd_sync_work` or any other work item on `req_workqueue`. I'm going to search for instances of `rtnl_lock` within the `net/bluetooth/` directory to see if there's any contention. This deadlock, I'm thinking, is a classic race condition and figuring out which resources are being contended is the key.
|
| 29/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Args: map[Expression:rtnl_lock PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/6lowpan.c=588=static void ifup(struct net_device *netdev)
--
net/bluetooth/6lowpan.c-591-
net/bluetooth/6lowpan.c:592: rtnl_lock();
net/bluetooth/6lowpan.c-593- err = dev_open(netdev, NULL);
--
net/bluetooth/6lowpan.c=599=static void ifdown(struct net_device *netdev)
net/bluetooth/6lowpan.c-600-{
net/bluetooth/6lowpan.c:601: rtnl_lock();
net/bluetooth/6lowpan.c-602- dev_close(netdev);
]
|
| 30/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 37199
output: 31
thoughts: 22
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Navigating the Bluetooth Stack Dilemma**
Okay, so I'm looking at something Bluetooth-related, and my mind immediately jumps to the low-level networking components. I need to figure out which protocol stack I'm dealing with. Is this related to the BNEP (Bluetooth Network Encapsulation Protocol) layer? Or, more likely given the context, am I working with CMTTP (Connection Manager Transport Protocol)? I need to quickly establish which protocol or sub-protocol I'm using, as they are used in very different situations, to avoid wasted time. Deciding between them changes everything downstream. It impacts my debugging strategy, which data structures I need to focus on, and ultimately how I approach the problem. I need to make the right choice to even begin.
|
| 31/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Error:
Args: map[Expression:rtnl_lock PathPrefix:net/bluetooth/bnep/]
Results:
|
| 32/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 37453
output: 28
thoughts: 25
Thoughts: Here's my thought process, summarized as you requested:
**Revisiting the Bluetooth Lock Search**
Okay, I'm going to take another pass through the `net/bluetooth/` directory. I'm specifically looking for instances of `rtnl_lock`. I could have sworn I'd already been quite thorough, but experience tells me it's always worth a second look, especially when dealing with potentially complex concurrency issues. There's a chance I overlooked something the first time around β perhaps a subtle usage, or a commented-out section that's now relevant. Double-checking is crucial to ensure I haven't missed a critical piece of the puzzle, and that I'm not overlooking a potential point of contention. Better to be certain, given the performance implications.
|
| 33/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Args: map[Expression:rtnl_lock PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/6lowpan.c=588=static void ifup(struct net_device *netdev)
--
net/bluetooth/6lowpan.c-591-
net/bluetooth/6lowpan.c:592: rtnl_lock();
net/bluetooth/6lowpan.c-593- err = dev_open(netdev, NULL);
--
net/bluetooth/6lowpan.c=599=static void ifdown(struct net_device *netdev)
net/bluetooth/6lowpan.c-600-{
net/bluetooth/6lowpan.c:601: rtnl_lock();
net/bluetooth/6lowpan.c-602- dev_close(netdev);
]
|
| 34/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 37864
output: 31
thoughts: 47
Thoughts: **Analyzing the Bluetooth Command Submission Flow**
Okay, so I'm looking at this `hci_cmd_sync_work` function, and it's calling `entry->func(hdev, entry->data)`. That's the key. I need to understand what `entry->func` *actually* is. It's the callback function that's ultimately being executed. What are all the potential functions this could be? I need to get a list. Let's start with searching for `hci_cmd_sync_submit` since that function is probably the one that submits the function.
|
| 35/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Args: map[Expression:hci_cmd_sync_submit PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_sync.c=696=EXPORT_SYMBOL(hci_cmd_sync_cancel_sync);
--
net/bluetooth/hci_sync.c-701- */
net/bluetooth/hci_sync.c:702:int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
net/bluetooth/hci_sync.c-703- void *data, hci_cmd_sync_work_destroy_t destroy)
--
net/bluetooth/hci_sync.c-732-}
net/bluetooth/hci_sync.c:733:EXPORT_SYMBOL(hci_cmd_sync_submit);
net/bluetooth/hci_sync.c-734-
--
net/bluetooth/hci_sync.c=739=int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
--
net/bluetooth/hci_sync.c-747-
net/bluetooth/hci_sync.c:748: return hci_cmd_sync_submit(hdev, func, data, destroy);
net/bluetooth/hci_sync.c-749-}
--
net/bluetooth/hci_sync.c=794=int hci_cmd_sync_run(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
--
net/bluetooth/hci_sync.c-806-
net/bluetooth/hci_sync.c:807: return hci_cmd_sync_submit(hdev, func, data, destroy);
net/bluetooth/hci_sync.c-808-}
--
net/bluetooth/mgmt.c=1390=static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1435- } else {
net/bluetooth/mgmt.c:1436: /* Use hci_cmd_sync_submit since hdev might not be running */
net/bluetooth/mgmt.c:1437: err = hci_cmd_sync_submit(hdev, set_powered_sync, cmd,
net/bluetooth/mgmt.c-1438- mgmt_set_powered_complete);
--
net/bluetooth/mgmt.c=2745=static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2780- /* MGMT_OP_ADD_UUID don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2781: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2782- */
net/bluetooth/mgmt.c:2783: err = hci_cmd_sync_submit(hdev, add_uuid_sync, cmd,
net/bluetooth/mgmt.c-2784- mgmt_class_complete);
--
net/bluetooth/mgmt.c=2820=static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-2878- /* MGMT_OP_REMOVE_UUID don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2879: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2880- */
net/bluetooth/mgmt.c:2881: err = hci_cmd_sync_submit(hdev, remove_uuid_sync, cmd,
net/bluetooth/mgmt.c-2882- mgmt_class_complete);
--
net/bluetooth/mgmt.c=2906=static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-2948- /* MGMT_OP_SET_DEV_CLASS don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2949: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2950- */
net/bluetooth/mgmt.c:2951: err = hci_cmd_sync_submit(hdev, set_class_sync, cmd,
net/bluetooth/mgmt.c-2952- mgmt_class_complete);
--
net/bluetooth/mgmt.c=5617=static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-5637-
net/bluetooth/mgmt.c:5638: err = hci_cmd_sync_submit(hdev, mgmt_remove_adv_monitor_sync, cmd,
net/bluetooth/mgmt.c-5639- mgmt_remove_adv_monitor_complete);
]
|
| 36/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 39320
output: 31
thoughts: 15
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Delving Deeper into the HCI Command Queue**
Okay, so I'm revisiting the HCI command execution flow. I had a good grasp on the typical asynchronous execution, the buffer management, the event signaling... but now I'm seeing `hci_cmd_sync_queue` pop up again. Hmm, not just in the usual places. It's used. That means I need to rethink my mental model of the command flow. I had it somewhat compartmentalized, asynchronous for most operations, synchronous for initialization and a few very specific functions. It seems I need to adjust and revisit where this is happening. The implications are significant; blocking versus non-blocking command execution profoundly affects latency, error handling, and overall system responsiveness. I need to trace back from this usage and ensure my understanding incorporates the nuances of *when* `hci_cmd_sync_queue` is employed and *why*. I have to ensure I haven't missed any key interactions. This could affect my understanding of how a host controller can handle concurrent commands. Time to dig in and re-evaluate my assumptions about command queuing!
|
| 37/2 |
2026/05/31 10:16 |
tool |
grepper |
0m
Args: map[Expression:hci_cmd_sync_queue PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_conn.c=459=bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
--
net/bluetooth/hci_conn.c-471- conn_handle->handle = handle;
net/bluetooth/hci_conn.c:472: result = hci_cmd_sync_queue(conn->hdev, hci_enhanced_setup_sync,
net/bluetooth/hci_conn.c-473- conn_handle, NULL);
--
net/bluetooth/hci_conn.c=721=static int hci_le_terminate_big(struct hci_dev *hdev, struct hci_conn *conn)
--
net/bluetooth/hci_conn.c-736-
net/bluetooth/hci_conn.c:737: ret = hci_cmd_sync_queue(hdev, terminate_big_sync, d,
net/bluetooth/hci_conn.c-738- terminate_big_destroy);
--
net/bluetooth/hci_conn.c=772=static int hci_le_big_terminate(struct hci_dev *hdev, struct hci_conn *conn)
--
net/bluetooth/hci_conn.c-808-
net/bluetooth/hci_conn.c:809: ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
net/bluetooth/hci_conn.c-810- terminate_big_destroy);
--
net/bluetooth/hci_conn.c=871=static int hci_le_remove_cig(struct hci_dev *hdev, u8 handle)
--
net/bluetooth/hci_conn.c-874-
net/bluetooth/hci_conn.c:875: return hci_cmd_sync_queue(hdev, remove_cig_sync, UINT_PTR(handle),
net/bluetooth/hci_conn.c-876- NULL);
--
net/bluetooth/hci_conn.c=1889=static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos)
--
net/bluetooth/hci_conn.c-1940-done:
net/bluetooth/hci_conn.c:1941: if (hci_cmd_sync_queue(hdev, set_cig_params_sync,
net/bluetooth/hci_conn.c-1942- UINT_PTR(qos->ucast.cig), NULL) < 0)
--
net/bluetooth/hci_conn.c=2066=int hci_le_create_cis_pending(struct hci_dev *hdev)
--
net/bluetooth/hci_conn.c-2088- /* Queue Create CIS */
net/bluetooth/hci_conn.c:2089: return hci_cmd_sync_queue(hdev, hci_create_cis_sync, NULL, NULL);
net/bluetooth/hci_conn.c-2090-}
--
net/bluetooth/hci_conn.c=2287=struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
--
net/bluetooth/hci_conn.c-2327- /* Queue start periodic advertising and create BIG */
net/bluetooth/hci_conn.c:2328: err = hci_cmd_sync_queue(hdev, create_big_sync, conn,
net/bluetooth/hci_conn.c-2329- create_big_complete);
--
net/bluetooth/hci_event.c=7010=static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
--
net/bluetooth/hci_event.c-7051- */
net/bluetooth/hci_event.c:7052: hci_cmd_sync_queue(hdev, hci_iso_term_big_sync,
net/bluetooth/hci_event.c-7053- UINT_PTR(ev->handle), NULL);
--
net/bluetooth/hci_sync.c=364=static void le_scan_disable(struct work_struct *work)
--
net/bluetooth/hci_sync.c-375-
net/bluetooth/hci_sync.c:376: status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL);
net/bluetooth/hci_sync.c-377- if (status) {
--
net/bluetooth/hci_sync.c-403-
net/bluetooth/hci_sync.c:404: status = hci_cmd_sync_queue(hdev, interleaved_inquiry_sync, NULL, NULL);
net/bluetooth/hci_sync.c-405- if (status) {
--
net/bluetooth/hci_sync.c=447=static void reenable_adv(struct work_struct *work)
--
net/bluetooth/hci_sync.c-456-
net/bluetooth/hci_sync.c:457: status = hci_cmd_sync_queue(hdev, reenable_adv_sync, NULL, NULL);
net/bluetooth/hci_sync.c-458- if (status)
--
net/bluetooth/hci_sync.c=553=static void adv_timeout_expire(struct work_struct *work)
--
net/bluetooth/hci_sync.c-572- *inst_ptr = hdev->cur_adv_instance;
net/bluetooth/hci_sync.c:573: hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL);
net/bluetooth/hci_sync.c-574-
--
net/bluetooth/hci_sync.c=733=EXPORT_SYMBOL(hci_cmd_sync_submit);
--
net/bluetooth/hci_sync.c-738- */
net/bluetooth/hci_sync.c:739:int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
net/bluetooth/hci_sync.c-740- void *data, hci_cmd_sync_work_destroy_t destroy)
--
net/bluetooth/hci_sync.c-749-}
net/bluetooth/hci_sync.c:750:EXPORT_SYMBOL(hci_cmd_sync_queue);
net/bluetooth/hci_sync.c-751-
--
net/bluetooth/hci_sync.c=753=_hci_cmd_sync_lookup_entry(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
--
net/bluetooth/hci_sync.c-778- */
net/bluetooth/hci_sync.c:779:int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
net/bluetooth/hci_sync.c-780- void *data, hci_cmd_sync_work_destroy_t destroy)
--
net/bluetooth/hci_sync.c-784-
net/bluetooth/hci_sync.c:785: return hci_cmd_sync_queue(hdev, func, data, destroy);
net/bluetooth/hci_sync.c-786-}
net/bluetooth/hci_sync.c:787:EXPORT_SYMBOL(hci_cmd_sync_queue_once);
net/bluetooth/hci_sync.c-788-
--
net/bluetooth/hci_sync.c=1912=int hci_enable_advertising(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-1917-
net/bluetooth/hci_sync.c:1918: return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL);
net/bluetooth/hci_sync.c-1919-}
--
net/bluetooth/hci_sync.c=3246=int hci_update_scan(struct hci_dev *hdev)
net/bluetooth/hci_sync.c-3247-{
net/bluetooth/hci_sync.c:3248: return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL);
net/bluetooth/hci_sync.c-3249-}
--
net/bluetooth/hci_sync.c=3256=int hci_update_passive_scan(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-3266-
net/bluetooth/hci_sync.c:3267: return hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL,
net/bluetooth/hci_sync.c-3268- NULL);
--
net/bluetooth/hci_sync.c=5881=int hci_update_discoverable(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-5887- hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY))
net/bluetooth/hci_sync.c:5888: return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL,
net/bluetooth/hci_sync.c-5889- NULL);
--
net/bluetooth/hci_sync.c=6862=int hci_update_adv_data(struct hci_dev *hdev, u8 instance)
net/bluetooth/hci_sync.c-6863-{
net/bluetooth/hci_sync.c:6864: return hci_cmd_sync_queue(hdev, _update_adv_data_sync,
net/bluetooth/hci_sync.c-6865- UINT_PTR(instance), NULL);
--
net/bluetooth/hci_sync.c=6929=int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn)
net/bluetooth/hci_sync.c-6930-{
net/bluetooth/hci_sync.c:6931: return hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn,
net/bluetooth/hci_sync.c-6932- NULL);
--
net/bluetooth/hci_sync.c=6966=int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn)
net/bluetooth/hci_sync.c-6967-{
net/bluetooth/hci_sync.c:6968: return hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn,
net/bluetooth/hci_sync.c-6969- create_le_conn_complete);
--
net/bluetooth/hci_sync.c=7174=int hci_connect_pa_sync(struct hci_dev *hdev, struct hci_conn *conn)
net/bluetooth/hci_sync.c-7175-{
net/bluetooth/hci_sync.c:7176: return hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn,
net/bluetooth/hci_sync.c-7177- create_pa_complete);
--
net/bluetooth/hci_sync.c=7237=int hci_connect_big_sync(struct hci_dev *hdev, struct hci_conn *conn)
net/bluetooth/hci_sync.c-7238-{
net/bluetooth/hci_sync.c:7239: return hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn,
net/bluetooth/hci_sync.c-7240- create_big_complete);
--
net/bluetooth/hci_sync.c=7303=int hci_past_sync(struct hci_conn *conn, struct hci_conn *le)
--
net/bluetooth/hci_sync.c-7321- if (conn->role == HCI_ROLE_MASTER)
net/bluetooth/hci_sync.c:7322: err = hci_cmd_sync_queue_once(conn->hdev,
net/bluetooth/hci_sync.c-7323- hci_le_past_set_info_sync, data,
--
net/bluetooth/hci_sync.c-7325- else
net/bluetooth/hci_sync.c:7326: err = hci_cmd_sync_queue_once(conn->hdev, hci_le_past_sync,
net/bluetooth/hci_sync.c-7327- data, past_complete);
--
net/bluetooth/hci_sync.c=7397=int hci_le_read_remote_features(struct hci_conn *conn)
--
net/bluetooth/hci_sync.c-7411- if (conn->out || (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES))
net/bluetooth/hci_sync.c:7412: err = hci_cmd_sync_queue_once(hdev,
net/bluetooth/hci_sync.c-7413- hci_le_read_remote_features_sync,
--
net/bluetooth/iso.c=1563=static void iso_conn_big_sync(struct sock *sk)
--
net/bluetooth/iso.c-1575- * it enqueues the HCI LE BIG Create Sync command via
net/bluetooth/iso.c:1576: * hci_cmd_sync_queue_once, which checks hdev flags that might
net/bluetooth/iso.c-1577- * change.
--
net/bluetooth/mgmt.c=1009=static void service_cache_off(struct work_struct *work)
--
net/bluetooth/mgmt.c-1016-
net/bluetooth/mgmt.c:1017: hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL);
net/bluetooth/mgmt.c-1018-}
--
net/bluetooth/mgmt.c=1032=static void rpa_expired(struct work_struct *work)
--
net/bluetooth/mgmt.c-1043-
net/bluetooth/mgmt.c:1044: hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL);
net/bluetooth/mgmt.c-1045-}
--
net/bluetooth/mgmt.c=1049=static void discov_off(struct work_struct *work)
--
net/bluetooth/mgmt.c-1066-
net/bluetooth/mgmt.c:1067: hci_cmd_sync_queue(hdev, set_discoverable_sync, NULL, NULL);
net/bluetooth/mgmt.c-1068-
--
net/bluetooth/mgmt.c=1105=static void mesh_next(struct hci_dev *hdev, void *data, int err)
--
net/bluetooth/mgmt.c-1111-
net/bluetooth/mgmt.c:1112: err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx,
net/bluetooth/mgmt.c-1113- mesh_send_start_complete);
--
net/bluetooth/mgmt.c=1121=static void mesh_send_done(struct work_struct *work)
--
net/bluetooth/mgmt.c-1128-
net/bluetooth/mgmt.c:1129: hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next);
net/bluetooth/mgmt.c-1130-}
--
net/bluetooth/mgmt.c=1390=static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1432- hci_cmd_sync_cancel_sync(hdev, -EHOSTDOWN);
net/bluetooth/mgmt.c:1433: err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd,
net/bluetooth/mgmt.c-1434- mgmt_set_powered_complete);
--
net/bluetooth/mgmt.c=1572=static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1693-
net/bluetooth/mgmt.c:1694: err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd,
net/bluetooth/mgmt.c-1695- mgmt_set_discoverable_complete);
--
net/bluetooth/mgmt.c=1772=static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1820-
net/bluetooth/mgmt.c:1821: err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd,
net/bluetooth/mgmt.c-1822- mgmt_set_connectable_complete);
--
net/bluetooth/mgmt.c=2012=static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2070- else
net/bluetooth/mgmt.c:2071: err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd,
net/bluetooth/mgmt.c-2072- set_ssp_complete);
--
net/bluetooth/mgmt.c=2242=static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2282- else
net/bluetooth/mgmt.c:2283: err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd,
net/bluetooth/mgmt.c-2284- set_mesh_complete);
--
net/bluetooth/mgmt.c=2437=static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-2456- else
net/bluetooth/mgmt.c:2457: err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL);
net/bluetooth/mgmt.c-2458-
--
net/bluetooth/mgmt.c=2471=static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2507- else if (!sending)
net/bluetooth/mgmt.c:2508: err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx,
net/bluetooth/mgmt.c-2509- mesh_send_start_complete);
--
net/bluetooth/mgmt.c=2532=static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2604- else
net/bluetooth/mgmt.c:2605: err = hci_cmd_sync_queue(hdev, set_le_sync, cmd,
net/bluetooth/mgmt.c-2606- set_le_complete);
--
net/bluetooth/mgmt.c=2649=static int mgmt_hci_cmd_sync(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-2665- else
net/bluetooth/mgmt.c:2666: err = hci_cmd_sync_queue(hdev, send_hci_cmd_sync, cmd, NULL);
net/bluetooth/mgmt.c-2667-
--
net/bluetooth/mgmt.c=2745=static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-2780- /* MGMT_OP_ADD_UUID don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2781: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2782- */
--
net/bluetooth/mgmt.c=2820=static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-2878- /* MGMT_OP_REMOVE_UUID don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2879: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2880- */
--
net/bluetooth/mgmt.c=2906=static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-2948- /* MGMT_OP_SET_DEV_CLASS don't require adapter the UP/Running so use
net/bluetooth/mgmt.c:2949: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
net/bluetooth/mgmt.c-2950- */
--
net/bluetooth/mgmt.c=3102=static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-3220-
net/bluetooth/mgmt.c:3221: err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd,
net/bluetooth/mgmt.c-3222- unpair_device_complete);
--
net/bluetooth/mgmt.c=3263=static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-3298-
net/bluetooth/mgmt.c:3299: err = hci_cmd_sync_queue(hdev, disconnect_sync, cmd,
net/bluetooth/mgmt.c-3300- disconnect_complete);
--
net/bluetooth/mgmt.c=3941=static void set_name_complete(struct hci_dev *hdev, void *data, int err)
--
net/bluetooth/mgmt.c-3961- if (hci_dev_test_flag(hdev, HCI_LE_ADV))
net/bluetooth/mgmt.c:3962: hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL);
net/bluetooth/mgmt.c-3963- }
--
net/bluetooth/mgmt.c=3998=static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-4040- else
net/bluetooth/mgmt.c:4041: err = hci_cmd_sync_queue(hdev, set_name_sync, cmd,
net/bluetooth/mgmt.c-4042- set_name_complete);
--
net/bluetooth/mgmt.c=4066=static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-4086- if (hci_dev_test_flag(hdev, HCI_LE_ADV))
net/bluetooth/mgmt.c:4087: hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL,
net/bluetooth/mgmt.c-4088- NULL);
--
net/bluetooth/mgmt.c=4211=static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-4321- else
net/bluetooth/mgmt.c:4322: err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd,
net/bluetooth/mgmt.c-4323- set_default_phy_complete);
--
net/bluetooth/mgmt.c=5398=static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-5423- cmd->user_data = m;
net/bluetooth/mgmt.c:5424: err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd,
net/bluetooth/mgmt.c-5425- mgmt_add_adv_patterns_monitor_complete);
--
net/bluetooth/mgmt.c=5746=static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-5771- else
net/bluetooth/mgmt.c:5772: err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd,
net/bluetooth/mgmt.c-5773- read_local_oob_data_complete);
--
net/bluetooth/mgmt.c=5985=static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-6041-
net/bluetooth/mgmt.c:6042: err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd,
net/bluetooth/mgmt.c-6043- start_discovery_complete);
--
net/bluetooth/mgmt.c=6071=static int start_service_discovery(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-6168-
net/bluetooth/mgmt.c:6169: err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd,
net/bluetooth/mgmt.c-6170- start_discovery_complete);
--
net/bluetooth/mgmt.c=6208=static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-6238-
net/bluetooth/mgmt.c:6239: err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd,
net/bluetooth/mgmt.c-6240- stop_discovery_complete);
--
net/bluetooth/mgmt.c=6372=static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-6396-
net/bluetooth/mgmt.c:6397: hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL);
net/bluetooth/mgmt.c-6398-
--
net/bluetooth/mgmt.c=6510=static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-6583- else
net/bluetooth/mgmt.c:6584: err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd,
net/bluetooth/mgmt.c-6585- set_advertising_complete);
--
net/bluetooth/mgmt.c=6721=static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-6759- else
net/bluetooth/mgmt.c:6760: err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd,
net/bluetooth/mgmt.c-6761- fast_connectable_complete);
--
net/bluetooth/mgmt.c=6818=static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
--
net/bluetooth/mgmt.c-6895- else
net/bluetooth/mgmt.c:6896: err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd,
net/bluetooth/mgmt.c-6897- set_bredr_complete);
--
net/bluetooth/mgmt.c=6968=static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-7033- else
net/bluetooth/mgmt.c:7034: err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd,
net/bluetooth/mgmt.c-7035- set_secure_conn_complete);
--
net/bluetooth/mgmt.c=7419=static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-7479- } else {
net/bluetooth/mgmt.c:7480: err = hci_cmd_sync_queue(hdev, get_conn_info_sync,
net/bluetooth/mgmt.c-7481- cmd, get_conn_info_complete);
--
net/bluetooth/mgmt.c=7563=static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-7609- else
net/bluetooth/mgmt.c:7610: err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd,
net/bluetooth/mgmt.c-7611- get_clock_info_complete);
--
net/bluetooth/mgmt.c=7667=static int add_device(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-7752-
net/bluetooth/mgmt.c:7753: err = hci_cmd_sync_queue(hdev, add_device_sync, cmd,
net/bluetooth/mgmt.c-7754- add_device_complete);
--
net/bluetooth/mgmt.c=7795=static int remove_device(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-7907-
net/bluetooth/mgmt.c:7908: hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL);
net/bluetooth/mgmt.c-7909-
--
net/bluetooth/mgmt.c=7931=static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-8038- conn->le_supv_timeout != timeout))
net/bluetooth/mgmt.c:8039: hci_cmd_sync_queue(hdev, conn_update_sync,
net/bluetooth/mgmt.c-8040- hci_param, NULL);
--
net/bluetooth/mgmt.c=8278=static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk,
--
net/bluetooth/mgmt.c-8288-
net/bluetooth/mgmt.c:8289: err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd,
net/bluetooth/mgmt.c-8290- read_local_oob_ext_data_complete);
--
net/bluetooth/mgmt.c=8734=static int add_advertising(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-8857-
net/bluetooth/mgmt.c:8858: err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd,
net/bluetooth/mgmt.c-8859- add_advertising_complete);
--
net/bluetooth/mgmt.c=8927=static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-9022-
net/bluetooth/mgmt.c:9023: err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd,
net/bluetooth/mgmt.c-9024- add_ext_adv_params_complete);
--
net/bluetooth/mgmt.c=9086=static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-9178-
net/bluetooth/mgmt.c:9179: err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd,
net/bluetooth/mgmt.c-9180- add_ext_adv_data_complete);
--
net/bluetooth/mgmt.c=9243=static int remove_advertising(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-9279-
net/bluetooth/mgmt.c:9280: err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd,
net/bluetooth/mgmt.c-9281- remove_advertising_complete);
--
net/bluetooth/msft.c=927=static struct msft_monitor_addr_filter_data *msft_add_address_filter
--
net/bluetooth/msft.c-955-
net/bluetooth/msft.c:956: err = hci_cmd_sync_queue(hdev, msft_add_address_filter_sync,
net/bluetooth/msft.c-957- address_filter, NULL);
--
net/bluetooth/msft.c=972=static void msft_monitor_device_evt(struct hci_dev *hdev, struct sk_buff *skb)
--
net/bluetooth/msft.c-1058- address_filter->state = AF_STATE_REMOVING;
net/bluetooth/msft.c:1059: hci_cmd_sync_queue(hdev,
net/bluetooth/msft.c-1060- msft_cancel_address_filter_sync,
]
|
| 38/2 |
2026/05/31 10:16 |
llm |
expert |
0m
Model:
Tokens:
input: 48278
output: 38
thoughts: 633
Thoughts: **Debugging a Bluetooth Device Hang**
Okay, so I'm looking at this Bluetooth driver code, and I've got a task that's blocked for a *way* longer time than I'd expect. `hci_cmd_sync_work` is the culprit, and it seems to be blocking. The critical point is that this function runs `entry->func` while holding `hci_req_sync_lock(hdev)`. So, if `entry->func` blocks, `hci_cmd_sync_work` blocks too.
My initial thought is that `entry->func` is probably waiting for a completion, likely an HCI command response. Something like `__hci_cmd_sync_skb` might be involved, which sends a command and waits for an event. The default timeout is pretty reasonable, at around 2 seconds, `HCI_CMD_TIMEOUT`. But it's blocked for *152* seconds, so it's clearly not just a standard timeout.
My next hunch is a mutex or a lock. Maybe `entry->func` is calling something that's taking `rtnl_lock` or something similar, and that's causing the deadlock. Let's see if something like `set_powered_sync` or related functions is the problem.
Alright, now I'm starting to see a possible path. `hci_dev_open` is called from `hci_sock_ioctl(HCIDEVUP)`. So when the user space calls the `HCIDEVUP` ioctl, it calls `hci_dev_open`. And `hci_dev_open` calls `flush_workqueue(hdev->req_workqueue)`. I need to figure out how this is involved with the lock!
One scenario that comes to mind is that `req_workqueue` contains a work item that is waiting on `hdev->lock`, and then it gets flushed by `hci_dev_open`, leading to a race. No, this can't be, because `hci_dev_open` *doesn't* hold `hdev->lock` when it calls `flush_workqueue`. And `hci_sock_ioctl` doesn't either. The `sock_do_ioctl` function doesn't seem to hold any locks, either.
Hang on...`hci_dev_open` *does* call `flush_workqueue(hdev->req_workqueue)`. If `req_workqueue` is running `hci_cmd_sync_work`, and `hci_cmd_sync_work` is waiting on `hdev->req_sync_lock`? But `hci_dev_open` *still* doesn't hold `hdev->req_sync_lock` when calling `flush_workqueue`! This looks like a race condition!
I need to see what's getting queued to that `req_workqueue`. What if the queue has an item with `hdev->power_on` waiting to run? And the `hdev->power_on` work runs `hci_power_on`.
|
| 39/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c Name:hci_power_on]
Results: map[SourceCode: 943: static void hci_power_on(struct work_struct *work)
944: {
945: struct hci_dev *hdev = container_of(work, struct hci_dev, power_on);
946: int err;
947:
948: BT_DBG("%s", hdev->name);
949:
950: if (test_bit(HCI_UP, &hdev->flags) &&
951: hci_dev_test_flag(hdev, HCI_MGMT) &&
952: hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {
953: cancel_delayed_work(&hdev->power_off);
954: err = hci_powered_update_sync(hdev);
955: mgmt_power_on(hdev, err);
956: return;
957: }
958:
959: err = hci_dev_do_open(hdev);
960: if (err < 0) {
961: hci_dev_lock(hdev);
962: mgmt_set_powered_failed(hdev, err);
963: hci_dev_unlock(hdev);
964: return;
965: }
966:
967: /* During the HCI setup phase, a few error conditions are
968: * ignored and they need to be checked now. If they are still
969: * valid, it is important to turn the device back off.
970: */
971: if (hci_dev_test_flag(hdev, HCI_RFKILLED) ||
972: hci_dev_test_flag(hdev, HCI_UNCONFIGURED) ||
973: (!bacmp(&hdev->bdaddr, BDADDR_ANY) &&
974: !bacmp(&hdev->static_addr, BDADDR_ANY))) {
975: hci_dev_clear_flag(hdev, HCI_AUTO_OFF);
976: hci_dev_do_close(hdev);
977: } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
978: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
979: HCI_AUTO_OFF_TIMEOUT);
980: }
981:
982: if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) {
983: /* For unconfigured devices, set the HCI_RAW flag
984: * so that userspace can easily identify them.
985: */
986: if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
987: set_bit(HCI_RAW, &hdev->flags);
988:
989: /* For fully configured devices, this will send
990: * the Index Added event. For unconfigured devices,
991: * it will send Unconfigued Index Added event.
992: *
993: * Devices with HCI_QUIRK_RAW_DEVICE are ignored
994: * and no event will be send.
995: */
996: mgmt_index_added(hdev);
997: } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) {
998: /* When the controller is now configured, then it
999: * is important to clear the HCI_RAW flag.
1000: */
1001: if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
1002: clear_bit(HCI_RAW, &hdev->flags);
1003:
1004: /* Powering on the controller with HCI_CONFIG set only
1005: * happens with the transition from unconfigured to
1006: * configured. This will send the Index Added event.
1007: */
1008: mgmt_index_added(hdev);
1009: }
1010: }
SourceFile:net/bluetooth/hci_core.c]
|
| 40/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 50789
output: 38
thoughts: 398
Thoughts: **Analyzing Potential Race Conditions in Bluetooth Device Power-On**
Okay, let's break this down systematically. I'm looking at the interaction between `hci_power_on` and `hci_dev_open`, specifically concerning potential race conditions. I see that `hci_power_on` gets scheduled on `hdev->req_workqueue`. It then calls `hci_dev_do_open(hdev)`.
The crucial point here is that `hci_dev_do_open` acquires `hci_req_sync_lock(hdev)`. My immediate concern is concurrent calls to `hci_dev_open`. If that happens while `hci_power_on` is running, there could be a problem.
Now, I recall that `hci_dev_open` uses `flush_workqueue(hdev->req_workqueue)`. If `hci_power_on` is *currently* running on that workqueue, `flush_workqueue` will correctly wait for it to finish. But, and this is the important part, `hci_power_on` *itself* calls `hci_dev_do_open`, which *also* grabs `hci_req_sync_lock(hdev)`. The critical check here is that `hci_dev_open` doesn't hold `hci_req_sync_lock` when it calls `flush_workqueue`. *That's good*, so `hci_power_on` can acquire the lock, finish, and the flush will then complete. We're safe there.
Alright, but there is still other concurrent issues to check for. The call path to `hci_dev_open` is `sock_do_ioctl` -> `hci_sock_ioctl`. So the next question is what locks are held during the `hci_dev_open` calls from `hci_sock_ioctl`. Let's dig deeper:
Inside `hci_sock_ioctl`, a switch statement handles different commands, and I see that for some commands the function calls `lock_sock(sk)`. But it looks like, for the `HCIDEVUP` command which eventually calls `hci_dev_open`, it DOES NOT hold this lock, and I can be sure to check that! It looks like lock is called BEFORE the switch statement, so all calls will lock and unlock the socket before calling into `hci_dev_open`.
I think that should be a safe implementation.
|
| 41/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sock.c Name:hci_sock_ioctl]
Results: map[SourceCode:1043: static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
1044: unsigned long arg)
1045: {
1046: void __user *argp = (void __user *)arg;
1047: struct sock *sk = sock->sk;
1048: int err;
1049:
1050: BT_DBG("cmd %x arg %lx", cmd, arg);
1051:
1052: /* Make sure the cmd is valid before doing anything */
1053: switch (cmd) {
1054: case HCIGETDEVLIST:
1055: case HCIGETDEVINFO:
1056: case HCIGETCONNLIST:
1057: case HCIDEVUP:
1058: case HCIDEVDOWN:
1059: case HCIDEVRESET:
1060: case HCIDEVRESTAT:
1061: case HCISETSCAN:
1062: case HCISETAUTH:
1063: case HCISETENCRYPT:
1064: case HCISETPTYPE:
1065: case HCISETLINKPOL:
1066: case HCISETLINKMODE:
1067: case HCISETACLMTU:
1068: case HCISETSCOMTU:
1069: case HCIINQUIRY:
1070: case HCISETRAW:
1071: case HCIGETCONNINFO:
1072: case HCIGETAUTHINFO:
1073: case HCIBLOCKADDR:
1074: case HCIUNBLOCKADDR:
1075: break;
1076: default:
1077: return -ENOIOCTLCMD;
1078: }
1079:
1080: lock_sock(sk);
1081:
1082: if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
1083: err = -EBADFD;
1084: goto done;
1085: }
1086:
1087: /* When calling an ioctl on an unbound raw socket, then ensure
1088: * that the monitor gets informed. Ensure that the resulting event
1089: * is only send once by checking if the cookie exists or not. The
1090: * socket cookie will be only ever generated once for the lifetime
1091: * of a given socket.
1092: */
1093: if (hci_sock_gen_cookie(sk)) {
1094: struct sk_buff *skb;
1095:
1096: /* Perform careful checks before setting the HCI_SOCK_TRUSTED
1097: * flag. Make sure that not only the current task but also
1098: * the socket opener has the required capability, since
1099: * privileged programs can be tricked into making ioctl calls
1100: * on HCI sockets, and the socket should not be marked as
1101: * trusted simply because the ioctl caller is privileged.
1102: */
1103: if (sk_capable(sk, CAP_NET_ADMIN))
1104: hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
1105:
1106: /* Send event to monitor */
1107: skb = create_monitor_ctrl_open(sk);
1108: if (skb) {
1109: hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
1110: HCI_SOCK_TRUSTED, NULL);
1111: kfree_skb(skb);
1112: }
1113: }
1114:
1115: release_sock(sk);
1116:
1117: switch (cmd) {
1118: case HCIGETDEVLIST:
1119: return hci_get_dev_list(argp);
1120:
1121: case HCIGETDEVINFO:
1122: return hci_get_dev_info(argp);
1123:
1124: case HCIGETCONNLIST:
1125: return hci_get_conn_list(argp);
1126:
1127: case HCIDEVUP:
1128: if (!capable(CAP_NET_ADMIN))
1129: return -EPERM;
1130: return hci_dev_open(arg);
1131:
1132: case HCIDEVDOWN:
1133: if (!capable(CAP_NET_ADMIN))
1134: return -EPERM;
1135: return hci_dev_close(arg);
1136:
1137: case HCIDEVRESET:
1138: if (!capable(CAP_NET_ADMIN))
1139: return -EPERM;
1140: return hci_dev_reset(arg);
1141:
1142: case HCIDEVRESTAT:
1143: if (!capable(CAP_NET_ADMIN))
1144: return -EPERM;
1145: return hci_dev_reset_stat(arg);
1146:
1147: case HCISETSCAN:
1148: case HCISETAUTH:
1149: case HCISETENCRYPT:
1150: case HCISETPTYPE:
1151: case HCISETLINKPOL:
1152: case HCISETLINKMODE:
1153: case HCISETACLMTU:
1154: case HCISETSCOMTU:
1155: if (!capable(CAP_NET_ADMIN))
1156: return -EPERM;
1157: return hci_dev_cmd(cmd, argp);
1158:
1159: case HCIINQUIRY:
1160: return hci_inquiry(argp);
1161: }
1162:
1163: lock_sock(sk);
1164:
1165: err = hci_sock_bound_ioctl(sk, cmd, arg);
1166:
1167: done:
1168: release_sock(sk);
1169: return err;
1170: }
SourceFile:net/bluetooth/hci_sock.c]
|
| 42/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 53507
output: 40
thoughts: 700
Thoughts: **Analyzing Potential Concurrency Issues in HCI Device Opening**
Okay, so I'm looking at this Bluetooth stack code, specifically the `hci_dev_open` function. My initial observation is that `lock_sock(sk)` is called, but then `release_sock(sk)` happens *before* a crucial second switch. That means `hci_dev_open` is executed without the protection of `lock_sock(sk)`. This immediately raises a red flag: what if `hci_dev_open` is called concurrently with itself?
Let's dive deeper. `hci_dev_open` itself does a few interesting things. It checks flags like `HCI_UNCONFIGURED` and `HCI_USER_CHANNEL`, clears `HCI_AUTO_OFF` if set, and importantly, it calls `flush_workqueue(hdev->req_workqueue)`. Both threads would call `flush_workqueue(hdev->req_workqueue)`. Then, both threads would proceed to call `hci_dev_do_open(hdev)`. And that's where things get interesting because `hci_dev_do_open` takes `hci_req_sync_lock(hdev)`.
Now, the potential for a deadlock emerges. Let's say `hci_power_on` is running on `req_workqueue` simultaneously. Now `hci_power_on` can, and probably does, call `hci_dev_do_open(hdev)`. And because `hci_power_on` calls `hci_dev_do_open(hdev)` it will also take `hci_req_sync_lock(hdev)`.
So, what if a thread calls `hci_dev_open` and that then calls `flush_workqueue(hdev->req_workqueue)`? `flush_workqueue` *should* wait for `hci_power_on` to finish, right? But `hci_power_on` calls `hci_dev_do_open(hdev)`, which takes `hci_req_sync_lock(hdev)`. Wait... hang on. `hci_power_on` *doesn't* hold any locks initially. It just calls `hci_dev_do_open(hdev)`.
Ah, I think I see it. `hci_power_on` will complete without any contention, and then `flush_workqueue` will return. And then finally, the concurrent call to `hci_dev_open` will continue and call `hci_dev_do_open(hdev)`. So far, this seems safe.
But, I need to be absolutely sure. What if `hci_dev_do_open` itself queues a work item on `req_workqueue` and then blocks waiting for it? I need to analyze the `hci_dev_do_open` and `hci_dev_open_sync` code to make sure there are no such conditions. It's time to dig deeper and confirm my understanding.
|
| 43/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_dev_open_sync]
Results: map[SourceCode:5102: int hci_dev_open_sync(struct hci_dev *hdev)
5103: {
5104: int ret;
5105:
5106: bt_dev_dbg(hdev, "");
5107:
5108: if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
5109: ret = -ENODEV;
5110: goto done;
5111: }
5112:
5113: if (!hci_dev_test_flag(hdev, HCI_SETUP) &&
5114: !hci_dev_test_flag(hdev, HCI_CONFIG)) {
5115: /* Check for rfkill but allow the HCI setup stage to
5116: * proceed (which in itself doesn't cause any RF activity).
5117: */
5118: if (hci_dev_test_flag(hdev, HCI_RFKILLED)) {
5119: ret = -ERFKILL;
5120: goto done;
5121: }
5122:
5123: /* Check for valid public address or a configured static
5124: * random address, but let the HCI setup proceed to
5125: * be able to determine if there is a public address
5126: * or not.
5127: *
5128: * In case of user channel usage, it is not important
5129: * if a public address or static random address is
5130: * available.
5131: */
5132: if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
5133: !bacmp(&hdev->bdaddr, BDADDR_ANY) &&
5134: !bacmp(&hdev->static_addr, BDADDR_ANY)) {
5135: ret = -EADDRNOTAVAIL;
5136: goto done;
5137: }
5138: }
5139:
5140: if (test_bit(HCI_UP, &hdev->flags)) {
5141: ret = -EALREADY;
5142: goto done;
5143: }
5144:
5145: if (hdev->open(hdev)) {
5146: ret = -EIO;
5147: goto done;
5148: }
5149:
5150: hci_devcd_reset(hdev);
5151:
5152: set_bit(HCI_RUNNING, &hdev->flags);
5153: hci_sock_dev_event(hdev, HCI_DEV_OPEN);
5154:
5155: ret = hci_dev_init_sync(hdev);
5156: if (!ret) {
5157: hci_dev_hold(hdev);
5158: hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
5159: hci_adv_instances_set_rpa_expired(hdev, true);
5160: set_bit(HCI_UP, &hdev->flags);
5161: hci_sock_dev_event(hdev, HCI_DEV_UP);
5162: hci_leds_update_powered(hdev, true);
5163: if (!hci_dev_test_flag(hdev, HCI_SETUP) &&
5164: !hci_dev_test_flag(hdev, HCI_CONFIG) &&
5165: !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&
5166: !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
5167: hci_dev_test_flag(hdev, HCI_MGMT)) {
5168: ret = hci_powered_update_sync(hdev);
5169: mgmt_power_on(hdev, ret);
5170: }
5171: } else {
5172: /* Init failed, cleanup */
5173: flush_work(&hdev->tx_work);
5174:
5175: /* Since hci_rx_work() is possible to awake new cmd_work
5176: * it should be flushed first to avoid unexpected call of
5177: * hci_cmd_work()
5178: */
5179: flush_work(&hdev->rx_work);
5180: flush_work(&hdev->cmd_work);
5181:
5182: skb_queue_purge(&hdev->cmd_q);
5183: skb_queue_purge(&hdev->rx_q);
5184:
5185: if (hdev->flush)
5186: hdev->flush(hdev);
5187:
5188: if (hdev->sent_cmd) {
5189: cancel_delayed_work_sync(&hdev->cmd_timer);
5190: kfree_skb(hdev->sent_cmd);
5191: hdev->sent_cmd = NULL;
5192: }
5193:
5194: if (hdev->req_skb) {
5195: kfree_skb(hdev->req_skb);
5196: hdev->req_skb = NULL;
5197: }
5198:
5199: clear_bit(HCI_RUNNING, &hdev->flags);
5200: hci_sock_dev_event(hdev, HCI_DEV_CLOSE);
5201:
5202: hdev->close(hdev);
5203: hdev->flags &= BIT(HCI_RAW);
5204: }
5205:
5206: done:
5207: return ret;
5208: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 44/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 56550
output: 40
thoughts: 524
Thoughts: **Analyzing the Bluetooth HCI Device Open/Close Race Condition**
Okay, let's break this down. My initial thought is that `hci_dev_open_sync` calls the driver's open function, `hdev->open`. Right, so for `vhci`, that's `vhci_open`; for `hci_uart`, it's `hci_uart_open`. The reproducer uses `vhci`, which is key. The reproducer doesn't explicitly show `vhci` setup, but Syzkaller *usually* handles that. So I'm assuming `vhci` is in play here.
If `hdev->open` blocks, then `hci_dev_open_sync` blocks. Now, I see that the block is in `flush_workqueue(hdev->req_workqueue)` within `hci_dev_open`. That means `flush_workqueue` is waiting for a work item on that queue to complete. We need to identify that work item.
Looking at the code, `hci_cmd_sync_work` is the most likely candidate. It takes `hci_req_sync_lock(hdev)`. If `hci_cmd_sync_work` is running, it will try to acquire that lock. If another thread already holds that `hci_req_sync_lock(hdev)`, then `hci_cmd_sync_work` will block. So, who could be holding it?
Hmm... other threads calling `hci_dev_do_open`, `hci_dev_do_close`, or `hci_dev_do_reset` are the obvious candidates. But wait, `hci_dev_do_open` *does* hold that lock, and it's called from `hci_dev_open`, which FIRST calls `flush_workqueue(hdev->req_workqueue)`.
So, `hci_dev_open` does this:
1. `flush_workqueue(hdev->req_workqueue)`
2. `hci_req_sync_lock(hdev)` (inside `hci_dev_do_open`)
I'm starting to see a race. What if another thread calls `hci_dev_do_close` concurrently? Importantly, `hci_dev_do_close` *also* takes `hci_req_sync_lock(hdev)`. Does it also call `flush_workqueue(hdev->req_workqueue)`? That could be the key to triggering the deadlock. I need to check the close path now.
|
| 45/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c Name:hci_dev_do_close]
Results: map[SourceCode: 493: int hci_dev_do_close(struct hci_dev *hdev)
494: {
495: int err;
496:
497: BT_DBG("%s %p", hdev->name, hdev);
498:
499: hci_req_sync_lock(hdev);
500:
501: err = hci_dev_close_sync(hdev);
502:
503: hci_req_sync_unlock(hdev);
504:
505: return err;
506: }
SourceFile:net/bluetooth/hci_core.c]
|
| 46/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 57870
output: 40
thoughts: 45
Thoughts: Okay, here's my interpretation of those thoughts, summarized from my perspective as someone well-versed in this area:
**Deconstructing a Potential Race Condition in HCI Device Closure**
Hmm, let's see. My mind immediately flags this as a potential trouble spot: `hci_dev_close_sync` is being called while we have the `hci_req_sync_lock` held. That's a classic scenario where you need to be very, very careful. My immediate question is, does `hci_dev_close_sync` in turn attempt to wait for the `req_workqueue` to complete? Because if it does, and if we're not managing the locking correctly, we're likely staring down the barrel of a deadlock. It could be something straightforward, or it could be a subtle edge case, but the pattern itself is worth taking a deep look at. The fact that `hci_req_sync_lock` is in the equation at all means there's some kind of shared state, and closure functions are notorious for causing problems if they interact with shared resources without perfect synchronization. This warrants some more serious attention.
|
| 47/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_dev_close_sync]
Results: map[SourceCode:5252: int hci_dev_close_sync(struct hci_dev *hdev)
5253: {
5254: bool auto_off;
5255: int err = 0;
5256:
5257: bt_dev_dbg(hdev, "");
5258:
5259: if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
5260: disable_delayed_work(&hdev->power_off);
5261: disable_delayed_work(&hdev->ncmd_timer);
5262: disable_delayed_work(&hdev->le_scan_disable);
5263: } else {
5264: cancel_delayed_work(&hdev->power_off);
5265: cancel_delayed_work(&hdev->ncmd_timer);
5266: cancel_delayed_work(&hdev->le_scan_disable);
5267: }
5268:
5269: hci_cmd_sync_cancel_sync(hdev, ENODEV);
5270:
5271: cancel_interleave_scan(hdev);
5272:
5273: if (hdev->adv_instance_timeout) {
5274: cancel_delayed_work_sync(&hdev->adv_instance_expire);
5275: hdev->adv_instance_timeout = 0;
5276: }
5277:
5278: err = hci_dev_shutdown(hdev);
5279:
5280: if (!test_and_clear_bit(HCI_UP, &hdev->flags)) {
5281: cancel_delayed_work_sync(&hdev->cmd_timer);
5282: return err;
5283: }
5284:
5285: hci_leds_update_powered(hdev, false);
5286:
5287: /* Flush RX and TX works */
5288: flush_work(&hdev->tx_work);
5289: flush_work(&hdev->rx_work);
5290:
5291: if (hdev->discov_timeout > 0) {
5292: hdev->discov_timeout = 0;
5293: hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
5294: hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
5295: }
5296:
5297: if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE))
5298: cancel_delayed_work(&hdev->service_cache);
5299:
5300: if (hci_dev_test_flag(hdev, HCI_MGMT)) {
5301: struct adv_info *adv_instance;
5302:
5303: cancel_delayed_work_sync(&hdev->rpa_expired);
5304:
5305: list_for_each_entry(adv_instance, &hdev->adv_instances, list)
5306: cancel_delayed_work_sync(&adv_instance->rpa_expired_cb);
5307: }
5308:
5309: /* Avoid potential lockdep warnings from the *_flush() calls by
5310: * ensuring the workqueue is empty up front.
5311: */
5312: drain_workqueue(hdev->workqueue);
5313:
5314: hci_dev_lock(hdev);
5315:
5316: hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
5317:
5318: auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF);
5319:
5320: if (!auto_off && !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
5321: hci_dev_test_flag(hdev, HCI_MGMT))
5322: __mgmt_power_off(hdev);
5323:
5324: hci_inquiry_cache_flush(hdev);
5325: hci_pend_le_actions_clear(hdev);
5326: hci_conn_hash_flush(hdev);
5327: /* Prevent data races on hdev->smp_data or hdev->smp_bredr_data */
5328: smp_unregister(hdev);
5329: hci_dev_unlock(hdev);
5330:
5331: hci_sock_dev_event(hdev, HCI_DEV_DOWN);
5332:
5333: if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
5334: aosp_do_close(hdev);
5335: msft_do_close(hdev);
5336: }
5337:
5338: if (hdev->flush)
5339: hdev->flush(hdev);
5340:
5341: /* Reset device */
5342: skb_queue_purge(&hdev->cmd_q);
5343: atomic_set(&hdev->cmd_cnt, 1);
5344: if (hci_test_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE) &&
5345: !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
5346: set_bit(HCI_INIT, &hdev->flags);
5347: hci_reset_sync(hdev);
5348: clear_bit(HCI_INIT, &hdev->flags);
5349: }
5350:
5351: /* flush cmd work */
5352: flush_work(&hdev->cmd_work);
5353:
5354: /* Drop queues */
5355: skb_queue_purge(&hdev->rx_q);
5356: skb_queue_purge(&hdev->cmd_q);
5357: skb_queue_purge(&hdev->raw_q);
5358:
5359: /* Drop last sent command */
5360: if (hdev->sent_cmd) {
5361: cancel_delayed_work_sync(&hdev->cmd_timer);
5362: kfree_skb(hdev->sent_cmd);
5363: hdev->sent_cmd = NULL;
5364: }
5365:
5366: /* Drop last request */
5367: if (hdev->req_skb) {
5368: kfree_skb(hdev->req_skb);
5369: hdev->req_skb = NULL;
5370: }
5371:
5372: clear_bit(HCI_RUNNING, &hdev->flags);
5373: hci_sock_dev_event(hdev, HCI_DEV_CLOSE);
5374:
5375: /* After this point our queues are empty and no tasks are scheduled. */
5376: hdev->close(hdev);
5377:
5378: /* Clear flags */
5379: hdev->flags &= BIT(HCI_RAW);
5380: hci_dev_clear_volatile_flags(hdev);
5381:
5382: memset(hdev->eir, 0, sizeof(hdev->eir));
5383: memset(hdev->dev_class, 0, sizeof(hdev->dev_class));
5384: bacpy(&hdev->random_addr, BDADDR_ANY);
5385: hci_codec_list_clear(&hdev->local_codecs);
5386:
5387: hci_dev_put(hdev);
5388: return err;
5389: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 48/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 60421
output: 42
thoughts: 64
Thoughts: **Analyzing the Device Closure Process**
Okay, so I'm looking at `hci_dev_close_sync` and, immediately, it's calling `hci_cmd_sync_cancel_sync(hdev, ENODEV)`. Hmm, that's interesting. I know `hci_cmd_sync_cancel_sync` is responsible for *cancelling* synchronized work, right? So, this suggests that the device closure is actively cancelling any outstanding synchronous commands. That makes sense from a resource management perspective; we don't want to leave commands hanging in the air when we're closing down the device. To be absolutely sure, I should really verify how `hci_cmd_sync_cancel_sync` functions and confirm its role in this specific situation. This deserves a deeper dive; I need to understand the implications of this cancellation and how it relates to device state transitions.
|
| 49/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_cmd_sync_cancel_sync]
Results: map[SourceCode: 677: /* Cancel ongoing command request synchronously:
678: *
679: * - Set result and mark status to HCI_REQ_CANCELED
680: * - Wakeup command sync thread
681: */
682: void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
683: {
684: bt_dev_dbg(hdev, "err 0x%2.2x", err);
685:
686: if (hdev->req_status == HCI_REQ_PEND) {
687: /* req_result is __u32 so error must be positive to be properly
688: * propagated.
689: */
690: hdev->req_result = err < 0 ? -err : err;
691: hdev->req_status = HCI_REQ_CANCELED;
692:
693: wake_up_interruptible(&hdev->req_wait_q);
694: }
695: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 50/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 61041
output: 42
thoughts: 678
Thoughts: **Analyzing the HCI Command Synchronization Logic**
Okay, so `hci_cmd_sync_cancel_sync` doesn't actually cancel the `hdev->cmd_sync_work`. That's a key point to remember. It just wakes up `hdev->req_wait_q` if the request status is `HCI_REQ_PEND`. But that doesn't really address the core issue of what happens if `hci_cmd_sync_work` is currently running on the `req_workqueue`. Let's break this down further.
If `hci_dev_close_sync` is called, it acquires `hci_req_sync_lock(hdev)`. If `hci_cmd_sync_work` is already running, it will block on that lock. Effectively, `hci_cmd_sync_work` will be waiting for `hci_dev_close_sync` to finish. Now, `hci_dev_close_sync` calls `drain_workqueue(hdev->workqueue)`. Wait a minute, that's not `hdev->req_workqueue`. So, `hci_dev_close_sync` isn't waiting for the `req_workqueue` to finish. It finishes, releases the lock, and then `hci_cmd_sync_work` can run. But, here is an important point: `hci_dev_close_sync` calls `hci_dev_put(hdev)`.
The crucial question is: What if `hci_dev_open` is called concurrently with `hci_dev_close`? In this scenario, `hci_dev_open` calls `flush_workqueue(hdev->req_workqueue)`. If `hci_cmd_sync_work` is running, it will block on `hci_req_sync_lock(hdev)`. If `hci_dev_close` holds the lock, `hci_cmd_sync_work` waits, `hci_dev_close` completes, releases the lock, and `hci_cmd_sync_work` acquires the lock and runs. Then `hci_cmd_sync_work` completes, and `flush_workqueue` in `hci_dev_open` completes. This particular scenario doesn't appear to result in a deadlock.
Now, let's consider the more nuanced scenario: What if `hci_cmd_sync_work` is waiting for an event? `hci_cmd_sync_work` calls `entry->func(hdev, entry->data)`. This function, `entry->func`, might call `__hci_cmd_sync_skb`, which then calls `wait_event_interruptible_timeout(hdev->req_wait_q, ...)`. If `__hci_cmd_sync_skb` is waiting, does it hold the `hci_req_sync_lock(hdev)`? It does. Good, `__hci_cmd_sync_skb` is called with the lock held. Now I need to examine `__hci_cmd_sync_skb` more closely to be certain that there are no hidden race conditions in that particular code path.
|
| 51/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:__hci_cmd_sync_skb]
Results: map[SourceCode: SourceFile:]
|
| 52/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 62459
output: 39
thoughts: 13
Thoughts: Here's my thought process, summarized as you requested:
**Investigating `__hci_cmd_sync`**
Okay, so I'm seeing `__hci_cmd_sync` pop up in my analysis. Given my expertise, I'm already mentally tagging this as a core function within the HCI (Host Controller Interface) layer, likely related to synchronous command execution. My immediate goal is to understand its role and context within the larger system. This name strongly suggests it's a synchronous variant, so I'm expecting this to mean it's blocking, meaning the calling code will wait for a response before proceeding. Now, I want to confirm that assumption and clarify the specific function of this particular instance. Let's start by searching to see where it's defined and used. I'll need to look in the relevant Bluetooth stack code base, probably starting with the HCI driver implementation. My primary objective here is to figure out: what the function does, where it's used, what the typical data passed to it would be, and what it implies about the design choices made in the overall architecture. I'm looking for clues about potential performance bottlenecks, potential error handling mechanisms, and any possible synchronization issues. Specifically, I'm interested in how it interacts with the underlying hardware, how it handles command timeouts, and whether it's thread-safe. I'm going to start with the search to track down the implementation.
|
| 53/2 |
2026/05/31 10:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:__hci_cmd_sync]
Results: map[SourceCode: 219: /* This function requires the caller holds hdev->req_lock. */
220: struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
221: const void *param, u32 timeout)
222: {
223: return __hci_cmd_sync_sk(hdev, opcode, plen, param, 0, timeout, NULL);
224: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 54/2 |
2026/05/31 10:17 |
llm |
expert |
0m
Model:
Tokens:
input: 62967
output: 41
thoughts: 14
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Diving into `__hci_cmd_sync_sk`**
Alright, time to dig in. The mention of `__hci_cmd_sync_sk` immediately flags a potential area of interest related to synchronous HCI command execution, likely within the kernel. My immediate thought is to investigate its role in the command flow. I'm assuming we're dealing with a synchronous execution path, so I need to understand how the command is initiated, how it's handled, how it waits for a response, and what safeguards are in place. What's the context? Is this the main path for most HCI commands, or a specific subset? Are there any obvious race conditions or locking issues associated with its use? I need to analyze its relationship to the socket and the underlying HCI transport. I also want to see what error handling is in place, and if there are any obvious bottlenecks or opportunities for optimization. Let's see how well documented this piece of the kernel is, and if there are any existing bug reports or patches related to this function. This will allow me to narrow my focus and target my investigation more effectively.
|
| 55/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:__hci_cmd_sync_sk]
Results: map[SourceCode: 155: /* This function requires the caller holds hdev->req_lock. */
156: struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
157: const void *param, u8 event, u32 timeout,
158: struct sock *sk)
159: {
160: struct hci_request req;
161: struct sk_buff *skb;
162: int err = 0;
163:
164: bt_dev_dbg(hdev, "Opcode 0x%4.4x", opcode);
165:
166: hci_request_init(&req, hdev);
167:
168: hci_cmd_sync_add(&req, opcode, plen, param, event, sk);
169:
170: hdev->req_status = HCI_REQ_PEND;
171:
172: err = hci_req_sync_run(&req);
173: if (err < 0)
174: return ERR_PTR(err);
175:
176: err = wait_event_interruptible_timeout(hdev->req_wait_q,
177: hdev->req_status != HCI_REQ_PEND,
178: timeout);
179:
180: if (err == -ERESTARTSYS)
181: return ERR_PTR(-EINTR);
182:
183: switch (hdev->req_status) {
184: case HCI_REQ_DONE:
185: err = -bt_to_errno(hdev->req_result);
186: break;
187:
188: case HCI_REQ_CANCELED:
189: err = -hdev->req_result;
190: break;
191:
192: default:
193: err = -ETIMEDOUT;
194: break;
195: }
196:
197: hdev->req_status = 0;
198: hdev->req_result = 0;
199: skb = hdev->req_rsp;
200: hdev->req_rsp = NULL;
201:
202: bt_dev_dbg(hdev, "end: err %d", err);
203:
204: if (err < 0) {
205: kfree_skb(skb);
206: return ERR_PTR(err);
207: }
208:
209: /* If command return a status event skb will be set to NULL as there are
210: * no parameters.
211: */
212: if (!skb)
213: return ERR_PTR(-ENODATA);
214:
215: return skb;
216: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 56/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 64179
output: 38
thoughts: 389
Thoughts: **Debugging a Bluetooth Timeout**
Okay, so I'm looking at this trace, and I see a call to `__hci_cmd_sync_sk` which uses `wait_event_interruptible_timeout`. The timeout is set to `HCI_CMD_TIMEOUT`, which I know is 2 seconds. But the task is blocked for a whopping 152 seconds. That's a huge discrepancy! Clearly, it's *not* stuck inside the timeout function itself. Hmm... so where *is* it blocked? The trace points to `flush_workqueue(hdev->req_workqueue)`.
Aha! That means a work item running on `req_workqueue` is the culprit, and it's being held up for an unacceptably long time. 152 seconds... that screams deadlock. We need to figure out which work item is the issue. Let me quickly run through the possibilities: `hdev->power_on`, `hdev->power_off`, `hdev->error_reset`, `hdev->interleave_scan`, `hdev->cmd_sync_work`, `hdev->adv_instance_expire`, `hdev->le_scan_disable`, `hdev->discov_off`, and `hdev->mesh_send_done`.
Let's start by digging into `hci_power_on`, since that seems like a likely candidate for being long-running. Okay, `hci_power_on` calls `hci_dev_do_open(hdev)`. And that in turn calls `hci_dev_open_sync(hdev)`. Okay, and then `hci_dev_open_sync` calls `hdev->open(hdev)`.
So, if `hdev->open` blocks indefinitely, then `hci_power_on` will block indefinitely too. That's where we need to look. So what is `hdev->open`? Let's assume the device is `vhci`, then it's `vhci_open`.
|
| 57/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_vhci.c Name:vhci_open]
Results: map[SourceCode: 639: static int vhci_open(struct inode *inode, struct file *file)
640: {
641: struct vhci_data *data;
642:
643: data = kzalloc(sizeof(*data), GFP_KERNEL);
644: if (!data)
645: return -ENOMEM;
646:
647: skb_queue_head_init(&data->readq);
648: init_waitqueue_head(&data->read_wait);
649:
650: mutex_init(&data->open_mutex);
651: INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
652: INIT_WORK(&data->suspend_work, vhci_suspend_work);
653:
654: file->private_data = data;
655: nonseekable_open(inode, file);
656:
657: schedule_delayed_work(&data->open_timeout, secs_to_jiffies(1));
658:
659: return 0;
660: }
SourceFile:drivers/bluetooth/hci_vhci.c]
|
| 58/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 65404
output: 38
thoughts: 35
Thoughts: Okay, let me think this through.
**Analyzing the VHCI Driver's File Operations**
Right, so I'm looking at this code and it's hitting me that `vhci_open` is specifically the file operation for interacting with the `/dev/vhci` device node. That makes perfect sense; the driver needs a way to handle access to that character device. But then I'm thinking, isn't there another crucial element here? Where is the `hdev->open` operation for the `vhci` context? The `hdev` structure represents the host device, and presumably, there's an `open` method associated with *it* that needs to be considered. Are these two connected, or is `vhci_open` doing the bulk of the initial setup? Or, does `hdev->open` merely handle some higher-level initialization? I need to clarify the relationship and potential overlap between these two operations; that's the key to understanding the full picture of how the driver handles device access. It's not immediately obvious if both are called or if one calls the other...
|
| 59/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_vhci.c Name:vhci_setup]
Results: map[SourceCode: 272: static int vhci_setup(struct hci_dev *hdev)
273: {
274: struct vhci_data *vhci = hci_get_drvdata(hdev);
275:
276: if (vhci->msft_opcode)
277: hci_set_msft_opcode(hdev, vhci->msft_opcode);
278:
279: if (vhci->aosp_capable)
280: hci_set_aosp_capable(hdev);
281:
282: return 0;
283: }
SourceFile:drivers/bluetooth/hci_vhci.c]
|
| 60/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 65921
output: 32
thoughts: 21
Thoughts: Here's a summary of my thought process:
**Diving into the HCI VHCI Driver**
Okay, so I need to find something in the Bluetooth virtual HCI driver. Specifically, I recall the need to investigate something related to the `.open` function. Given my experience, the first logical step is to pinpoint its location. I immediately zero in on the `drivers/bluetooth/` directory, and knowing that the virtual HCI driver is named `hci_vhci.c`, I'll search that specific file. Let's start the hunt for `.open` within `drivers/bluetooth/hci_vhci.c`. Hopefully, it's a straightforward search!
|
| 61/2 |
2026/05/31 10:18 |
tool |
grepper |
0m
Args: map[Expression:\.open PathPrefix:drivers/bluetooth/hci_vhci.c]
Results: map[Output:drivers/bluetooth/hci_vhci.c=157=static const struct file_operations force_suspend_fops = {
drivers/bluetooth/hci_vhci.c:158: .open = simple_open,
drivers/bluetooth/hci_vhci.c-159- .read = force_suspend_read,
--
drivers/bluetooth/hci_vhci.c=196=static const struct file_operations force_wakeup_fops = {
drivers/bluetooth/hci_vhci.c:197: .open = simple_open,
drivers/bluetooth/hci_vhci.c-198- .read = force_wakeup_read,
--
drivers/bluetooth/hci_vhci.c=265=static const struct file_operations aosp_capable_fops = {
drivers/bluetooth/hci_vhci.c:266: .open = simple_open,
drivers/bluetooth/hci_vhci.c-267- .read = aosp_capable_read,
--
drivers/bluetooth/hci_vhci.c=378=static const struct file_operations force_devcoredump_fops = {
drivers/bluetooth/hci_vhci.c:379: .open = simple_open,
drivers/bluetooth/hci_vhci.c-380- .write = force_devcd_write,
--
drivers/bluetooth/hci_vhci.c=701=static const struct file_operations vhci_fops = {
--
drivers/bluetooth/hci_vhci.c-705- .poll = vhci_poll,
drivers/bluetooth/hci_vhci.c:706: .open = vhci_open,
drivers/bluetooth/hci_vhci.c-707- .release = vhci_release,
]
|
| 62/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 66578
output: 40
thoughts: 19
Thoughts: Here's a summary of my thought process:
**Tracing the Device Initialization**
Okay, so I'm trying to figure out where this `hdev->open` function pointer gets set. I see it's used later, but I need to understand where it's initialized. My focus is on the virtual HCI device creation flow. Let me trace back... Hmm, let's see, it looks like `hdev->open` is assigned *during* the device creation process. I'm noting that the assignment specifically happens within `vhci_create_device`. Got it. That's the key. Now I need to understand what's happening within `vhci_create_device`. This helps me define the context of the device and when its resources are allocated. This is a crucial detail for understanding the device's lifecycle.
|
| 63/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_vhci.c Name:vhci_create_device]
Results: map[SourceCode: 474: static int vhci_create_device(struct vhci_data *data, __u8 opcode)
475: {
476: int err;
477:
478: mutex_lock(&data->open_mutex);
479: err = __vhci_create_device(data, opcode);
480: mutex_unlock(&data->open_mutex);
481:
482: return err;
483: }
SourceFile:drivers/bluetooth/hci_vhci.c]
|
| 64/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 66982
output: 41
thoughts: 13
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `__vhci_create_device`**
Okay, so we're starting here with `__vhci_create_device`. That's where the rubber meets the road, as far as the virtual host controller interface is concerned. I need to refresh my memory on the critical path there. Specifically, what happens in terms of resource allocation, device initialization, and the potential for synchronization issues. I want to see how device-specific data structures are set up and how they interact with the overall VHCI framework. I'm keen to understand the error handling at this stage, particularly around memory allocation failures and potential race conditions in a multithreaded environment. Are there any subtle bugs that might manifest under heavy load or with a large number of virtual devices? I need to focus on this function to have a clear understanding of the vhci subsystem
|
| 65/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_vhci.c Name:__vhci_create_device]
Results: map[SourceCode: 405: static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
406: {
407: struct hci_dev *hdev;
408: struct sk_buff *skb;
409:
410: if (data->hdev)
411: return -EBADFD;
412:
413: /* bits 2-5 are reserved (must be zero) */
414: if (opcode & 0x3c)
415: return -EINVAL;
416:
417: skb = bt_skb_alloc(4, GFP_KERNEL);
418: if (!skb)
419: return -ENOMEM;
420:
421: hdev = hci_alloc_dev();
422: if (!hdev) {
423: kfree_skb(skb);
424: return -ENOMEM;
425: }
426:
427: data->hdev = hdev;
428:
429: hdev->bus = HCI_VIRTUAL;
430: hci_set_drvdata(hdev, data);
431:
432: hdev->open = vhci_open_dev;
433: hdev->close = vhci_close_dev;
434: hdev->flush = vhci_flush;
435: hdev->send = vhci_send_frame;
436: hdev->get_data_path_id = vhci_get_data_path_id;
437: hdev->get_codec_config_data = vhci_get_codec_config_data;
438: hdev->wakeup = vhci_wakeup;
439: hdev->setup = vhci_setup;
440: hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP);
441: hci_set_quirk(hdev, HCI_QUIRK_SYNC_FLOWCTL_SUPPORTED);
442:
443: /* bit 6 is for external configuration */
444: if (opcode & 0x40)
445: hci_set_quirk(hdev, HCI_QUIRK_EXTERNAL_CONFIG);
446:
447: /* bit 7 is for raw device */
448: if (opcode & 0x80)
449: hci_set_quirk(hdev, HCI_QUIRK_RAW_DEVICE);
450:
451: if (hci_register_dev(hdev) < 0) {
452: BT_ERR("Can't register HCI device");
453: hci_free_dev(hdev);
454: data->hdev = NULL;
455: kfree_skb(skb);
456: return -EBUSY;
457: }
458:
459: if (!IS_ERR_OR_NULL(hdev->debugfs))
460: vhci_debugfs_init(data);
461:
462: hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
463:
464: skb_put_u8(skb, 0xff);
465: skb_put_u8(skb, opcode);
466: put_unaligned_le16(hdev->id, skb_put(skb, 2));
467: skb_queue_head(&data->readq, skb);
468: atomic_inc(&data->initialized);
469:
470: wake_up_interruptible(&data->read_wait);
471: return 0;
472: }
SourceFile:drivers/bluetooth/hci_vhci.c]
|
| 66/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 68349
output: 40
thoughts: 15
Thoughts: Here's a summary of my understanding, framed as my own thoughts:
**Dissecting the Device Initialization**
Okay, so I'm looking at this driver code, and I see `hdev->open`. I immediately recognize that this is the function responsible for handling the device opening operation. Good. Now, I see that `hdev->open` is assigned to `vhci_open_dev`. This tells me that the specific implementation for opening the virtual HCI device is `vhci_open_dev`. I need to drill down into `vhci_open_dev` to see the details of how this virtual device is initialized, how resources are allocated, and how the connection is established. This is a crucial piece, as the device open is the gateway to all future interactions with the virtual HCI device.
|
| 67/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/bluetooth/hci_vhci.c Name:vhci_open_dev]
Results: map[SourceCode: 51: static int vhci_open_dev(struct hci_dev *hdev)
52: {
53: return 0;
54: }
SourceFile:drivers/bluetooth/hci_vhci.c]
|
| 68/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 68654
output: 40
thoughts: 45
Thoughts: Okay, here's my thinking process:
**Diving into the HCI Device Opening**
Alright, so `vhci_open_dev` is non-blocking, that's good to know. Now, I need to pinpoint the potential bottlenecks within `hci_dev_open_sync`. If `vhci_open_dev` isn't the culprit, where else could it be getting hung up? My immediate suspicion lands on `hci_dev_init_sync(hdev)`. That function seems like a likely candidate for introducing delays or contention during the opening process. I'll need to dig into that function and see what's happening in there.
|
| 69/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_dev_init_sync]
Results: map[SourceCode:5045: /* This function handles hdev init stage:
5046: *
5047: * Calls hci_dev_setup_sync to perform setup stage
5048: * Calls hci_init_sync to perform HCI command init sequence
5049: */
5050: static int hci_dev_init_sync(struct hci_dev *hdev)
5051: {
5052: int ret;
5053:
5054: bt_dev_dbg(hdev, "");
5055:
5056: atomic_set(&hdev->cmd_cnt, 1);
5057: set_bit(HCI_INIT, &hdev->flags);
5058:
5059: ret = hci_dev_setup_sync(hdev);
5060:
5061: if (hci_dev_test_flag(hdev, HCI_CONFIG)) {
5062: /* If public address change is configured, ensure that
5063: * the address gets programmed. If the driver does not
5064: * support changing the public address, fail the power
5065: * on procedure.
5066: */
5067: if (bacmp(&hdev->public_addr, BDADDR_ANY) &&
5068: hdev->set_bdaddr)
5069: ret = hdev->set_bdaddr(hdev, &hdev->public_addr);
5070: else
5071: ret = -EADDRNOTAVAIL;
5072: }
5073:
5074: if (!ret) {
5075: if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&
5076: !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
5077: ret = hci_init_sync(hdev);
5078: if (!ret && hdev->post_init)
5079: ret = hdev->post_init(hdev);
5080: }
5081: }
5082:
5083: /* If the HCI Reset command is clearing all diagnostic settings,
5084: * then they need to be reprogrammed after the init procedure
5085: * completed.
5086: */
5087: if (hci_test_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_DIAG) &&
5088: !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
5089: hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag)
5090: ret = hdev->set_diag(hdev, true);
5091:
5092: if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
5093: msft_do_open(hdev);
5094: aosp_do_open(hdev);
5095: }
5096:
5097: clear_bit(HCI_INIT, &hdev->flags);
5098:
5099: return ret;
5100: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 70/2 |
2026/05/31 10:18 |
llm |
expert |
0m
Model:
Tokens:
input: 69785
output: 40
thoughts: 173
Thoughts: **My Line of Reasoning**
Okay, so I'm looking at this `hci_dev_init_sync` function. It seems it calls `hci_init_sync(hdev)` which, ah, yes, sends those HCI commands. Right. And if this device is the `vhci`, then those commands go to the `vhci` character device. The key question is, what happens if nobody's *reading* from that character device? My immediate concern is that the commands will just... queue up.
But wait a minute! If they queue up, then `__hci_cmd_sync_sk` kicks in, and that function *waits* for the response. Clever. It's supposed to wait with a timeout of `HCI_CMD_TIMEOUT`, which is a reasonable two seconds. So, the system *shouldn't* block indefinitely, which is a big relief. It should just return `-ETIMEDOUT` if it doesn't get a response.
Hmm, but I have to consider edge cases. What if something else is fiddling with `hdev->req_status` while this is happening? Or, what if `hci_req_sync_run` itself blocks? That would throw a spanner in the works. Need to keep those things in mind.
|
| 71/2 |
2026/05/31 10:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_req_sync_run]
Results: map[SourceCode: 115: static int hci_req_sync_run(struct hci_request *req)
116: {
117: struct hci_dev *hdev = req->hdev;
118: struct sk_buff *skb;
119: unsigned long flags;
120:
121: bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q));
122:
123: /* If an error occurred during request building, remove all HCI
124: * commands queued on the HCI request queue.
125: */
126: if (req->err) {
127: skb_queue_purge(&req->cmd_q);
128: return req->err;
129: }
130:
131: /* Do not allow empty requests */
132: if (skb_queue_empty(&req->cmd_q))
133: return -ENODATA;
134:
135: skb = skb_peek_tail(&req->cmd_q);
136: bt_cb(skb)->hci.req_complete_skb = hci_cmd_sync_complete;
137: bt_cb(skb)->hci.req_flags |= HCI_REQ_SKB;
138:
139: spin_lock_irqsave(&hdev->cmd_q.lock, flags);
140: skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q);
141: spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
142:
143: queue_work(hdev->workqueue, &hdev->cmd_work);
144:
145: return 0;
146: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 72/2 |
2026/05/31 10:18 |
llm |
expert |
1m
Model:
Tokens:
input: 70821
output: 38
thoughts: 1094
Thoughts: **Debugging a Bluetooth Device Power-On Timeout**
Okay, so I'm looking at this `hci_power_on` function and why it might be taking so long to complete, specifically why `flush_workqueue(hdev->req_workqueue)` could be blocking for a massive 152 seconds. I've walked through the call stack: `hci_req_sync_run` schedules `cmd_work`, which, at the end of the chain, calls `hci_dev_open_sync`, and that function is where the timeout occurs.
First, I thought maybe `req_workqueue` was just flooded with an infinite loop of work items, something like `power_on` queuing `power_off`, and vice versa. But no, that's not it. `hci_power_on` *does* schedule a `power_off` but with a 2-second delay, so that's not the root cause.
Then, I started thinking about `hci_cmd_sync_work`. This function processes a linked list of entries, so if someone keeps adding entries to `cmd_sync_work_list`, `hci_cmd_sync_work` will never finish. But, who adds to this list? `hci_cmd_sync_submit` and `hci_cmd_sync_queue`. The concern I have is an endless loop. Could `entry->func` call `hci_cmd_sync_queue` recursively? Maybe, but I need to investigate in more detail.
Wait, what if `flush_workqueue` is blocked because `hci_cmd_sync_work` is blocked on a lock? Specifically, the `hci_req_sync_lock(hdev)`. If another thread holds that lock for a long time, the work item processing commands gets blocked. And then `flush_workqueue` would just wait forever. Who could be holding that lock for a long time? `hci_dev_open` is the first suspect. But, `hci_dev_open` calls `flush_workqueue` *before* taking the lock.
Aha! What if two threads are in play? One thread, Thread A, calls `hci_dev_do_open` which *does* take the lock. Meanwhile, Thread B calls `hci_dev_open`.
Thread A: `hci_dev_do_open` -> `hci_req_sync_lock(hdev)` -> `hci_dev_open_sync` -> `hdev->open` -> ...
Thread B: `hci_dev_open` -> `flush_workqueue(hdev->req_workqueue)`.
So, if `req_workqueue` has `hci_cmd_sync_work` queued, `flush_workqueue` waits for `hci_cmd_sync_work` to finish. `hci_cmd_sync_work` then tries to acquire `hci_req_sync_lock(hdev)`. It blocks because Thread A is holding the lock. Now, Thread B is blocked in `flush_workqueue` and `hci_cmd_sync_work` is blocked on Thread A. If Thread A takes 152 seconds, so does Thread B. But, why does Thread A take 152 seconds? Maybe the timeouts. `hci_dev_open_sync` sends many commands. If each command times out after 2 seconds, and there are 76 commands, that equals 152 seconds! I need to check how many commands `hci_init_sync` sends.
|
| 73/2 |
2026/05/31 10:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_init_sync]
Results: map[SourceCode:4881: static int hci_init_sync(struct hci_dev *hdev)
4882: {
4883: int err;
4884:
4885: err = hci_init1_sync(hdev);
4886: if (err < 0)
4887: return err;
4888:
4889: if (hci_dev_test_flag(hdev, HCI_SETUP))
4890: hci_debugfs_create_basic(hdev);
4891:
4892: err = hci_init2_sync(hdev);
4893: if (err < 0)
4894: return err;
4895:
4896: err = hci_init3_sync(hdev);
4897: if (err < 0)
4898: return err;
4899:
4900: err = hci_init4_sync(hdev);
4901: if (err < 0)
4902: return err;
4903:
4904: /* This function is only called when the controller is actually in
4905: * configured state. When the controller is marked as unconfigured,
4906: * this initialization procedure is not run.
4907: *
4908: * It means that it is possible that a controller runs through its
4909: * setup phase and then discovers missing settings. If that is the
4910: * case, then this function will not be called. It then will only
4911: * be called during the config phase.
4912: *
4913: * So only when in setup phase or config phase, create the debugfs
4914: * entries and register the SMP channels.
4915: */
4916: if (!hci_dev_test_flag(hdev, HCI_SETUP) &&
4917: !hci_dev_test_flag(hdev, HCI_CONFIG))
4918: return 0;
4919:
4920: if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED))
4921: return 0;
4922:
4923: hci_debugfs_create_common(hdev);
4924:
4925: if (lmp_bredr_capable(hdev))
4926: hci_debugfs_create_bredr(hdev);
4927:
4928: if (lmp_le_capable(hdev))
4929: hci_debugfs_create_le(hdev);
4930:
4931: return 0;
4932: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 74/2 |
2026/05/31 10:19 |
llm |
expert |
0m
Model:
Tokens:
input: 73485
output: 38
thoughts: 2586
Thoughts: **Analyzing a Bluetooth HCI Device Initialization Hang**
Okay, here's the breakdown of my thought process on this issue. First, I'm thinking, "if a command times out during the init sequence, it errors out and aborts right away, right?". But this can't be it, because this scenario would not lead to an extended delay. So it's not simply a command timeout. But wait, what if the commands are succeeding, but there are a huge number of them? No, that's not it either, because successful commands are fast. Then, what if `hci_req_sync_run` is the problem? And it seems it queues `cmd_work` on `hdev->workqueue`, right.
Okay, so I consider if `hdev->workqueue` is blocked, and if so, what functions are running there? `hci_cmd_work`, `hci_rx_work`, `hci_tx_work` are. Let's see if `hci_cmd_work` might be stuck.
Aha! The reproducer is using `cake` qdisc. Is there any link between cake and bluetooth? So the reproducer configures `cake` on `lo` using a netlink socket and a `RTM_NEWQDISC` message. But that probably doesn't explain the hang... The `cake` qdisc could call `flush_workqueue`? But the call trace is `hci_dev_open`, which is called within `sock_do_ioctl`, which is called from within the `ioctl` syscall, which is the reproducer's call. It means the process calling `ioctl` on a socket is blocked in `hci_dev_open`.
Then I remember the `SIOCGIFINDEX` ioctl with the number `0x8933`, but that just returns the ifindex from `dev_ioctl`. It doesn't call `hci_dev_open`. So why is `hci_dev_open` in the trace? `sock_do_ioctl` calls `ops->ioctl` if it's the right socket. If it's a Bluetooth socket, the `ops->ioctl` handler is `hci_sock_ioctl`. `hci_sock_ioctl` handles `HCIDEVUP` by calling `hci_dev_open`. So, the reproducer *must* be calling `ioctl(fd, HCIDEVUP, arg)` on a Bluetooth socket! But the reproducer doesn't have `socket(AF_BLUETOOTH)` or `HCIDEVUP`. Hmm, syzkaller sometimes misses this.
Let's assume `ioctl(HCIDEVUP)` is called. It blocks in `flush_workqueue(hdev->req_workqueue)`. Why? Some work is stuck in the queue. Is it `hci_cmd_sync_work`? If so, who holds the lock `hci_req_sync_lock(hdev)`? It could be another thread running `hci_dev_do_open`, `hci_dev_do_close`, or `hci_dev_do_reset`, which might be stuck also. `hci_dev_do_open` calls `hci_dev_open_sync`. `hci_dev_open_sync` calls `hdev->open`. If `hdev->open` is `vhci_open_dev`, then it returns immediately. Then `hci_dev_init_sync` is called. So it may call `hci_init_sync`, which sends commands and waits for responses. But no, that would just lead to timeout after 2 seconds.
But what if `hci_req_sync_run` is blocking? But it queues `cmd_work` on `hdev->workqueue`. If `hdev->workqueue` is stuck, the command isn't sent and it times out after 2 seconds. No it doesn't explain the 152-second delay.
So, is there any loop in `hci_dev_open_sync`? Nope. What if `hci_cmd_sync_work` is stuck *inside* the function, not waiting for the lock. Let's look at what is queued on `cmd_sync_work_list`. I see a bunch of callers of `hci_cmd_sync_submit` and `hci_cmd_sync_queue`. Some of these functions could block for a longer time, maybe several seconds.
Aha, perhaps `__hci_cmd_sync_sk` is called within a loop and that is the bottleneck. For example, `start_discovery_sync`.
|
| 75/2 |
2026/05/31 10:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:start_discovery_sync]
Results: map[SourceCode:5977: static int start_discovery_sync(struct hci_dev *hdev, void *data)
5978: {
5979: if (!mgmt_pending_listed(hdev, data))
5980: return -ECANCELED;
5981:
5982: return hci_start_discovery_sync(hdev);
5983: }
SourceFile:net/bluetooth/mgmt.c]
|
| 76/2 |
2026/05/31 10:20 |
llm |
expert |
0m
Model:
Tokens:
input: 77228
output: 40
thoughts: 13
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:
**Deep Dive on `hci_start_discovery_sync`**
Alright, let's zero in on `hci_start_discovery_sync`. I need to refresh my memory on the exact implementation details of this function and how it fits into the broader HCI discovery flow. I'm assuming we're talking about a synchronous approach here, which means we're blocking until the discovery process completes or fails. That likely entails sending an HCI command, waiting for a response (or timeout), and then potentially processing some subsequent events related to the devices discovered.
I need to quickly consider potential locking issues and race conditions. Is this function thread-safe? Does it properly handle concurrent access to the HCI interface? I also need to think about error handling. What happens if the HCI command fails at a low level? Are errors propagated correctly, and what are the implications for the higher-level application code? Is there appropriate retry logic, or is this function expected to be the atomic unit of the discovery process?
Another point to review is how this function handles the different types of discovery. Does it support both inquiry and scanning or does it combine them into one unit? And what are the configuration options available? We need to keep in mind the various HCI parameters associated with the discovery process itself, such as the inquiry scan type, scan interval, scan window, and how the results are filtered. I also wonder about any optimizations performed or potential power management implications.
Finally, I will go through the calling functions to see which of them are being blocked by this function. I will need to verify if the function design and its position within our architecture are suitable for the discovery service being delivered.
|
| 77/2 |
2026/05/31 10:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_start_discovery_sync]
Results: map[SourceCode:6038: int hci_start_discovery_sync(struct hci_dev *hdev)
6039: {
6040: unsigned long timeout;
6041: int err;
6042:
6043: bt_dev_dbg(hdev, "type %u", hdev->discovery.type);
6044:
6045: switch (hdev->discovery.type) {
6046: case DISCOV_TYPE_BREDR:
6047: return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN, 0);
6048: case DISCOV_TYPE_INTERLEAVED:
6049: /* When running simultaneous discovery, the LE scanning time
6050: * should occupy the whole discovery time sine BR/EDR inquiry
6051: * and LE scanning are scheduled by the controller.
6052: *
6053: * For interleaving discovery in comparison, BR/EDR inquiry
6054: * and LE scanning are done sequentially with separate
6055: * timeouts.
6056: */
6057: if (hci_test_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY)) {
6058: timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT);
6059: /* During simultaneous discovery, we double LE scan
6060: * interval. We must leave some time for the controller
6061: * to do BR/EDR inquiry.
6062: */
6063: err = hci_start_interleaved_discovery_sync(hdev);
6064: break;
6065: }
6066:
6067: timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout);
6068: err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery);
6069: break;
6070: case DISCOV_TYPE_LE:
6071: timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT);
6072: err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery);
6073: break;
6074: default:
6075: return -EINVAL;
6076: }
6077:
6078: if (err)
6079: return err;
6080:
6081: bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout));
6082:
6083: queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable,
6084: timeout);
6085: return 0;
6086: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 78/2 |
2026/05/31 10:20 |
llm |
expert |
0m
Model:
Tokens:
input: 78456
output: 39
thoughts: 11
Thoughts: Okay, let's see...
**Diving into Bluetooth Inquiry**
Wait a second⦠`hci_inquiry_sync`? That's not the usual inquiry function I'm accustomed to working with. Interesting choice, or perhaps a typo. This immediately makes me think, how is this different? Is this a synchronous version? Am I looking at something low-level like direct HCI commands, bypassing the more user-friendly abstraction layers I'm probably used to. I need to refresh my memory on the intricacies of the HCI inquiry command and the specific nuances of `hci_inquiry_sync`. This tells me that they're probably working with timing constraints and lower-level protocols directly, likely looking for a deterministic result or wanting to control the inquiry process in a very precise manner. I need to understand the implications of synchronous operation here, especially regarding blocking and potential impact on application responsiveness. Where is this implemented? In the kernel? In a user library? Understanding the context is key now.
|
| 79/2 |
2026/05/31 10:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_inquiry_sync]
Results: map[SourceCode:5925: int hci_inquiry_sync(struct hci_dev *hdev, u8 length, u8 num_rsp)
5926: {
5927: const u8 giac[3] = { 0x33, 0x8b, 0x9e };
5928: const u8 liac[3] = { 0x00, 0x8b, 0x9e };
5929: struct hci_cp_inquiry cp;
5930:
5931: bt_dev_dbg(hdev, "");
5932:
5933: if (test_bit(HCI_INQUIRY, &hdev->flags))
5934: return 0;
5935:
5936: hci_dev_lock(hdev);
5937: hci_inquiry_cache_flush(hdev);
5938: hci_dev_unlock(hdev);
5939:
5940: memset(&cp, 0, sizeof(cp));
5941:
5942: if (hdev->discovery.limited)
5943: memcpy(&cp.lap, liac, sizeof(cp.lap));
5944: else
5945: memcpy(&cp.lap, giac, sizeof(cp.lap));
5946:
5947: cp.length = length;
5948: cp.num_rsp = num_rsp;
5949:
5950: return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY,
5951: sizeof(cp), &cp, HCI_CMD_TIMEOUT);
5952: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 80/2 |
2026/05/31 10:20 |
llm |
expert |
0m
Model:
Tokens:
input: 79198
output: 36
thoughts: 804
Thoughts: **Analyzing Potential Deadlocks in Bluetooth Device Initialization**
Okay, so I'm digging into this Bluetooth driver code, specifically around the `hci_dev_open` function, and I'm trying to figure out if there's a potential for deadlock. The code uses `HCI_CMD_TIMEOUT`, which is a common pattern, but that got me thinking about workqueues.
The question that jumped out at me is, what if `hdev->req_workqueue` gets blocked because `hci_dev_open` calls `flush_workqueue`? If `hci_dev_open` calls `flush_workqueue(hdev->req_workqueue)`, it essentially waits for all currently executing work items to complete before continuing. Now, if *one* of those currently executing work items, for whatever reason, calls `flush_workqueue(hdev->req_workqueue)` itself, thatβs a guaranteed deadlock, right? But I quickly dismissed that since work items generally don't call `flush_workqueue` on the same queue.
Then I shifted my focus to locks. What if a work item holds a lock, and `hci_dev_open` tries to acquire the same lock while flushing the workqueue? I checked; `hci_dev_open` doesnβt take any locks before the `flush_workqueue` call. Okay, good.
Now, I remembered that `hci_dev_open` is called from `hci_sock_ioctl`. `hci_sock_ioctl` *does* take `lock_sock(sk)`. But wait, I checked `hci_sock_ioctl` earlier, and it actually calls `release_sock(sk)` *before* calling `hci_dev_open`. So `lock_sock(sk)` isnβt held in that case. I then checked up the call stack via `sock_do_ioctl` and `vfs_ioctl` to make sure no other locks are held there, either. No problems so far.
Then it hit me: what about `hci_sock_bind`? `hci_sock_bind` *does* hold `lock_sock(sk)`! Specifically:
```c
lock_sock(sk);
...
case HCI_CHANNEL_USER:
...
err = hci_dev_open(hdev->id);
```
So if `hci_dev_open` is called from `hci_sock_bind`, `lock_sock(sk)` *is* held. If there's a work item on `req_workqueue` that tries to take `lock_sock(sk)`, BOOM, deadlock.
Now the critical question: which work items use `lock_sock(sk)`? Let's see⦠The work items on `req_workqueue` are: `hdev->power_on`, `hdev->power_off`, `hdev->error_reset`, `hdev->interleave_scan`, `hdev->cmd_sync_work`, `hdev->adv_instance_expire`, `hdev->le_scan_disable`, `hdev->discov_off`, and `hdev->mesh_send_done`.
Okay, `cmd_sync_work` runs `entry->func`. `entry->func` can be a number of things: like `set_powered_sync` or `add_uuid_sync`. Those are called from `mgmt.c` or `hci_sock.c`. Do those functions take `lock_sock(sk)`? Typically, the management functions don't know about sockets. However, `mgmt` functions *do* send events to sockets.
Aha! `mgmt_power_on` sends an event. Does *sending* the event take `lock_sock(sk)`? Now I need to check `mgmt_power_on` specifically to see...
|
| 81/2 |
2026/05/31 10:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:mgmt_power_on]
Results: map[SourceCode:9519: void mgmt_power_on(struct hci_dev *hdev, int err)
9520: {
9521: struct cmd_lookup match = { NULL, hdev };
9522:
9523: bt_dev_dbg(hdev, "err %d", err);
9524:
9525: hci_dev_lock(hdev);
9526:
9527: if (!err) {
9528: restart_le_actions(hdev);
9529: hci_update_passive_scan(hdev);
9530: }
9531:
9532: mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, true, settings_rsp,
9533: &match);
9534:
9535: new_settings(hdev, match.sk);
9536:
9537: if (match.sk)
9538: sock_put(match.sk);
9539:
9540: hci_dev_unlock(hdev);
9541: }
SourceFile:net/bluetooth/mgmt.c]
|
| 82/2 |
2026/05/31 10:20 |
llm |
expert |
0m
Model:
Tokens:
input: 81212
output: 34
thoughts: 13
Thoughts: Here's my understanding of the thought process, summarized as you requested:
**Deconstructing the `mgmt_power_on` Call**
Okay, so `mgmt_power_on` is being triggered. My immediate focus is on understanding what this action entails. The code explicitly states that `mgmt_power_on` calls `new_settings`. This is the core of the operation. This tells me that powering on the management system requires applying a fresh set of configurations. I need to dig into `new_settings` now. I'll need to understand what parameters are used in that settings file. Knowing the settings in advance is very important. I need to determine the format of these settings. Is this an incremental set of changes, or a complete state declaration? Also, what are the implications of the configuration change? Any potential side effects? It is important that I know if the settings will be overwritten upon power on, or if there is the potential to break the existing system. From a security perspective I need to know, is there the possibility of a malicious actor corrupting `new_settings` to introduce vulnerabilities or disrupt the power-on sequence? Understanding the architecture of `mgmt_power_on` is crucial for debugging.
|
| 83/2 |
2026/05/31 10:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:new_settings]
Results: map[SourceCode:1324: static int new_settings(struct hci_dev *hdev, struct sock *skip)
1325: {
1326: __le32 ev = cpu_to_le32(get_current_settings(hdev));
1327:
1328: return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev,
1329: sizeof(ev), HCI_MGMT_SETTING_EVENTS, skip);
1330: }
SourceFile:net/bluetooth/mgmt.c]
|
| 84/2 |
2026/05/31 10:20 |
llm |
expert |
0m
Model:
Tokens:
input: 81674
output: 28
thoughts: 1594
Thoughts: **Analyzing a Bluetooth Concurrency Bug**
Okay, let's break this down. My initial thought was about how `mgmt_limited_event` leads to `mgmt_event`, which iterates through sockets and sends events. The critical point is that it uses `read_lock(&hci_sk_list.lock)` instead of `lock_sock(sk)`. This seemed important, but I need to investigate the context of the lock.
My first thought was that `hci_dev_open` might be called from `hci_sock_bind`, but the call trace says no, it's called from `sock_ioctl` which is unrelated. So, `lock_sock(sk)` isn't held when `hci_dev_open` is called.
Now, let's look at the syzkaller reproducer. It sets up a `cake` qdisc with a netlink socket and I was thinking that somehow the `cake` qdisc setup might call `flush_workqueue`, but the blocked task is `syz-executor`, running `ioctl(HCIDEVUP)`.
The reproducer is a single-threaded C program, so how is this possible?
Wait, there is no `HCIDEVUP` call in the reproducer! But the call trace still leads to `hci_dev_open` from `sock_ioctl`. How can that happen with a netlink socket?
`0x8933` is `SIOCGIFINDEX`, which is strange for a netlink socket. `sock_do_ioctl` calls `ops->ioctl`. For a netlink socket, it would be `netlink_ioctl`, but this either doesn't exist or returns an error. If there is an error, `sock_do_ioctl` falls back to `dev_ioctl`, which handles `SIOCGIFINDEX`, but that doesn't call `hci_dev_open`. So, how is it possible to get to `hci_dev_open`?
Ah, if the socket *isn't* a netlink socket! Then, syzkaller might be running multiple programs together, even if the reproducer *itself* is not a netlink socket.
But syzkaller says it's reproducible *with* the provided program. If this is true, then THIS program should trigger the bug, which it doesn't. And the `cake` qdisc is not related to Bluetooth at all.
Could `cake` qdisc do memory corruption and lead to a wild jump? Unlikely, because the call trace is valid for `HCIDEVUP`.
So why does the reproducer show `AF_NETLINK` and `cake`? Syzkaller could have a faulty reproduction, where the exact syscalls have failed to be isolated, or perhaps the bug is a side effect of something else.
Wait! What if `syz-executor:6137` is a *background* thread that Syzkaller creates, running `HCIDEVUP`, and it's being blocked by the main thread that sets up `cake` qdisc (and potentially holds a lock)?
Yes, syzkaller runs multiple threads! If it's blocked for 152 seconds, it's waiting for something. Specifically, it's waiting for `flush_workqueue(hdev->req_workqueue)`. So, a work item on `req_workqueue` is blocked.
The blocked work item might be `hci_cmd_sync_work`. If so, what is *it* waiting for? Maybe it's waiting for `rtnl_lock`? Does it take `rtnl_lock`?
Let's check if any functions called by `hci_cmd_sync_work` take `rtnl_lock`. `hci_cmd_sync_work` calls `entry->func`. This is the key: Could `entry->func` take `rtnl_lock`? It's time to search for `rtnl_lock` within the Bluetooth code.
|
| 85/2 |
2026/05/31 10:21 |
tool |
grepper |
0m
Args: map[Expression:rtnl_lock PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/6lowpan.c=588=static void ifup(struct net_device *netdev)
--
net/bluetooth/6lowpan.c-591-
net/bluetooth/6lowpan.c:592: rtnl_lock();
net/bluetooth/6lowpan.c-593- err = dev_open(netdev, NULL);
--
net/bluetooth/6lowpan.c=599=static void ifdown(struct net_device *netdev)
net/bluetooth/6lowpan.c-600-{
net/bluetooth/6lowpan.c:601: rtnl_lock();
net/bluetooth/6lowpan.c-602- dev_close(netdev);
]
|
| 86/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 84345
output: 32
thoughts: 253
Thoughts: **Investigating Potential RTNL Lock Contention in Bluetooth Driver Initialization**
Okay, so I'm digging into this Bluetooth driver initialization and trying to pinpoint where a potential lock contention issue might be arising. My initial hunch is always to look at the locking strategy. From what I've seen, only `6lowpan.c` seems to be taking the `rtnl_lock`. That's a potential area to investigate, but I need to understand the full flow.
The immediate question is, does `hci_cmd_sync_work` ever call `ifup` or `ifdown`? The answer, as far as I can see, is no. So, what else could the work item in question be waiting for? I'm thinking perhaps the work item is related to `hci_power_on`? That seems like a likely candidate.
And yes, `hci_power_on` does call `hci_dev_do_open(hdev)`. Okay, `hci_dev_do_open` then calls `hci_dev_open_sync(hdev)`. This is getting closer to the critical path. `hci_dev_open_sync` subsequently calls `hdev->open(hdev)`. This is where it gets interesting, as `hdev` could be one of several different Bluetooth device types.
If `hdev` is a `vhci` device, then `hdev->open` is `vhci_open_dev`, which appears to do absolutely nothing. That's not the source of the problem. What about other device types? What if `hdev` is a `bpf` device? Or is it related to `hci_vhci`? Wait, what about `virtio_bluetooth`? My mind immediately goes to the `virtbt_open` implementation if `hdev->open` is associated with `virtio_bluetooth`... I need to consider that!
This is key, now, does `hdev->open` *itself* take the `rtnl_lock`? If it does, that's where the contention lies, and I can start tracing back the initialization sequence. So, I need to go through each of the potential `hdev->open` implementations very carefully. I'll need to check them all to rule them out. I'll need to be thorough. Let's do this.
|
| 87/2 |
2026/05/31 10:21 |
tool |
grepper |
0m
Args: map[Expression:\.open\s*=\s* PathPrefix:drivers/bluetooth/]
Results: map[Output:drivers/bluetooth/btmrvl_debugfs.c=54=static const struct file_operations btmrvl_hscfgcmd_fops = {
--
drivers/bluetooth/btmrvl_debugfs.c-56- .write = btmrvl_hscfgcmd_write,
drivers/bluetooth/btmrvl_debugfs.c:57: .open = simple_open,
drivers/bluetooth/btmrvl_debugfs.c-58- .llseek = default_llseek,
--
drivers/bluetooth/btmrvl_debugfs.c=94=static const struct file_operations btmrvl_pscmd_fops = {
--
drivers/bluetooth/btmrvl_debugfs.c-96- .write = btmrvl_pscmd_write,
drivers/bluetooth/btmrvl_debugfs.c:97: .open = simple_open,
drivers/bluetooth/btmrvl_debugfs.c-98- .llseek = default_llseek,
--
drivers/bluetooth/btmrvl_debugfs.c=132=static const struct file_operations btmrvl_hscmd_fops = {
--
drivers/bluetooth/btmrvl_debugfs.c-134- .write = btmrvl_hscmd_write,
drivers/bluetooth/btmrvl_debugfs.c:135: .open = simple_open,
drivers/bluetooth/btmrvl_debugfs.c-136- .llseek = default_llseek,
--
drivers/bluetooth/btusb.c=3876=static const struct file_operations force_poll_sync_fops = {
drivers/bluetooth/btusb.c-3877- .owner = THIS_MODULE,
drivers/bluetooth/btusb.c:3878: .open = simple_open,
drivers/bluetooth/btusb.c-3879- .read = force_poll_sync_read,
--
drivers/bluetooth/hci_ag6xx.c=300=static const struct hci_uart_proto ag6xx_proto = {
--
drivers/bluetooth/hci_ag6xx.c-303- .manufacturer = 2,
drivers/bluetooth/hci_ag6xx.c:304: .open = ag6xx_open,
drivers/bluetooth/hci_ag6xx.c-305- .close = ag6xx_close,
--
drivers/bluetooth/hci_aml.c=666=static const struct hci_uart_proto aml_hci_proto = {
--
drivers/bluetooth/hci_aml.c-670- .oper_speed = 4000000,
drivers/bluetooth/hci_aml.c:671: .open = aml_open,
drivers/bluetooth/hci_aml.c-672- .close = aml_close,
--
drivers/bluetooth/hci_ath.c=247=static const struct hci_uart_proto athp = {
--
drivers/bluetooth/hci_ath.c-250- .manufacturer = 69,
drivers/bluetooth/hci_ath.c:251: .open = ath_open,
drivers/bluetooth/hci_ath.c-252- .close = ath_close,
--
drivers/bluetooth/hci_bcm.c=1294=static const struct hci_uart_proto bcm_proto = {
--
drivers/bluetooth/hci_bcm.c-1298- .init_speed = 115200,
drivers/bluetooth/hci_bcm.c:1299: .open = bcm_open,
drivers/bluetooth/hci_bcm.c-1300- .close = bcm_close,
--
drivers/bluetooth/hci_bcsp.c=762=static const struct hci_uart_proto bcsp = {
--
drivers/bluetooth/hci_bcsp.c-764- .name = "BCSP",
drivers/bluetooth/hci_bcsp.c:765: .open = bcsp_open,
drivers/bluetooth/hci_bcsp.c-766- .close = bcsp_close,
--
drivers/bluetooth/hci_h4.c=133=static const struct hci_uart_proto h4p = {
--
drivers/bluetooth/hci_h4.c-135- .name = "H4",
drivers/bluetooth/hci_h4.c:136: .open = h4_open,
drivers/bluetooth/hci_h4.c-137- .close = h4_close,
--
drivers/bluetooth/hci_h5.c=840=static const struct hci_uart_proto h5p = {
--
drivers/bluetooth/hci_h5.c-842- .name = "Three-wire (H5)",
drivers/bluetooth/hci_h5.c:843: .open = h5_open,
drivers/bluetooth/hci_h5.c-844- .close = h5_close,
--
drivers/bluetooth/hci_h5.c=1101=static struct h5_vnd rtl_vnd = {
drivers/bluetooth/hci_h5.c-1102- .setup = h5_btrtl_setup,
drivers/bluetooth/hci_h5.c:1103: .open = h5_btrtl_open,
drivers/bluetooth/hci_h5.c-1104- .close = h5_btrtl_close,
--
drivers/bluetooth/hci_intel.c=1044=static const struct hci_uart_proto intel_proto = {
--
drivers/bluetooth/hci_intel.c-1049- .oper_speed = 3000000,
drivers/bluetooth/hci_intel.c:1050: .open = intel_open,
drivers/bluetooth/hci_intel.c-1051- .close = intel_close,
--
drivers/bluetooth/hci_ldisc.c=828=static struct tty_ldisc_ops hci_uart_ldisc = {
--
drivers/bluetooth/hci_ldisc.c-831- .name = "n_hci",
drivers/bluetooth/hci_ldisc.c:832: .open = hci_uart_tty_open,
drivers/bluetooth/hci_ldisc.c-833- .close = hci_uart_tty_close,
--
drivers/bluetooth/hci_ll.c=798=static const struct hci_uart_proto llp = {
--
drivers/bluetooth/hci_ll.c-801- .setup = ll_setup,
drivers/bluetooth/hci_ll.c:802: .open = ll_open,
drivers/bluetooth/hci_ll.c-803- .close = ll_close,
--
drivers/bluetooth/hci_mrvl.c=434=static const struct hci_uart_proto mrvl_proto_8897 = {
--
drivers/bluetooth/hci_mrvl.c-438- .oper_speed = 3000000,
drivers/bluetooth/hci_mrvl.c:439: .open = mrvl_open,
drivers/bluetooth/hci_mrvl.c-440- .close = mrvl_close,
--
drivers/bluetooth/hci_mrvl.c=448=static const struct hci_uart_proto mrvl_proto_8997 = {
--
drivers/bluetooth/hci_mrvl.c-452- .oper_speed = 3000000,
drivers/bluetooth/hci_mrvl.c:453: .open = mrvl_open,
drivers/bluetooth/hci_mrvl.c-454- .close = mrvl_close,
--
drivers/bluetooth/hci_nokia.c=665=static const struct hci_uart_proto nokia_proto = {
--
drivers/bluetooth/hci_nokia.c-667- .name = "Nokia",
drivers/bluetooth/hci_nokia.c:668: .open = nokia_open,
drivers/bluetooth/hci_nokia.c-669- .close = nokia_close,
--
drivers/bluetooth/hci_qca.c=2046=static const struct hci_uart_proto qca_proto = {
--
drivers/bluetooth/hci_qca.c-2051- .oper_speed = 3000000,
drivers/bluetooth/hci_qca.c:2052: .open = qca_open,
drivers/bluetooth/hci_qca.c-2053- .close = qca_close,
--
drivers/bluetooth/hci_vhci.c=157=static const struct file_operations force_suspend_fops = {
drivers/bluetooth/hci_vhci.c:158: .open = simple_open,
drivers/bluetooth/hci_vhci.c-159- .read = force_suspend_read,
--
drivers/bluetooth/hci_vhci.c=196=static const struct file_operations force_wakeup_fops = {
drivers/bluetooth/hci_vhci.c:197: .open = simple_open,
drivers/bluetooth/hci_vhci.c-198- .read = force_wakeup_read,
--
drivers/bluetooth/hci_vhci.c=265=static const struct file_operations aosp_capable_fops = {
drivers/bluetooth/hci_vhci.c:266: .open = simple_open,
drivers/bluetooth/hci_vhci.c-267- .read = aosp_capable_read,
--
drivers/bluetooth/hci_vhci.c=378=static const struct file_operations force_devcoredump_fops = {
drivers/bluetooth/hci_vhci.c:379: .open = simple_open,
drivers/bluetooth/hci_vhci.c-380- .write = force_devcd_write,
--
drivers/bluetooth/hci_vhci.c=701=static const struct file_operations vhci_fops = {
--
drivers/bluetooth/hci_vhci.c-705- .poll = vhci_poll,
drivers/bluetooth/hci_vhci.c:706: .open = vhci_open,
drivers/bluetooth/hci_vhci.c-707- .release = vhci_release,
]
|
| 88/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 87846
output: 28
thoughts: 708
Thoughts: **Analyzing Potential Deadlocks in the HCI Bluetooth Driver**
Okay, let's break this down. My initial thought was centered on `hdev->open`. I see it's assigned in the driver, specifically `hdev->open = vhci_open_dev;` for `vhci`. But `vhci_open_dev` just returns 0. So, I can be confident that calling `hdev->open` won't block. Good.
Now, the potential bottleneck: What if `hci_cmd_sync_work` ends up blocked in `hci_req_sync_lock`? If `hci_cmd_sync_work` is blocked in `hci_req_sync_lock`, the crucial question becomes, who actually *holds* `hci_req_sync_lock`?
If `hci_dev_open` is called, it calls `flush_workqueue(hdev->req_workqueue)`. But if `hci_dev_open` is called from `sock_ioctl(HCIDEVUP)`, it doesn't hold `hci_req_sync_lock`. Hmmm, I need to consider a race condition. What if `hci_dev_open` is called *concurrently*? Say, thread 1 calls it and thread 2 calls it simultaneously. Let's trace it out:
* **Thread 1:** `hci_dev_open` -> `flush_workqueue` -> `hci_dev_do_open` -> `hci_req_sync_lock`
* **Thread 2:** `hci_dev_open` -> `flush_workqueue`
If Thread 1 is in `hci_dev_do_open` and holds `hci_req_sync_lock`, and it queues a work item on `req_workqueue` and *then* waits for it, we have a problem. Does `hci_dev_open_sync` queue work on `req_workqueue`? That's the question. Let's check `hci_dev_open_sync`. It calls `hci_dev_init_sync`, which in turn calls `hci_init_sync`. Then `hci_init_sync` sends commands using `__hci_cmd_sync_sk`. `__hci_cmd_sync_sk` calls `hci_req_sync_run`. Crucially, `hci_req_sync_run` queues `cmd_work` on `hdev->workqueue`. Importantly, it does *NOT* queue anything on `hdev->req_workqueue`.
Therefore, `hci_dev_open_sync` doesn't wait for `req_workqueue`. It's waiting for `hdev->workqueue`. So, Thread 1 won't deadlock with `req_workqueue`. That's good.
Next: What if `hci_dev_open_sync` also calls `hci_powered_update_sync`? Does `hci_powered_update_sync` send commands and queue anything on `req_workqueue`? No.
Okay, let's shift gears: What about `hci_dev_close`? It calls `hci_dev_do_close` which takes `hci_req_sync_lock`. Then `hci_dev_close_sync` calls `cancel_delayed_work(&hdev->power_off)`. Again, it does not wait for `req_workqueue`.
Finally, the million-dollar question: Is there *any* function that holds `hci_req_sync_lock` and waits for something on `req_workqueue`? I need to search for uses of `flush_workqueue`, `cancel_work_sync`, or `cancel_delayed_work_sync` associated with `req_workqueue` to be certain. That's the key to confirming the absence of deadlock.
|
| 89/2 |
2026/05/31 10:21 |
tool |
grepper |
0m
Args: map[Expression:req_workqueue PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_core.c=438=int hci_dev_open(__u16 dev)
--
net/bluetooth/hci_core.c-473- */
net/bluetooth/hci_core.c:474: flush_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-475-
--
net/bluetooth/hci_core.c=943=static void hci_power_on(struct work_struct *work)
--
net/bluetooth/hci_core.c-977- } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
net/bluetooth/hci_core.c:978: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/hci_core.c-979- HCI_AUTO_OFF_TIMEOUT);
--
net/bluetooth/hci_core.c=2584=int hci_register_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2609-
net/bluetooth/hci_core.c:2610: hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI,
net/bluetooth/hci_core.c-2611- hdev->name);
net/bluetooth/hci_core.c:2612: if (!hdev->req_workqueue) {
net/bluetooth/hci_core.c-2613- destroy_workqueue(hdev->workqueue);
--
net/bluetooth/hci_core.c-2670-
net/bluetooth/hci_core.c:2671: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/hci_core.c-2672-
--
net/bluetooth/hci_core.c-2680- destroy_workqueue(hdev->workqueue);
net/bluetooth/hci_core.c:2681: destroy_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-2682-err:
--
net/bluetooth/hci_core.c=2743=void hci_release_dev(struct hci_dev *hdev)
--
net/bluetooth/hci_core.c-2749- destroy_workqueue(hdev->workqueue);
net/bluetooth/hci_core.c:2750: destroy_workqueue(hdev->req_workqueue);
net/bluetooth/hci_core.c-2751-
--
net/bluetooth/hci_event.c=4411=static void hci_hardware_error_evt(struct hci_dev *hdev, void *data,
--
net/bluetooth/hci_event.c-4419-
net/bluetooth/hci_event.c:4420: queue_work(hdev->req_workqueue, &hdev->error_reset);
net/bluetooth/hci_event.c-4421-}
--
net/bluetooth/hci_sync.c=586=static void interleave_scan_work(struct work_struct *work)
--
net/bluetooth/hci_sync.c-621- if (is_interleave_scanning(hdev))
net/bluetooth/hci_sync.c:622: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-623- &hdev->interleave_scan, timeout);
--
net/bluetooth/hci_sync.c=702=int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
--
net/bluetooth/hci_sync.c-726-
net/bluetooth/hci_sync.c:727: queue_work(hdev->req_workqueue, &hdev->cmd_sync_work);
net/bluetooth/hci_sync.c-728-
--
net/bluetooth/hci_sync.c=1954=int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
--
net/bluetooth/hci_sync.c-1991- hdev->adv_instance_timeout = timeout;
net/bluetooth/hci_sync.c:1992: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-1993- &hdev->adv_instance_expire,
--
net/bluetooth/hci_sync.c=2252=static void hci_start_interleave_scan(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-2254- hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
net/bluetooth/hci_sync.c:2255: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/hci_sync.c-2256- &hdev->interleave_scan, 0);
--
net/bluetooth/hci_sync.c=5397=static int hci_power_on_sync(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-5422- } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
net/bluetooth/hci_sync.c:5423: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/hci_sync.c-5424- HCI_AUTO_OFF_TIMEOUT);
--
net/bluetooth/hci_sync.c=6038=int hci_start_discovery_sync(struct hci_dev *hdev)
--
net/bluetooth/hci_sync.c-6082-
net/bluetooth/hci_sync.c:6083: queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable,
net/bluetooth/hci_sync.c-6084- timeout);
--
net/bluetooth/mgmt.c=1528=static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1550- int to = secs_to_jiffies(hdev->discov_timeout);
net/bluetooth/mgmt.c:1551: queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to);
net/bluetooth/mgmt.c-1552- }
--
net/bluetooth/mgmt.c=1572=static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
--
net/bluetooth/mgmt.c-1661- int to = secs_to_jiffies(hdev->discov_timeout);
net/bluetooth/mgmt.c:1662: queue_delayed_work(hdev->req_workqueue,
net/bluetooth/mgmt.c-1663- &hdev->discov_off, to);
--
net/bluetooth/mgmt.c=2298=static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err)
--
net/bluetooth/mgmt.c-2314- mesh_send_interval = msecs_to_jiffies((send->cnt) * 25);
net/bluetooth/mgmt.c:2315: queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done,
net/bluetooth/mgmt.c-2316- mesh_send_interval);
--
net/bluetooth/mgmt.c=8050=static int set_external_config(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-8093-
net/bluetooth/mgmt.c:8094: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/mgmt.c-8095- } else {
--
net/bluetooth/mgmt.c=8106=static int set_public_address(struct sock *sk, struct hci_dev *hdev,
--
net/bluetooth/mgmt.c-8149-
net/bluetooth/mgmt.c:8150: queue_work(hdev->req_workqueue, &hdev->power_on);
net/bluetooth/mgmt.c-8151- }
]
|
| 90/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 91570
output: 38
thoughts: 569
Thoughts: **Analyzing Potential Deadlock in Bluetooth Device Closure**
Okay, let's break this down systematically. My initial thought is to examine the locking and synchronization around Bluetooth device open and close operations, specifically looking for potential deadlocks.
First, I see that `hci_dev_open` calls `flush_workqueue` on the `req_workqueue`. Interesting. And if `hci_dev_open` is called via `sock_ioctl(HCIDEVUP)`, that call blocks. Hmm, nothing immediately jumps out as problematic here. No other call to `flush_workqueue(hdev->req_workqueue)` anywhere else, seems safe enough.
Now, what if `hci_dev_open` and `hci_dev_close` are called concurrently? `hci_dev_close` calls `hci_dev_do_close`, which takes `hci_req_sync_lock`. If `hci_dev_open` is in progress at the same time, the call to `flush_workqueue(hdev->req_workqueue)` could be problematic. If `req_workqueue` has a `hci_cmd_sync_work` running, this is what is most likely. It will block on `hci_req_sync_lock`. So `hci_cmd_sync_work` waits for `hci_dev_close` to release that lock. Fine, `hci_dev_close` finishes, releases the lock. Then `hci_cmd_sync_work` runs and completes, which should free up `flush_workqueue`. No deadlock there; it just serializes the operations. That's a safe result.
Now, let's dig deeper: What if `hci_dev_close` itself waits for the `req_workqueue` to complete? `hci_dev_close` calls `hci_dev_do_close` then calls `hci_dev_close_sync`. `hci_dev_close_sync` calls `cancel_delayed_work(&hdev->power_off)`. Wait, and it doesn't wait for `req_workqueue` to finish. But `cancel_delayed_work` doesn't wait - `cancel_delayed_work_sync` does. So, that's it! `hci_dev_close_sync` calls `cancel_delayed_work_sync(&hdev->adv_instance_expire)`. Critical point: `adv_instance_expire` runs on `req_workqueue`!
Aha! If `hci_dev_close_sync` calls `cancel_delayed_work_sync(&hdev->adv_instance_expire)`, it *waits* for `adv_instance_expire` to finish. But `hci_dev_close_sync` *also* holds `hci_req_sync_lock(hdev)`! The key question then: Does `adv_instance_expire` take `hci_req_sync_lock(hdev)`? This is the crucial point to verify, now I need to check the implementation of `adv_instance_expire` (or `adv_timeout_expire`) to know if there's a lock contention here.
|
| 91/2 |
2026/05/31 10:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:adv_timeout_expire]
Results: map[SourceCode: 553: static void adv_timeout_expire(struct work_struct *work)
554: {
555: u8 *inst_ptr;
556: struct hci_dev *hdev = container_of(work, struct hci_dev,
557: adv_instance_expire.work);
558:
559: bt_dev_dbg(hdev, "");
560:
561: hci_dev_lock(hdev);
562:
563: hdev->adv_instance_timeout = 0;
564:
565: if (hdev->cur_adv_instance == 0x00)
566: goto unlock;
567:
568: inst_ptr = kmalloc(1, GFP_KERNEL);
569: if (!inst_ptr)
570: goto unlock;
571:
572: *inst_ptr = hdev->cur_adv_instance;
573: hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL);
574:
575: unlock:
576: hci_dev_unlock(hdev);
577: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 92/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 93234
output: 35
thoughts: 429
Thoughts: **Analyzing Potential Deadlocks in HCI Device Closure**
Okay, let me break this down. My initial understanding was that `adv_timeout_expire` grabs the `hci_dev_lock(hdev)`, but crucially, it *doesn't* take the `hci_req_sync_lock(hdev)`. That's good. Therefore, my prior understanding was that `hci_dev_close_sync` waiting for `adv_timeout_expire` shouldn't deadlock on `hci_req_sync_lock`. But wait a second... `hci_dev_close_sync` itself *also* calls `hci_dev_lock(hdev)`! That could be a problem!
Okay, let's look closer. Aha! It's calling `cancel_delayed_work_sync(&hdev->adv_instance_expire)` *before* acquiring the `hci_dev_lock(hdev)`. So, it's not holding the device lock while it's waiting for the advertising instance expiry. That's a relief. So, the original scenario should be deadlock-free.
Now, what about that `cancel_delayed_work_sync(&hdev->le_scan_disable)` call? Hang on, no, it's actually just `cancel_delayed_work(&hdev->le_scan_disable)`. That's even better - non-synchronous cancellation. That avoids potential locking issues related to the scan disable timer.
However, `hci_dev_close_sync` *does* use `cancel_delayed_work_sync(&hdev->rpa_expired)`. This warrants further investigation. I need to verify whether the `rpa_expired` work runs on the request workqueue, or if there's a different workqueue, which would affect how it interacts with the lock. Let's delve into the `rpa_expired` function to determine this.
|
| 93/2 |
2026/05/31 10:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:rpa_expired]
Results: map[SourceCode:1032: static void rpa_expired(struct work_struct *work)
1033: {
1034: struct hci_dev *hdev = container_of(work, struct hci_dev,
1035: rpa_expired.work);
1036:
1037: bt_dev_dbg(hdev, "");
1038:
1039: hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
1040:
1041: if (!hci_dev_test_flag(hdev, HCI_ADVERTISING))
1042: return;
1043:
1044: hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL);
1045: }
SourceFile:net/bluetooth/mgmt.c]
|
| 94/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 94351
output: 52
thoughts: 47
Thoughts: Okay, here's my interpretation of those thoughts, framed as my own:
**RPA Expiry and Workqueues**
Right, so `rpa_expired` is running on `hdev->workqueue`. I need to remember that because it's crucial for context. Okay, so I initialized it with `INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired)`. Makes sense. Now the question is... where *exactly* is it queued? I need to track down the function or context where `queue_delayed_work()` (or similar) is called, or at the very least, understand the specific queuing mechanism. Understanding the scheduling context of this expiry task is absolutely critical for debugging, performance analysis, and potentially optimizing the related code path. It's time to dig deeper!
|
| 95/2 |
2026/05/31 10:21 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c IncludeSnippetLines:2 Name:rpa_expired SourceTreePrefix:net/bluetooth/]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:mgmt_init_hdev SourceFile:net/bluetooth/mgmt.c SourceLine:1141 SourceSnippet:1139: INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
1140: INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
1141: INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired);
1142: INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done);
1143:
]] TruncatedOutput:false]
|
| 96/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 94823
output: 34
thoughts: 17
Thoughts: Here's my attempt at summarizing that thought process, tailored for an expert audience:
**RPA Expiration Conundrum**
Okay, so I'm looking at this code, and I'm seeing `queue_delayed_work` called with `rpa_expired`. My initial reaction is a slight eyebrow raise. Why are we queuing *delayed* work for something that's explicitly labeled as "expired"? Doesn't that suggest a problem we should be addressing immediately? The "expired" state, in my experience, often implies a time-sensitive issue β an event that has crossed a hard deadline. Delaying action on an expired RPA feels counterintuitive, potentially opening the door to complications or missed opportunities. I need to dig deeper here. What's the *specific* use case? What's the underlying logic? Perhaps there's a good reason, like a graceful shutdown or a deferred cleanup, that warrants this delayed processing. But itβs definitely something that warrants close examination to ensure we're not introducing a subtle bug or performance bottleneck. This requires understanding the workflow.
|
| 97/2 |
2026/05/31 10:21 |
tool |
grepper |
0m
Args: map[Expression:queue_delayed_work.*rpa_expired PathPrefix:net/bluetooth/]
Results: map[Output:net/bluetooth/hci_event.c=1347=static u8 hci_cc_le_set_random_addr(struct hci_dev *hdev, void *data,
--
net/bluetooth/hci_event.c-1367- hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED);
net/bluetooth/hci_event.c:1368: queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
net/bluetooth/hci_event.c-1369- secs_to_jiffies(hdev->rpa_timeout));
]
|
| 98/2 |
2026/05/31 10:21 |
llm |
expert |
0m
Model:
Tokens:
input: 95265
output: 36
thoughts: 441
Thoughts: **Debugging a Bluetooth Device Open Hang**
Okay, so this is queued on `hdev->workqueue`. The problem seems to be a hang, so let's dig into `hci_dev_open`. That calls `flush_workqueue(hdev->req_workqueue)`. If `hci_dev_open` is stuck in that flush call, that means a work item on `req_workqueue` is blocked. Let's see... what work item could that be? Ah, `hci_cmd_sync_work`!
If *that* is blocked, what's it blocked on? It's taking `hci_req_sync_lock(hdev)`. Okay, so if that's held, who's holding it? Could it be `hci_dev_open` *itself*? Wait, no! `hci_dev_open` doesn't hold that lock *before* calling `flush_workqueue`.
But what if `hci_dev_do_open` is called, it holds the lock, then it queues something on `req_workqueue` and *waits* for that? No, `hci_dev_do_open` doesn't wait for `req_workqueue`. We checked that.
Hang on... what if `hci_cmd_sync_work` is blocked on `hdev->cmd_sync_work_lock`? No, that's just a mutex used briefly during dequeue. Scratch that.
Hmm... What if `hci_cmd_sync_work` is blocked *inside* `entry->func`? That's the key. `entry->func` could be `set_powered_sync`. Does *that* block? Bingo! `set_powered_sync` calls `hci_dev_open_sync` or `hci_dev_close_sync`! It's likely that a recursive call to `hci_dev_open` or `hci_dev_close` could be the hang point. Looks like we need to dig into how those sync calls behave.
|
| 99/2 |
2026/05/31 10:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:set_powered_sync]
Results: map[SourceCode:1368: static int set_powered_sync(struct hci_dev *hdev, void *data)
1369: {
1370: struct mgmt_pending_cmd *cmd = data;
1371: struct mgmt_mode cp;
1372:
1373: mutex_lock(&hdev->mgmt_pending_lock);
1374:
1375: /* Make sure cmd still outstanding. */
1376: if (!__mgmt_pending_listed(hdev, cmd)) {
1377: mutex_unlock(&hdev->mgmt_pending_lock);
1378: return -ECANCELED;
1379: }
1380:
1381: memcpy(&cp, cmd->param, sizeof(cp));
1382:
1383: mutex_unlock(&hdev->mgmt_pending_lock);
1384:
1385: BT_DBG("%s", hdev->name);
1386:
1387: return hci_set_powered_sync(hdev, cp.val);
1388: }
SourceFile:net/bluetooth/mgmt.c]
|
| 100/2 |
2026/05/31 10:21 |
llm |
expert |
1m
Model:
Tokens:
input: 96511
output: 40
thoughts: 13
Thoughts: Okay, let's dive into this. Here's my thought process on this prompt:
**Analyzing the Request: `hci_set_powered_sync`**
Alright, the request is clear. We're zeroing in on `hci_set_powered_sync`. This immediately flags a specific area for me - something related to Bluetooth, likely Low Energy given the "hci" prefix and power management or state synchronization. It's a low-level HCI (Host Controller Interface) command, probably operating close to the Bluetooth controller itself. We're likely dealing with configuring or signaling a change in the powered state of a Bluetooth device or connection. The "sync" part implies some sort of coordination, ensuring the state is consistent between the host and the controller, or perhaps across multiple components. I'm already mentally running through potential issues related to power management, connection stability, race conditions, and error handling. I'm curious what context surrounds this call. Is it being triggered by user action, an event, or a background process? What are the expected states and transitions? And of course, the underlying platform is key. This could be anything from embedded systems to smartphones to PCs. Let's see what the full prompt brings.
|
| 101/2 |
2026/05/31 10:22 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_set_powered_sync]
Results: map[SourceCode:5797: int hci_set_powered_sync(struct hci_dev *hdev, u8 val)
5798: {
5799: if (val)
5800: return hci_power_on_sync(hdev);
5801:
5802: return hci_power_off_sync(hdev);
5803: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 102/2 |
2026/05/31 10:22 |
llm |
expert |
0m
Model:
Tokens:
input: 96951
output: 40
thoughts: 13
Thoughts: Okay, let's dive into this. Here's my thought process on checking `hci_power_on_sync`:
**Examining `hci_power_on_sync`**
Alright, time to dissect this. `hci_power_on_sync`. Immediately, I'm thinking Bluetooth Host Controller Interface (HCI), specifically related to power-on synchronization. That's the core. What needs synchronization at power-on in HCI? The controller and the host, obviously. I need to figure out what data or actions we are talking about. Is this a critical piece that if out of sync can cause major issues, like data corruption or system instability, or is this more of an initialization step that might cause some minor issues if itβs not handled well?
I need to remember what this sync step actually involves. What's the potential for race conditions? Are we dealing with hardware registers, message passing, or something else entirely? I should check the surrounding code, see what functions call this, and understand its role in the bigger picture. Are there any known issues associated with this function? Are there any specific hardware revisions or configurations where this is particularly important? Maybe I'll also check the timing requirements of this function. I'll need to go through the associated documentation or the code comments to get a better understanding of what's going on. I'm going to look for any potential bottlenecks or areas that might introduce latency, especially during the boot process. Okay, let's start digging deeper...
|
| 103/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_sync.c Name:hci_power_on_sync]
Results: map[SourceCode:5391: /* This function perform power on HCI command sequence as follows:
5392: *
5393: * If controller is already up (HCI_UP) performs hci_powered_update_sync
5394: * sequence otherwise run hci_dev_open_sync which will follow with
5395: * hci_powered_update_sync after the init sequence is completed.
5396: */
5397: static int hci_power_on_sync(struct hci_dev *hdev)
5398: {
5399: int err;
5400:
5401: if (test_bit(HCI_UP, &hdev->flags) &&
5402: hci_dev_test_flag(hdev, HCI_MGMT) &&
5403: hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {
5404: cancel_delayed_work(&hdev->power_off);
5405: return hci_powered_update_sync(hdev);
5406: }
5407:
5408: err = hci_dev_open_sync(hdev);
5409: if (err < 0)
5410: return err;
5411:
5412: /* During the HCI setup phase, a few error conditions are
5413: * ignored and they need to be checked now. If they are still
5414: * valid, it is important to return the device back off.
5415: */
5416: if (hci_dev_test_flag(hdev, HCI_RFKILLED) ||
5417: hci_dev_test_flag(hdev, HCI_UNCONFIGURED) ||
5418: (!bacmp(&hdev->bdaddr, BDADDR_ANY) &&
5419: !bacmp(&hdev->static_addr, BDADDR_ANY))) {
5420: hci_dev_clear_flag(hdev, HCI_AUTO_OFF);
5421: hci_dev_close_sync(hdev);
5422: } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
5423: queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
5424: HCI_AUTO_OFF_TIMEOUT);
5425: }
5426:
5427: if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) {
5428: /* For unconfigured devices, set the HCI_RAW flag
5429: * so that userspace can easily identify them.
5430: */
5431: if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
5432: set_bit(HCI_RAW, &hdev->flags);
5433:
5434: /* For fully configured devices, this will send
5435: * the Index Added event. For unconfigured devices,
5436: * it will send Unconfigued Index Added event.
5437: *
5438: * Devices with HCI_QUIRK_RAW_DEVICE are ignored
5439: * and no event will be send.
5440: */
5441: mgmt_index_added(hdev);
5442: } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) {
5443: /* When the controller is now configured, then it
5444: * is important to clear the HCI_RAW flag.
5445: */
5446: if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
5447: clear_bit(HCI_RAW, &hdev->flags);
5448:
5449: /* Powering on the controller with HCI_CONFIG set only
5450: * happens with the transition from unconfigured to
5451: * configured. This will send the Index Added event.
5452: */
5453: mgmt_index_added(hdev);
5454: }
5455:
5456: return 0;
5457: }
SourceFile:net/bluetooth/hci_sync.c]
|
| 104/2 |
2026/05/31 10:23 |
llm |
expert |
0m
Model:
Tokens:
input: 98482
output: 38
thoughts: 437
Thoughts: **Debugging a Potential Bluetooth Subsystem Deadlock**
Okay, let's break this down. I see that `hci_power_on_sync` is calling `hci_dev_open_sync`, and that function is critical. But where is it *being* called from? Ah, `hci_power_on_sync` is called from `set_powered_sync`, which in turn, is called from `hci_cmd_sync_work`. And `hci_cmd_sync_work` is running on `hdev->req_workqueue`! So we have `hci_dev_open_sync` also running on `hdev->req_workqueue`.
Now, something sticks out: `hci_dev_open_sync` itself *doesn't* call `flush_workqueue(hdev->req_workqueue)`. That's important. However, if `hci_dev_open` *is* called concurrently, it *does* call `flush_workqueue(hdev->req_workqueue)`. This would wait for `hci_cmd_sync_work` to complete. But waitβ¦`hci_cmd_sync_work` is *already* running `hci_power_on_sync`, which then calls `hci_dev_open_sync`. `hci_dev_open_sync` then calls `hdev->open(hdev)`.
If `hdev->open` is `vhci_open_dev`, it returns 0. That looks clean. Then `hci_dev_init_sync` is called. Okay, `hci_dev_init_sync` sends commands using `__hci_cmd_sync_sk`. `__hci_cmd_sync_sk` queues `cmd_work` on `hdev->workqueue` and waits for a response. If the response comes, great; it continues. If there's a timeout, it returns `-ETIMEDOUT`.
So theoretically, `hci_cmd_sync_work` should *eventually* finish. So why the 152-second delay? Thatβs far too long. Could there be a deadlock in here somewhere? I'm starting to get worried that `__hci_cmd_sync_sk` might be waiting for `cmd_work` to run, but `cmd_work` is somehow blocked. That's a classic deadlock scenario. Time to check `hci_cmd_work`. I have a feeling we're going to find something there.
|
| 105/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c Name:hci_cmd_work]
Results: map[SourceCode:4137: static void hci_cmd_work(struct work_struct *work)
4138: {
4139: struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work);
4140: struct sk_buff *skb;
4141: int err;
4142:
4143: BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name,
4144: atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q));
4145:
4146: /* Send queued commands */
4147: if (atomic_read(&hdev->cmd_cnt)) {
4148: skb = skb_dequeue(&hdev->cmd_q);
4149: if (!skb)
4150: return;
4151:
4152: err = hci_send_cmd_sync(hdev, skb);
4153: if (err)
4154: return;
4155:
4156: rcu_read_lock();
4157: if (test_bit(HCI_RESET, &hdev->flags) ||
4158: hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
4159: cancel_delayed_work(&hdev->cmd_timer);
4160: else
4161: queue_delayed_work(hdev->workqueue, &hdev->cmd_timer,
4162: HCI_CMD_TIMEOUT);
4163: rcu_read_unlock();
4164: }
4165: }
SourceFile:net/bluetooth/hci_core.c]
|
| 106/2 |
2026/05/31 10:23 |
llm |
expert |
0m
Model:
Tokens:
input: 99985
output: 34
thoughts: 865
Thoughts: **The Root Cause of the HCI Hung Task**
Okay, let me break this down. My initial thought process was tracking the execution path of `hci_cmd_sync_work`. It's a command that gets sent using `hci_send_cmd_sync`, which then calls `vhci_send_frame` if the device is a `vhci` device. `vhci_send_frame` queues the command on `data->readq` and wakes up a reader. If there's no reader (e.g., nothing reading from `/dev/vhci`), the response isn't processed. This leads to a timeout of about 2 seconds, which is handled by `__hci_cmd_sync_sk`, resulting in `hci_init_sync`, `hci_dev_init_sync`, `hci_dev_open_sync`, `hci_power_on_sync`, and `set_powered_sync` failing. All of this should ideally take at most 2 seconds, and then `hci_cmd_sync_work` finishes.
However, the reported bug takes a lot longer, around 152 seconds. I initially thought: "Could it be that `hci_dev_open_sync` fails and the next entry in `cmd_sync_work_list` then gets processed?". If 76 of these entries exist, and each takes 2 seconds to fail, it makes perfect sense. Who could queue 76 entries on this list? Then it hit me: The syzkaller reproducer. Even though it doesn't directly send `MGMT_OP_SET_POWERED` in the repro, syzkaller runs multiple programs, so it could fuzz `mgmt` sockets and send a burst of these commands. Each command schedules `set_powered_sync` on `req_workqueue`. `hci_cmd_sync_work` then has to process all of them one at a time. If the device is `vhci` with no reader, each `hci_power_on_sync` takes 2 seconds to time out. So 76 commands translate to 152 seconds.
While `hci_cmd_sync_work` is running, if another thread calls `ioctl(HCIDEVUP)`, which in turn calls `hci_dev_open`, it also calls `flush_workqueue(hdev->req_workqueue)`. `flush_workqueue` waits for `hci_cmd_sync_work` to complete, blocking for 152 seconds, which explains the "hung task" warning. It makes sense, as the watchdog detects the thread blocking for longer than 120 seconds.
This explains the bug perfectly! It's a Denial of Service (DoS) vulnerability. An unprivileged user can send many `MGMT_OP_SET_POWERED` commands (or similar commands that time out) and then trigger `HCIDEVUP` (or another call to `flush_workqueue`), which leads to the hung task. Now, it would be important to investigate whether an unprivileged user can, indeed, send the `MGMT_OP_SET_POWERED` command!
|
| 107/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:set_powered]
Results: map[SourceCode:1390: static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
1391: u16 len)
1392: {
1393: struct mgmt_mode *cp = data;
1394: struct mgmt_pending_cmd *cmd;
1395: int err;
1396:
1397: bt_dev_dbg(hdev, "sock %p", sk);
1398:
1399: if (cp->val != 0x00 && cp->val != 0x01)
1400: return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
1401: MGMT_STATUS_INVALID_PARAMS);
1402:
1403: hci_dev_lock(hdev);
1404:
1405: if (!cp->val) {
1406: if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) {
1407: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
1408: MGMT_STATUS_BUSY);
1409: goto failed;
1410: }
1411: }
1412:
1413: if (pending_find(MGMT_OP_SET_POWERED, hdev)) {
1414: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
1415: MGMT_STATUS_BUSY);
1416: goto failed;
1417: }
1418:
1419: if (!!cp->val == hdev_is_powered(hdev)) {
1420: err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev);
1421: goto failed;
1422: }
1423:
1424: cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len);
1425: if (!cmd) {
1426: err = -ENOMEM;
1427: goto failed;
1428: }
1429:
1430: /* Cancel potentially blocking sync operation before power off */
1431: if (cp->val == 0x00) {
1432: hci_cmd_sync_cancel_sync(hdev, -EHOSTDOWN);
1433: err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd,
1434: mgmt_set_powered_complete);
1435: } else {
1436: /* Use hci_cmd_sync_submit since hdev might not be running */
1437: err = hci_cmd_sync_submit(hdev, set_powered_sync, cmd,
1438: mgmt_set_powered_complete);
1439: }
1440:
1441: if (err < 0)
1442: mgmt_pending_remove(cmd);
1443:
1444: failed:
1445: hci_dev_unlock(hdev);
1446: return err;
1447: }
SourceFile:net/bluetooth/mgmt.c]
|
| 108/2 |
2026/05/31 10:23 |
llm |
expert |
0m
Model:
Tokens:
input: 102487
output: 34
thoughts: 147
Thoughts: **Analyzing the Concurrency of Bluetooth Commands**
Okay, wait a minute. This `set_powered` function... I need to really understand this. It seems that `set_powered` calls `pending_find(MGMT_OP_SET_POWERED, hdev)`. So, if there's *already* a `MGMT_OP_SET_POWERED` command pending, it returns `MGMT_STATUS_BUSY`. Right, so you CANNOT stack up 76 `MGMT_OP_SET_POWERED` calls as I had initially considered. That's not how this works. You can only have *one* in the queue.
Okay, so if only one is processed, that means `hci_cmd_sync_work` will only handle a single `set_powered_sync` at a time. And that takes a solid two seconds to complete, which is a real bottleneck.
Now, that brings me to the core issue. What *other* Bluetooth commands are also using `hci_cmd_sync_submit` or `hci_cmd_sync_queue`? I need to understand if this single-queue limitation is affecting other critical functions. I think `add_uuid` uses these, let me check. Let's see what else might be in a similar state. I need to know where the choke points are.
|
| 109/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:add_uuid]
Results: map[SourceCode:2745: static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
2746: {
2747: struct mgmt_cp_add_uuid *cp = data;
2748: struct mgmt_pending_cmd *cmd;
2749: struct bt_uuid *uuid;
2750: int err;
2751:
2752: bt_dev_dbg(hdev, "sock %p", sk);
2753:
2754: hci_dev_lock(hdev);
2755:
2756: if (pending_eir_or_class(hdev)) {
2757: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID,
2758: MGMT_STATUS_BUSY);
2759: goto failed;
2760: }
2761:
2762: uuid = kmalloc(sizeof(*uuid), GFP_KERNEL);
2763: if (!uuid) {
2764: err = -ENOMEM;
2765: goto failed;
2766: }
2767:
2768: memcpy(uuid->uuid, cp->uuid, 16);
2769: uuid->svc_hint = cp->svc_hint;
2770: uuid->size = get_uuid_size(cp->uuid);
2771:
2772: list_add_tail(&uuid->list, &hdev->uuids);
2773:
2774: cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len);
2775: if (!cmd) {
2776: err = -ENOMEM;
2777: goto failed;
2778: }
2779:
2780: /* MGMT_OP_ADD_UUID don't require adapter the UP/Running so use
2781: * hci_cmd_sync_submit instead of hci_cmd_sync_queue.
2782: */
2783: err = hci_cmd_sync_submit(hdev, add_uuid_sync, cmd,
2784: mgmt_class_complete);
2785: if (err < 0) {
2786: mgmt_pending_free(cmd);
2787: goto failed;
2788: }
2789:
2790: failed:
2791: hci_dev_unlock(hdev);
2792: return err;
2793: }
SourceFile:net/bluetooth/mgmt.c]
|
| 110/2 |
2026/05/31 10:23 |
llm |
expert |
0m
Model:
Tokens:
input: 103697
output: 35
thoughts: 88
Thoughts: Here's my understanding of the situation:
**Analyzing `add_uuid` Command Behavior**
Okay, so `add_uuid` has a built-in mechanism to prevent concurrent execution with commands that modify EIR or the class of device. It calls `pending_eir_or_class(hdev)` first. If this function returns true, meaning an EIR or class-altering command is already pending, `add_uuid` will immediately return `MGMT_STATUS_BUSY`. This implies that we are limited to queuing only a single `add_uuid` command at a time, which makes sense. We don't want to get into a race condition when managing the EIR or class of the device.
Now, I'm starting to think about the broader picture of how the command queue works in this section of the code. My question then becomes: how does the system handle other commands? What about `hci_cmd_sync_queue`? Can we actually have a stack of commands? Is there some other mechanism that limits queuing in certain cases? Let's check `set_discoverable`. Checking it will give me better insights into the mechanics of the command queue.
|
| 111/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:set_discoverable]
Results: map[SourceCode:1572: static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
1573: u16 len)
1574: {
1575: struct mgmt_cp_set_discoverable *cp = data;
1576: struct mgmt_pending_cmd *cmd;
1577: u16 timeout;
1578: int err;
1579:
1580: bt_dev_dbg(hdev, "sock %p", sk);
1581:
1582: if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) &&
1583: !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
1584: return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1585: MGMT_STATUS_REJECTED);
1586:
1587: if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)
1588: return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1589: MGMT_STATUS_INVALID_PARAMS);
1590:
1591: timeout = __le16_to_cpu(cp->timeout);
1592:
1593: /* Disabling discoverable requires that no timeout is set,
1594: * and enabling limited discoverable requires a timeout.
1595: */
1596: if ((cp->val == 0x00 && timeout > 0) ||
1597: (cp->val == 0x02 && timeout == 0))
1598: return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1599: MGMT_STATUS_INVALID_PARAMS);
1600:
1601: hci_dev_lock(hdev);
1602:
1603: if (!hdev_is_powered(hdev) && timeout > 0) {
1604: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1605: MGMT_STATUS_NOT_POWERED);
1606: goto failed;
1607: }
1608:
1609: if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
1610: pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
1611: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1612: MGMT_STATUS_BUSY);
1613: goto failed;
1614: }
1615:
1616: if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) {
1617: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1618: MGMT_STATUS_REJECTED);
1619: goto failed;
1620: }
1621:
1622: if (hdev->advertising_paused) {
1623: err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
1624: MGMT_STATUS_BUSY);
1625: goto failed;
1626: }
1627:
1628: if (!hdev_is_powered(hdev)) {
1629: bool changed = false;
1630:
1631: /* Setting limited discoverable when powered off is
1632: * not a valid operation since it requires a timeout
1633: * and so no need to check HCI_LIMITED_DISCOVERABLE.
1634: */
1635: if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) {
1636: hci_dev_change_flag(hdev, HCI_DISCOVERABLE);
1637: changed = true;
1638: }
1639:
1640: err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
1641: if (err < 0)
1642: goto failed;
1643:
1644: if (changed)
1645: err = new_settings(hdev, sk);
1646:
1647: goto failed;
1648: }
1649:
1650: /* If the current mode is the same, then just update the timeout
1651: * value with the new value. And if only the timeout gets updated,
1652: * then no need for any HCI transactions.
1653: */
1654: if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) &&
1655: (cp->val == 0x02) == hci_dev_test_flag(hdev,
1656: HCI_LIMITED_DISCOVERABLE)) {
1657: cancel_delayed_work(&hdev->discov_off);
1658: hdev->discov_timeout = timeout;
1659:
1660: if (cp->val && hdev->discov_timeout > 0) {
1661: int to = secs_to_jiffies(hdev->discov_timeout);
1662: queue_delayed_work(hdev->req_workqueue,
1663: &hdev->discov_off, to);
1664: }
1665:
1666: err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
1667: goto failed;
1668: }
1669:
1670: cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len);
1671: if (!cmd) {
1672: err = -ENOMEM;
1673: goto failed;
1674: }
1675:
1676: /* Cancel any potential discoverable timeout that might be
1677: * still active and store new timeout value. The arming of
1678: * the timeout happens in the complete handler.
1679: */
1680: cancel_delayed_work(&hdev->discov_off);
1681: hdev->discov_timeout = timeout;
1682:
1683: if (cp->val)
1684: hci_dev_set_flag(hdev, HCI_DISCOVERABLE);
1685: else
1686: hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
1687:
1688: /* Limited discoverable mode */
1689: if (cp->val == 0x02)
1690: hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE);
1691: else
1692: hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
1693:
1694: err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd,
1695: mgmt_set_discoverable_complete);
1696:
1697: if (err < 0)
1698: mgmt_pending_remove(cmd);
1699:
1700: failed:
1701: hci_dev_unlock(hdev);
1702: return err;
1703: }
SourceFile:net/bluetooth/mgmt.c]
|
| 112/2 |
2026/05/31 10:23 |
llm |
expert |
0m
Model:
Tokens:
input: 106233
output: 34
thoughts: 73
Thoughts: Okay, here's my breakdown of this logic, thinking through it as if it's my own internal reasoning:
**Analyzing `set_discoverable` and Potential Command Queueing**
Alright, so `set_discoverable` is calling `pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)`. Right. So, that `pending_find` function is the gatekeeper here. It's essentially saying: "Hold up, are we already in the process of setting discoverability?" If so, we're not going to allow another one to be initiated. The system only permits one `set_discoverable` operation at a time. This makes sense from a resource and state management perspective, you don't want these commands stepping on each other.
But wait a minute... that got me thinking. If `set_discoverable` is this restrictive, are *any* of the management commands designed to be queued? Is there ANY command that bypasses this `pending_find` check? That would allow for multiple operations to be requested in a row. Let's see... let's check `add_device`. I want to investigate whether it has a similar blocking behavior and see if it can be added to the queue, or if other commands can be queued. It's time to dig into that function now.
|
| 113/2 |
2026/05/31 10:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:add_device]
Results: map[SourceCode:7667: static int add_device(struct sock *sk, struct hci_dev *hdev,
7668: void *data, u16 len)
7669: {
7670: struct mgmt_pending_cmd *cmd;
7671: struct mgmt_cp_add_device *cp = data;
7672: u8 auto_conn, addr_type;
7673: struct hci_conn_params *params;
7674: int err;
7675: u32 current_flags = 0;
7676: u32 supported_flags;
7677:
7678: bt_dev_dbg(hdev, "sock %p", sk);
7679:
7680: if (!bdaddr_type_is_valid(cp->addr.type) ||
7681: !bacmp(&cp->addr.bdaddr, BDADDR_ANY))
7682: return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7683: MGMT_STATUS_INVALID_PARAMS,
7684: &cp->addr, sizeof(cp->addr));
7685:
7686: if (cp->action != 0x00 && cp->action != 0x01 && cp->action != 0x02)
7687: return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7688: MGMT_STATUS_INVALID_PARAMS,
7689: &cp->addr, sizeof(cp->addr));
7690:
7691: hci_dev_lock(hdev);
7692:
7693: if (cp->addr.type == BDADDR_BREDR) {
7694: /* Only incoming connections action is supported for now */
7695: if (cp->action != 0x01) {
7696: err = mgmt_cmd_complete(sk, hdev->id,
7697: MGMT_OP_ADD_DEVICE,
7698: MGMT_STATUS_INVALID_PARAMS,
7699: &cp->addr, sizeof(cp->addr));
7700: goto unlock;
7701: }
7702:
7703: err = hci_bdaddr_list_add_with_flags(&hdev->accept_list,
7704: &cp->addr.bdaddr,
7705: cp->addr.type, 0);
7706: if (err)
7707: goto unlock;
7708:
7709: hci_update_scan(hdev);
7710:
7711: goto added;
7712: }
7713:
7714: addr_type = le_addr_type(cp->addr.type);
7715:
7716: if (cp->action == 0x02)
7717: auto_conn = HCI_AUTO_CONN_ALWAYS;
7718: else if (cp->action == 0x01)
7719: auto_conn = HCI_AUTO_CONN_DIRECT;
7720: else
7721: auto_conn = HCI_AUTO_CONN_REPORT;
7722:
7723: /* Kernel internally uses conn_params with resolvable private
7724: * address, but Add Device allows only identity addresses.
7725: * Make sure it is enforced before calling
7726: * hci_conn_params_lookup.
7727: */
7728: if (!hci_is_identity_address(&cp->addr.bdaddr, addr_type)) {
7729: err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7730: MGMT_STATUS_INVALID_PARAMS,
7731: &cp->addr, sizeof(cp->addr));
7732: goto unlock;
7733: }
7734:
7735: /* If the connection parameters don't exist for this device,
7736: * they will be created and configured with defaults.
7737: */
7738: params = hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type,
7739: auto_conn);
7740: if (!params) {
7741: err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7742: MGMT_STATUS_FAILED, &cp->addr,
7743: sizeof(cp->addr));
7744: goto unlock;
7745: }
7746:
7747: cmd = mgmt_pending_new(sk, MGMT_OP_ADD_DEVICE, hdev, data, len);
7748: if (!cmd) {
7749: err = -ENOMEM;
7750: goto unlock;
7751: }
7752:
7753: err = hci_cmd_sync_queue(hdev, add_device_sync, cmd,
7754: add_device_complete);
7755: if (err < 0) {
7756: err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7757: MGMT_STATUS_FAILED, &cp->addr,
7758: sizeof(cp->addr));
7759: mgmt_pending_free(cmd);
7760: }
7761:
7762: goto unlock;
7763:
7764: added:
7765: device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action);
7766: supported_flags = hdev->conn_flags;
7767: device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type,
7768: supported_flags, current_flags);
7769:
7770: err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7771: MGMT_STATUS_SUCCESS, &cp->addr,
7772: sizeof(cp->addr));
7773:
7774: unlock:
7775: hci_dev_unlock(hdev);
7776: return err;
7777: }
SourceFile:net/bluetooth/mgmt.c]
|
| 114/2 |
2026/05/31 10:23 |
llm |
expert |
1m
Model:
Tokens:
input: 108404
output: 34
thoughts: 287
Thoughts: **My Analysis of a Potential Denial of Service Vulnerability**
Okay, so I'm digging into this `add_device` function, and something's immediately jumping out at me. It doesn't seem to have any checks for `pending_find`! It just blindly schedules `add_device_sync` on the `req_workqueue`. Interesting. Now, `add_device_sync` itself calls `hci_update_passive_scan_sync`. I need to think about this... Does `hci_update_passive_scan_sync` actually send commands? Ah, yes, it does! It stops and restarts scanning.
Now, here's where it gets interesting, particularly if the device is a `vhci` device and no one is actually reading from it. The commands will time out after 2 seconds. Okay, so if an attacker can somehow send, say, 76 `MGMT_OP_ADD_DEVICE` commands... and if that many work requests are queued up, each will timeout for 2 seconds. That's 76 times 2... 152 seconds total!
Then, the attacker runs `HCIDEVUP`, which calls `hci_dev_open`. And `hci_dev_open` then calls `flush_workqueue(hdev->req_workqueue)`. Boom. That's going to block for a full 152 seconds. The hung task watchdog is going to kick in, and if `panic_on_hung_task` is set, the system will crash, or at the very least, print a warning. This is a clear Denial of Service scenario!
I need to confirm whether `MGMT_OP_ADD_DEVICE` is accessible to unprivileged users. I'll take a quick look at `mgmt_handlers` in `mgmt.c` to verify.
|
| 115/2 |
2026/05/31 10:24 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/bluetooth/mgmt.c Name:mgmt_handlers]
Results: map[SourceCode:9327: static const struct hci_mgmt_handler mgmt_handlers[] = {
9328: { NULL }, /* 0x0000 (no command) */
9329: { read_version, MGMT_READ_VERSION_SIZE,
9330: HCI_MGMT_NO_HDEV |
9331: HCI_MGMT_UNTRUSTED },
9332: { read_commands, MGMT_READ_COMMANDS_SIZE,
9333: HCI_MGMT_NO_HDEV |
9334: HCI_MGMT_UNTRUSTED },
9335: { read_index_list, MGMT_READ_INDEX_LIST_SIZE,
9336: HCI_MGMT_NO_HDEV |
9337: HCI_MGMT_UNTRUSTED },
9338: { read_controller_info, MGMT_READ_INFO_SIZE,
9339: HCI_MGMT_UNTRUSTED },
9340: { set_powered, MGMT_SETTING_SIZE },
9341: { set_discoverable, MGMT_SET_DISCOVERABLE_SIZE },
9342: { set_connectable, MGMT_SETTING_SIZE },
9343: { set_fast_connectable, MGMT_SETTING_SIZE },
9344: { set_bondable, MGMT_SETTING_SIZE },
9345: { set_link_security, MGMT_SETTING_SIZE },
9346: { set_ssp, MGMT_SETTING_SIZE },
9347: { set_hs, MGMT_SETTING_SIZE },
9348: { set_le, MGMT_SETTING_SIZE },
9349: { set_dev_class, MGMT_SET_DEV_CLASS_SIZE },
9350: { set_local_name, MGMT_SET_LOCAL_NAME_SIZE },
9351: { add_uuid, MGMT_ADD_UUID_SIZE },
9352: { remove_uuid, MGMT_REMOVE_UUID_SIZE },
9353: { load_link_keys, MGMT_LOAD_LINK_KEYS_SIZE,
9354: HCI_MGMT_VAR_LEN },
9355: { load_long_term_keys, MGMT_LOAD_LONG_TERM_KEYS_SIZE,
9356: HCI_MGMT_VAR_LEN },
9357: { disconnect, MGMT_DISCONNECT_SIZE },
9358: { get_connections, MGMT_GET_CONNECTIONS_SIZE },
9359: { pin_code_reply, MGMT_PIN_CODE_REPLY_SIZE },
9360: { pin_code_neg_reply, MGMT_PIN_CODE_NEG_REPLY_SIZE },
9361: { set_io_capability, MGMT_SET_IO_CAPABILITY_SIZE },
9362: { pair_device, MGMT_PAIR_DEVICE_SIZE },
9363: { cancel_pair_device, MGMT_CANCEL_PAIR_DEVICE_SIZE },
9364: { unpair_device, MGMT_UNPAIR_DEVICE_SIZE },
9365: { user_confirm_reply, MGMT_USER_CONFIRM_REPLY_SIZE },
9366: { user_confirm_neg_reply, MGMT_USER_CONFIRM_NEG_REPLY_SIZE },
9367: { user_passkey_reply, MGMT_USER_PASSKEY_REPLY_SIZE },
9368: { user_passkey_neg_reply, MGMT_USER_PASSKEY_NEG_REPLY_SIZE },
9369: { read_local_oob_data, MGMT_READ_LOCAL_OOB_DATA_SIZE },
9370: { add_remote_oob_data, MGMT_ADD_REMOTE_OOB_DATA_SIZE,
9371: HCI_MGMT_VAR_LEN },
9372: { remove_remote_oob_data, MGMT_REMOVE_REMOTE_OOB_DATA_SIZE },
9373: { start_discovery, MGMT_START_DISCOVERY_SIZE },
9374: { stop_discovery, MGMT_STOP_DISCOVERY_SIZE },
9375: { confirm_name, MGMT_CONFIRM_NAME_SIZE },
9376: { block_device, MGMT_BLOCK_DEVICE_SIZE },
9377: { unblock_device, MGMT_UNBLOCK_DEVICE_SIZE },
9378: { set_device_id, MGMT_SET_DEVICE_ID_SIZE },
9379: { set_advertising, MGMT_SETTING_SIZE },
9380: { set_bredr, MGMT_SETTING_SIZE },
9381: { set_static_address, MGMT_SET_STATIC_ADDRESS_SIZE },
9382: { set_scan_params, MGMT_SET_SCAN_PARAMS_SIZE },
9383: { set_secure_conn, MGMT_SETTING_SIZE },
9384: { set_debug_keys, MGMT_SETTING_SIZE },
9385: { set_privacy, MGMT_SET_PRIVACY_SIZE },
9386: { load_irks, MGMT_LOAD_IRKS_SIZE,
9387: HCI_MGMT_VAR_LEN },
9388: { get_conn_info, MGMT_GET_CONN_INFO_SIZE },
9389: { get_clock_info, MGMT_GET_CLOCK_INFO_SIZE },
9390: { add_device, MGMT_ADD_DEVICE_SIZE },
9391: { remove_device, MGMT_REMOVE_DEVICE_SIZE },
9392: { load_conn_param, MGMT_LOAD_CONN_PARAM_SIZE,
9393: HCI_MGMT_VAR_LEN },
9394: { read_unconf_index_list, MGMT_READ_UNCONF_INDEX_LIST_SIZE,
9395: HCI_MGMT_NO_HDEV |
9396: HCI_MGMT_UNTRUSTED },
9397: { read_config_info, MGMT_READ_CONFIG_INFO_SIZE,
9398: HCI_MGMT_UNCONFIGURED |
9399: HCI_MGMT_UNTRUSTED },
9400: { set_external_config, MGMT_SET_EXTERNAL_CONFIG_SIZE,
9401: HCI_MGMT_UNCONFIGURED },
9402: { set_public_address, MGMT_SET_PUBLIC_ADDRESS_SIZE,
9403: HCI_MGMT_UNCONFIGURED },
9404: { start_service_discovery, MGMT_START_SERVICE_DISCOVERY_SIZE,
9405: HCI_MGMT_VAR_LEN },
9406: { read_local_oob_ext_data, MGMT_READ_LOCAL_OOB_EXT_DATA_SIZE },
9407: { read_ext_index_list, MGMT_READ_EXT_INDEX_LIST_SIZE,
9408: HCI_MGMT_NO_HDEV |
9409: HCI_MGMT_UNTRUSTED },
9410: { read_adv_features, MGMT_READ_ADV_FEATURES_SIZE },
9411: { add_advertising, MGMT_ADD_ADVERTISING_SIZE,
9412: HCI_MGMT_VAR_LEN },
9413: { remove_advertising, MGMT_REMOVE_ADVERTISING_SIZE },
9414: { get_adv_size_info, MGMT_GET_ADV_SIZE_INFO_SIZE },
9415: { start_limited_discovery, MGMT_START_DISCOVERY_SIZE },
9416: { read_ext_controller_info,MGMT_READ_EXT_INFO_SIZE,
9417: HCI_MGMT_UNTRUSTED },
9418: { set_appearance, MGMT_SET_APPEARANCE_SIZE },
9419: { get_phy_configuration, MGMT_GET_PHY_CONFIGURATION_SIZE },
9420: { set_phy_configuration, MGMT_SET_PHY_CONFIGURATION_SIZE },
9421: { set_blocked_keys, MGMT_OP_SET_BLOCKED_KEYS_SIZE,
9422: HCI_MGMT_VAR_LEN },
9423: { set_wideband_speech, MGMT_SETTING_SIZE },
9424: { read_controller_cap, MGMT_READ_CONTROLLER_CAP_SIZE,
9425: HCI_MGMT_UNTRUSTED },
9426: { read_exp_features_info, MGMT_READ_EXP_FEATURES_INFO_SIZE,
9427: HCI_MGMT_UNTRUSTED |
9428: HCI_MGMT_HDEV_OPTIONAL },
9429: { set_exp_feature, MGMT_SET_EXP_FEATURE_SIZE,
9430: HCI_MGMT_VAR_LEN |
9431: HCI_MGMT_HDEV_OPTIONAL },
9432: { read_def_system_config, MGMT_READ_DEF_SYSTEM_CONFIG_SIZE,
9433: HCI_MGMT_UNTRUSTED },
9434: { set_def_system_config, MGMT_SET_DEF_SYSTEM_CONFIG_SIZE,
9435: HCI_MGMT_VAR_LEN },
9436: { read_def_runtime_config, MGMT_READ_DEF_RUNTIME_CONFIG_SIZE,
9437: HCI_MGMT_UNTRUSTED },
9438: { set_def_runtime_config, MGMT_SET_DEF_RUNTIME_CONFIG_SIZE,
9439: HCI_MGMT_VAR_LEN },
9440: { get_device_flags, MGMT_GET_DEVICE_FLAGS_SIZE },
9441: { set_device_flags, MGMT_SET_DEVICE_FLAGS_SIZE },
9442: { read_adv_mon_features, MGMT_READ_ADV_MONITOR_FEATURES_SIZE },
9443: { add_adv_patterns_monitor,MGMT_ADD_ADV_PATTERNS_MONITOR_SIZE,
9444: HCI_MGMT_VAR_LEN },
9445: { remove_adv_monitor, MGMT_REMOVE_ADV_MONITOR_SIZE },
9446: { add_ext_adv_params, MGMT_ADD_EXT_ADV_PARAMS_MIN_SIZE,
9447: HCI_MGMT_VAR_LEN },
9448: { add_ext_adv_data, MGMT_ADD_EXT_ADV_DATA_SIZE,
9449: HCI_MGMT_VAR_LEN },
9450: { add_adv_patterns_monitor_rssi,
9451: MGMT_ADD_ADV_PATTERNS_MONITOR_RSSI_SIZE,
9452: HCI_MGMT_VAR_LEN },
9453: { set_mesh, MGMT_SET_MESH_RECEIVER_SIZE,
9454: HCI_MGMT_VAR_LEN },
9455: { mesh_features, MGMT_MESH_READ_FEATURES_SIZE },
9456: { mesh_send, MGMT_MESH_SEND_SIZE,
9457: HCI_MGMT_VAR_LEN },
9458: { mesh_send_cancel, MGMT_MESH_SEND_CANCEL_SIZE },
9459: { mgmt_hci_cmd_sync, MGMT_HCI_CMD_SYNC_SIZE, HCI_MGMT_VAR_LEN },
9460: };
SourceFile:net/bluetooth/mgmt.c]
|
| 116/2 |
2026/05/31 10:24 |
llm |
expert |
0m
Model:
Tokens:
input: 112138
output: 55
thoughts: 2464
Thoughts: **Analysis of the Bluetooth HCI Vulnerability**
Okay, let's break this down. First, the `add_device` function, is out β it needs a trusted socket, and that's either `CAP_NET_ADMIN` or a user channel socket. Since `hci_sock_bind` requires `CAP_NET_ADMIN` to set the trusted flag, an unprivileged user can't send `add_device` commands. So, what *can* an unprivileged user do via the management interface? Only a limited set of commands with `HCI_MGMT_UNTRUSTED` are allowed like `read_version` and such, which don't involve the workqueue. Therefore, unprivileged users can't trigger this via the `mgmt` socket.
Alright, what about `HCIDEVUP`? That also needs `CAP_NET_ADMIN`. In fact, it returns an error if the calling process isn't privileged. This bug seems to hinge on `CAP_NET_ADMIN`. If it's needed in the initial user namespace, unprivileged processes are out of luck. And, since `hci_sock_bind` also checks global `CAP_NET_ADMIN`, it's not accessible from user namespaces either! I'm verifying this now... Yep, the code uses `capable(CAP_NET_ADMIN)` not `ns_capable()`. The bug needs global `CAP_NET_ADMIN`.
But wait, syzkaller runs as root! So it has global `CAP_NET_ADMIN`, and this isn't a vulnerability for unprivileged users. But are there *other* ways to get to `hci_dev_open`? `hci_sock_bind` for `HCI_CHANNEL_USER` also requires `CAP_NET_ADMIN`.
What about `hci_power_on`? It is called from `req_workqueue`. This work gets queued by either `hci_register_dev`, `set_external_config`, or `set_public_address`. The latter two are management commands, so again, they need `CAP_NET_ADMIN`. That leaves `hci_register_dev`, which gets called when a new HCI device is registered, like a USB dongle. `vhci` is one example, but that needs `/dev/vhci`, which is normally restricted to root. So, a regular user can't create a `vhci` device.
Can a malicious USB dongle trigger this? Okay, if a dongle plugs in, `hci_register_dev` is called. It queues `hdev->power_on` which then calls `hci_dev_open`. That goes to `hci_dev_open_sync`, `hci_dev_init_sync` which sends commands to the dongle. The dongle times out if it doesn't respond. But `hci_init_sync` aborts on the first error. So, it's a single timeout. No 152-second delay. Let's see how many commands are sent in `hci_init_sync`, maybe 10-20 commands? Even at two seconds each, that's not 152 seconds. But wait. A malicious dongle *can* delay. If it is slow to respond, it could stall out the init. Is delaying init a denial-of-service, though?
It only blocks `req_workqueue` for that specific device. It's not a system-wide block unless something later *calls* `hci_dev_open` or `HCIDEVUP` on that device. Who would call that? Maybe some udev rule or `bluetoothd`? `bluetoothd` uses `MGMT_OP_SET_POWERED` and that doesn't block. It is async. The only thing blocking is calls to `HCIDEVUP` or `HCI_CHANNEL_USER`. And those need `CAP_NET_ADMIN`.
So, the bug is:
1. Triggered by `CAP_NET_ADMIN` (root).
2. Requires a lot of commands or a very slow device to trigger.
3. Causes a hung task warning that can be a DoS if the hung task watchdog is enabled.
Since it needs `CAP_NET_ADMIN`, unprivileged users can't exploit it. It's not accessible from user namespaces. A malicious USB dongle *can't* force a privileged process to call `HCIDEVUP` or `HCI_CHANNEL_USER`, since `bluetoothd` uses `MGMT_OP_SET_POWERED`, which is asynchronous. The malicious device *can* make `hci_power_on` take a long time, but it only blocks `req_workqueue`, which is per
|
| 117/2 |
2026/05/31 10:25 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:net/bluetooth/hci_core.c IncludeSnippetLines:2 Name:hci_dev_open SourceTreePrefix:net/bluetooth/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hci_sock_bind SourceFile:net/bluetooth/hci_sock.c SourceLine:1318 SourceSnippet:1316: hci_dev_unlock(hdev);
1317:
1318: err = hci_dev_open(hdev->id);
1319: if (err) {
1320: if (err == -EALREADY) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hci_sock_ioctl SourceFile:net/bluetooth/hci_sock.c SourceLine:1130 SourceSnippet:1128: if (!capable(CAP_NET_ADMIN))
1129: return -EPERM;
1130: return hci_dev_open(arg);
1131:
1132: case HCIDEVDOWN:
]] TruncatedOutput:false]
|
| 118/2 |
2026/05/31 10:25 |
llm |
expert |
0m
Model:
Tokens:
input: 115956
output: 66
thoughts: 1366
Thoughts: **Analysis of the Bluetooth HCI Hung Task: A Deep Dive**
Okay, so I've been digging into this "bug" reported by syzkaller regarding a hung task within the Bluetooth HCI (Host Controller Interface) subsystem. My initial instinct was to check where the vulnerability stems from: `hci_sock_bind` and `hci_sock_ioctl`. The core thing is both of these functions require `CAP_NET_ADMIN` within the initial namespace.
Looking at the code, in the `HCI_CHANNEL_USER` case, it's immediately clear: `!capable(CAP_NET_ADMIN)` results in an `-EPERM` error. Same deal with `HCIDEVUP`. This means `hci_dev_open` is strictly guarded by that `CAP_NET_ADMIN` check. Alright, so an unprivileged user is completely locked out. User namespaces? Nope, `capable()` checks the `init_user_ns`. A rogue USB device can't trigger this either, because it can't force a privileged process to call `HCIDEVUP` or bind a `HCI_CHANNEL_USER` socket. Even if root calls `HCIDEVUP` or binds the `HCI_CHANNEL_USER` socket, that's just root causing a delay - a self-inflicted wound, if you will, or a delay.
So, this is NOT a security bug. It's more like syzkaller finding a way to make a root process block by abusing root privileges and the `vhci` interface.
Let's break down the potential impact. Exploitable? No, not really. It's just a hung task, a delay. Denial of Service? Not really either, it requires `CAP_NET_ADMIN` and only blocks the thread calling `ioctl`. The system won't crash unless `panic_on_hung_task` is set, but since you need root, root can crash the system anyway. Can an unprivileged process trigger it? No. User namespaces? No. VM Guest? No. Host in a Confidential Computing context? No. Network, Peripheral, Filesystem? None.
Wait a sec... is there ANY chance `hci_dev_open` is called from a network packet, perhaps? Nope, it's only called from socket ioctls and binds. Okay, and how about `hci_sock_ioctl`? Can that be called without the proper privileges? Again, no. The check is explicit. The same applies to `hci_sock_bind` β absolutely protected.
Just to be absolutely sure, let me verify that `capable(CAP_NET_ADMIN)` cannot be bypassed. Nope, `capable()` is a standard kernel function that checks the init user namespace.
Let's check if `hci_dev_open` is called from *anywhere* else. I used the `codesearch-find-references` tool and it only returned `hci_sock_bind` and `hci_sock_ioctl`. But wait, what about `hci_dev_do_open`? That's called by `hci_power_on` and `hci_dev_open`. However, it doesn't call `flush_workqueue(hdev->req_workqueue)`. So, no blocking there. What about `hci_power_on_sync`? It calls `hci_dev_open_sync`, and that ALSO doesn't call `flush_workqueue`.
Therefore, the *only* place `flush_workqueue(hdev->req_workqueue)` is called from is `hci_dev_open`. And `hci_dev_open` is STRICTLY protected by `CAP_NET_ADMIN`.
Therefore, this has NO security impact. I've got to write down the final assessment.
So, here's the summary: The bug is a hung task in `hci_dev_open` caused by `flush_workqueue(hdev->req_workqueue)`. This happens when a privileged user (with `CAP_NET_ADMIN` in the init namespace) queues a long-running/blocking operation on the `req_workqueue` (like by sending many `MGMT_OP_SET_POWERED` commands or using a `vhci` device that doesn't respond to commands, causing them to timeout after 2 seconds each), and then calls `ioctl(HCIDEVUP)` or binds a `HCI_CHANNEL_USER` socket. Then `hci_dev_open` is called, which then calls `flush_workqueue(hdev->req_workqueue)`. Because the workqueue is busy, `flush_workqueue` blocks, triggering the hung task watchdog. Since queueing these commands (e.g., `vhci` creation
|
| 119/2 |
2026/05/31 10:25 |
tool |
set-results |
0m
Args: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 120/2 |
2026/05/31 10:25 |
llm |
expert |
0m
Model:
Tokens:
input: 118477
output: 712
thoughts: 13
Thoughts: Okay, here's the summary, rendered in the first person, assuming the user is an expert:
**Final Reasoning and Conclusion**
Alright, the data's in, the analyses are done, and the findings are conclusive. I'm now at the point of finalizing my reasoning. There's no further processing needed, all parameters have been accounted for, and the implications of this outcome are clear. This section is where I'll connect the dots and present my definitive interpretation of the results, drawing on my deep understanding of the subject matter to articulate why these specific outcomes are what they are. I'll need to clarify the scope, the limits, and the most probable inferences that can be drawn with confidence.
|
| 121/1 |
2026/05/31 10:25 |
action |
format-explanation |
0m
Results: map[Explanation:**Analysis:**
The bug report indicates a hung task in `hci_dev_open`, specifically blocked at
`flush_workqueue(hdev->req_workqueue)`. This happens when a thread waits for all
currently executing and queued work items on the Bluetooth device's
`req_workqueue` to finish.
By examining the source code, we can see that `hci_dev_open` is only called from
two places in the kernel:
1. `hci_sock_ioctl` when handling the `HCIDEVUP` command.
2. `hci_sock_bind` when binding a socket to `HCI_CHANNEL_USER`.
In both cases, the kernel explicitly checks for the `CAP_NET_ADMIN` capability
in the initial user namespace using `capable(CAP_NET_ADMIN)`:
```c
// In hci_sock_ioctl:
case HCIDEVUP:
if (!capable(CAP_NET_ADMIN))
return -EPERM;
return hci_dev_open(arg);
// In hci_sock_bind:
case HCI_CHANNEL_USER:
...
if (!capable(CAP_NET_ADMIN)) {
err = -EPERM;
goto done;
}
...
err = hci_dev_open(hdev->id);
```
Because `capable()` checks the init namespace (unlike `ns_capable()`), these
operations are strictly inaccessible to unprivileged users, even if they create
a new user namespace.
The hung task itself is caused by the `req_workqueue` being busy for an extended
period (e.g., > 120 seconds). This can be artificially triggered by a root user
(like the syzkaller fuzzer) by creating a virtual Bluetooth device (`vhci`) and
either not reading from its character device or queuing many operations (like
`add_device` or `set_powered` via the `mgmt` interface) that end up timing out
sequentially (each HCI command timeout is typically 2 seconds). When the root
user subsequently calls `HCIDEVUP`, the `flush_workqueue` call blocks until all
those timeouts expire, triggering the kernel's hung task watchdog.
A malicious physical Bluetooth peripheral could intentionally ignore
initialization commands to delay its own `hci_power_on` work item (which runs on
`req_workqueue`). However, this would only block the workqueue for that specific
device. It would not cause a system-wide denial of service or hang system
daemons, because standard daemons (like `bluetoothd`) use the asynchronous
`mgmt` interface (e.g., `MGMT_OP_SET_POWERED`), which queues work but does not
call `flush_workqueue`. The hang only occurs if a privileged process explicitly
invokes the legacy `HCIDEVUP` ioctl or binds a `HCI_CHANNEL_USER` socket while
the workqueue is stalled.
**Conclusion:**
Since triggering the bug requires global `CAP_NET_ADMIN` privileges to both
stall the workqueue and invoke the blocking `hci_dev_open` path, it crosses no
privilege boundaries. It is not accessible to unprivileged users, user
namespaces, or remote attackers, and a malicious peripheral cannot force a
privileged process to execute the blocking code path. Therefore, this bug has no
security impact.]
|