From 45a25a1bfd267d9e420119a48e5291d7882395df Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Tue, 10 Nov 2026 03:55:41 +0000 Subject: [PATCH 01/26] Bluetooth: hci_qca: clear qca_memdump when discarding dump packets qca_controller_memdump() frees qca_memdump when a memdump packet with a non-zero sequence number arrives while QCA_MEMDUMP_COLLECTION is not set, but leaves qca->qca_memdump pointing at the freed object. The next run of the work reads the stale pointer into its local variable, skips the allocation and uses the freed memory. Another packet with a non-zero sequence number frees it a second time, and a packet with sequence number 0 writes ram_dump_size, current_seq_no and received_dump into it. The original code cleared the pointer here; the assignment was dropped when the condition was changed to test QCA_MEMDUMP_COLLECTION. All other places that free the structure clear the pointer. A controller that sends two memdump events without a leading sequence number 0 can trigger a use-after-free or double free of a kmalloc object. Found by LLM-assisted source review. Fixes: 06d3fdfcdf5c ("Bluetooth: hci_qca: Add qcom devcoredump support") Cc: stable@vger.kernel.org Signed-off-by: Joas Antonio dos Santos Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_qca.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index d96ae0fc2b2e..dfaf4861f498 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1132,6 +1132,7 @@ static void qca_controller_memdump(struct work_struct *work) if (!test_bit(QCA_MEMDUMP_COLLECTION, &qca->flags)) { bt_dev_err(hu->hdev, "QCA: Discarding other packets"); kfree(qca_memdump); + qca->qca_memdump = NULL; kfree_skb(skb); mutex_unlock(&qca->hci_memdump_lock); return; From a57a255ce204b51327ac4e840a7726b0ab9a1942 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 10 Nov 2026 17:29:28 +0800 Subject: [PATCH 02/26] Bluetooth: hci_qca: Reopen the UART after enabling QCA2066 QCA2066 does not reopen the UART after the controller is enabled, which causes RX/TX out-of-sync errors. The UART has to be reopened once the controller is powered on. qca_regulator_init() already enables the controller and then reopens the UART, but QCA2066 does not go through it. QCA2066 was added with its own SoC type and handled in the default case. Let QCA2066 go through qca_regulator_init() as well, and handle it in the other places that check the SoC type in the same way. This also applies the baudrate switching, flow control, shutdown and probe handling of those chips to QCA2066. btqca.c checks the SoC type in the same way, so the firmware version is also shown in the log. Signed-off-by: Shuai Zhang Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btqca.c | 1 + drivers/bluetooth/hci_qca.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 60735b70d89a..9f54e33e4250 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -983,6 +983,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, switch (soc_type) { case QCA_WCN3991: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: /* get fw build info */ diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index dfaf4861f498..f10edada9512 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1387,6 +1387,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: usleep_range(1000, 10000); @@ -1474,6 +1475,7 @@ static int qca_check_speeds(struct hci_uart *hu) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (!qca_get_speed(hu, QCA_INIT_SPEED) && @@ -1517,6 +1519,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: hci_uart_set_flow_control(hu, true); @@ -1552,6 +1555,7 @@ error: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: hci_uart_set_flow_control(hu, false); @@ -1868,6 +1872,7 @@ static int qca_power_on(struct hci_dev *hdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: ret = qca_regulator_init(hu); @@ -1990,6 +1995,7 @@ retry: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (qcadev && qcadev->bdaddr_property_broken) @@ -2023,6 +2029,7 @@ retry: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: break; @@ -2285,6 +2292,7 @@ static void qca_power_off(struct hci_uart *hu) break; case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: gpiod_set_value_cansleep(qcadev->bt_en, 0); msleep(100); @@ -2439,6 +2447,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: qcadev->bt_power = devm_kzalloc(&serdev->dev, @@ -2458,6 +2467,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (!device_property_present(&serdev->dev, "enable-gpios")) { @@ -2501,6 +2511,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) if (!qcadev->bt_en && (data->soc_type == QCA_WCN6750 || + data->soc_type == QCA_QCA2066 || data->soc_type == QCA_WCN6855 || data->soc_type == QCA_WCN7850)) power_ctrl_enabled = false; @@ -2509,6 +2520,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) GPIOD_IN); if (IS_ERR(qcadev->sw_ctrl) && (data->soc_type == QCA_WCN6750 || + data->soc_type == QCA_QCA2066 || data->soc_type == QCA_WCN6855 || data->soc_type == QCA_WCN7850)) { dev_err(&serdev->dev, "failed to acquire SW_CTRL gpio\n"); @@ -2593,6 +2605,7 @@ static void qca_serdev_remove(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (power->vregs_on) From 45e28b01e4d06282d03f08888f09722709d4b552 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 10 Nov 2026 17:29:29 +0800 Subject: [PATCH 03/26] Bluetooth: hci_qca: Don't use the serdev port after a failed reopen If serdev_device_open() fails in qca_port_reopen(), qca_regulator_init() or the qca_setup() retry path, the port is left closed but HCI_UART_PROTO_READY stays set. The error reaches qca_setup(), whose retry loop calls serdev_device_close() again, and hci_uart_close() or hci_uart_unregister_device() close it once more later. The HCI core also calls hci_uart_flush() from hci_dev_close_sync() before hdev->close(), which writes to the closed port. serdev_device_close() and serdev_device_write_flush() have no "not open" check. ttyport_open() clears serport->tty when it fails, so both end up passing NULL to the tty layer, and the runtime PM usage count is dropped once too often. Keep HCI_UART_PROTO_READY in sync with the port state in hci_qca: clear it when the port is closed, set it only after a successful open, and only call serdev_device_close() when it was set. hci_uart_open() already treats the flag as "port is open" and reopens the port when it is clear, so the next power on recovers. Make hci_uart_flush() skip the port flush when the flag is clear, as it already does for the proto flush. Signed-off-by: Shuai Zhang Reviewed-by: Bartosz Golaszewski Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_qca.c | 33 +++++++++++++++++++++++++++------ drivers/bluetooth/hci_serdev.c | 6 ++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index f10edada9512..d693e2842725 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1755,6 +1755,27 @@ static bool qca_wakeup(struct hci_dev *hdev) return wakeup; } +static void qca_port_close(struct hci_uart *hu) +{ + /* HCI_UART_PROTO_READY tracks whether the port is open, so a port + * left closed by a failed qca_port_open() is not closed again by + * hci_uart_close() or hci_uart_unregister_device(). + */ + if (test_and_clear_bit(HCI_UART_PROTO_READY, &hu->flags)) + serdev_device_close(hu->serdev); +} + +static int qca_port_open(struct hci_uart *hu) +{ + int ret; + + ret = serdev_device_open(hu->serdev); + if (!ret) + set_bit(HCI_UART_PROTO_READY, &hu->flags); + + return ret; +} + static int qca_port_reopen(struct hci_uart *hu) { int ret; @@ -1764,8 +1785,8 @@ static int qca_port_reopen(struct hci_uart *hu) * Without this, we will have RTS and CTS synchronization * issues. */ - serdev_device_close(hu->serdev); - ret = serdev_device_open(hu->serdev); + qca_port_close(hu); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hu->hdev, "failed to open port"); return ret; @@ -1789,12 +1810,12 @@ static int qca_regulator_init(struct hci_uart *hu) qcadev = serdev_device_get_drvdata(hu->serdev); if (!qcadev->bt_power->vregs_on) { - serdev_device_close(hu->serdev); + qca_port_close(hu); ret = qca_regulator_enable(qcadev); if (ret) return ret; - ret = serdev_device_open(hu->serdev); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hu->hdev, "failed to open port"); return ret; @@ -2073,8 +2094,8 @@ out: if (retries < MAX_INIT_RETRIES) { bt_dev_warn(hdev, "Retry BT power ON:%d", retries); if (hu->serdev) { - serdev_device_close(hu->serdev); - ret = serdev_device_open(hu->serdev); + qca_port_close(hu); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hdev, "failed to open port"); return ret; diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index 48ba017e219b..d2c48df34199 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -101,11 +101,13 @@ static int hci_uart_flush(struct hci_dev *hdev) kfree_skb(hu->tx_skb); hu->tx_skb = NULL; } + if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) + return 0; + /* Flush any pending characters in the driver and discipline. */ serdev_device_write_flush(hu->serdev); - if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) - hu->proto->flush(hu); + hu->proto->flush(hu); return 0; } From 4728474344793dd67956e03a2cb244b71383ef7c Mon Sep 17 00:00:00 2001 From: Xu Rao Date: Tue, 10 Nov 2026 11:07:56 +0800 Subject: [PATCH 04/26] Bluetooth: MGMT: Fix runtime config status opcode The Set Default Runtime Configuration command uses opcode 0x004e, but set_def_runtime_config() reports its invalid-parameter status with the Set Default System Configuration opcode, 0x004c. A management client that matches Command Status events to its pending request by opcode therefore cannot associate the response with the request it sent. Runtime configuration parameters are not implemented, so the command still returns MGMT_STATUS_INVALID_PARAMS. Use MGMT_OP_SET_DEF_RUNTIME_CONFIG for the status event so the response identifies the command that was actually handled. Fixes: aececa645dc7 ("Bluetooth: mgmt: Add commands for runtime configuration") Signed-off-by: Xu Rao Cc: stable@vger.kernel.org Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c index fdcc752c6f13..6a617656bfbe 100644 --- a/net/bluetooth/mgmt_config.c +++ b/net/bluetooth/mgmt_config.c @@ -362,6 +362,6 @@ int set_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, { bt_dev_dbg(hdev, "sock %p", sk); - return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEF_SYSTEM_CONFIG, + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEF_RUNTIME_CONFIG, MGMT_STATUS_INVALID_PARAMS); } From 1645edfa8c29e43239cca615cefcb19959d3aa36 Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Tue, 10 Nov 2026 03:26:03 +0000 Subject: [PATCH 05/26] Bluetooth: L2CAP: validate MPS and MTU in ECRED connection response l2cap_ecred_conn_rsp() stores the MTU and MPS from the peer without checking them against the minimums required for enhanced credit based channels. The other LE and ECRED handlers (l2cap_le_connect_req(), l2cap_le_connect_rsp(), l2cap_ecred_conn_req(), l2cap_ecred_reconf_req()) all reject values below the minimum. With an MPS below L2CAP_SDULEN_SIZE, the pdu_len computation in l2cap_segment_le_sdu() wraps: pdu_len = chan->remote_mps - L2CAP_SDULEN_SIZE; pdu_len is then clamped to the SDU length, which l2cap_chan_send() has already limited to chan->omtu, so nothing is over-allocated and there is no memory safety issue. The result is that the whole SDU is sent as a single PDU, larger than the MPS the peer announced, and a channel is established with parameters the specification does not allow. Apply the same L2CAP_ECRED_MIN_MTU / L2CAP_ECRED_MIN_MPS checks that l2cap_ecred_conn_req() uses and drop the channel when the response carries smaller values. Found by LLM-assisted manual code review. Fixes: 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode") Signed-off-by: Joas Antonio dos Santos Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 7dcb0586a10b..0398cc5a2dc0 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -5701,6 +5701,16 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, break; } + /* + * Validate MPS and MTU per BT Core Spec + * Vol 3 Part A Sec 10.2 + */ + if (mtu < L2CAP_ECRED_MIN_MTU || + mps < L2CAP_ECRED_MIN_MPS) { + l2cap_chan_del(chan, ECONNREFUSED); + break; + } + chan->ident = 0; chan->dcid = dcid; chan->omtu = mtu; From d9a1bd14caf5d235499319f7aee9e641c12d90a9 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sat, 24 Oct 2026 23:27:49 +0800 Subject: [PATCH 06/26] Bluetooth: hci_conn: Initialize the device before hash insertion An hci_conn must have an initialized embedded device before an RCU reader can acquire a reference to it. __hci_conn_add() instead adds the connection to conn_hash before hci_conn_init_sysfs() calls device_initialize(). Holding hdev->lock during creation does not exclude hci_disconnect_all_sync(), which looks up the connection and calls hci_conn_get() under RCU without that lock. When a new incoming ACL request overlaps controller poweroff before the connection is registered in sysfs, the separate event and request workqueues can execute this sequence: 1. The event worker holds hdev->lock and publishes a new connection in __hci_conn_add(), before device_initialize(). 2. The request worker finds that connection under RCU, calls hci_conn_get() and leaves its RCU read-side critical section. 3. The event worker runs hci_conn_init_sysfs(), sets BT_CONNECT in hci_conn_request_evt() and releases hdev->lock. 4. The request worker calls hci_abort_conn_sync(), which acquires hdev->lock and reaches hci_conn_failed(), hci_conn_del() and hci_conn_del_sysfs() to delete the pending connection. 5. After abort returns, the request worker calls hci_conn_put(). device_initialize() resets the kobject reference count to one, discarding the walker's premature get. If no other device references exist, deletion of the unregistered device drops that one reference and bt_link_release() frees the hci_conn. The walker's trailing put then accesses the freed kobject, as shown by the KASAN report below. The RCU grace period in hci_conn_hash_del() cannot preserve the walker after it has left its read-side critical section. Initialize the device before hci_conn_hash_add() publishes the connection. The existing RCU publication then makes the initialized device visible to readers, so the walker takes a valid reference that survives deletion until its matching put. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in kobject_put+0x4f3/0x610 Read of size 1 at addr ffff88811e6fcd2c by task kworker/u17:0/559 Workqueue: hci0 hci_cmd_sync_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? kobject_put+0x4f3/0x610 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? kobject_put+0x4f3/0x610 kasan_report+0xe0/0x110 ? kobject_put+0x4f3/0x610 ? hci_disconnect_all_sync.constprop.0+0xd8/0x520 kobject_put+0x4f3/0x610 ? hci_disconnect_all_sync.constprop.0+0xd8/0x520 put_device+0x24/0x30 hci_disconnect_all_sync.constprop.0+0x176/0x520 ? hci_disconnect_all_sync.constprop.0+0xcd/0x520 ? __pfx_hci_disconnect_all_sync.constprop.0+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 hci_set_powered_sync+0x48f/0x680 ? __pfx_hci_set_powered_sync+0x10/0x10 ? __pfx___mutex_unlock_slowpath+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 set_powered_sync+0xaa/0x150 hci_cmd_sync_work+0x1b3/0x450 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 561: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 __hci_conn_add+0x10c/0x1f70 hci_conn_add_unset+0x72/0x120 hci_conn_request_evt+0xb2b/0xd40 hci_event_packet+0x894/0xc70 hci_rx_work+0x367/0xf00 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 Freed by task 559: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 bt_link_release+0x4a/0xb0 device_release+0xd7/0x280 kobject_put+0x1ad/0x610 put_device+0x24/0x30 hci_conn_del_sysfs+0x15d/0x190 hci_conn_del+0x684/0x1100 hci_abort_conn_sync+0x7d6/0xae0 hci_disconnect_all_sync.constprop.0+0x164/0x520 hci_set_powered_sync+0x48f/0x680 set_powered_sync+0xaa/0x150 hci_cmd_sync_work+0x1b3/0x450 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 The buggy address belongs to the object at ffff88811e6fc000 which belongs to the cache kmalloc-8k of size 8192 The buggy address is located 3372 bytes inside of freed 8192-byte region [ffff88811e6fc000, ffff88811e6fe000) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11e6f8 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100043180 dead000000000122 0000000000000000 raw: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100043180 dead000000000122 0000000000000000 head: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88811e6fcc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88811e6fcc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88811e6fcd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88811e6fcd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88811e6fce00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Fixes: 94d9ba9f9888 ("Bluetooth: hci_sync: Fix UAF in hci_disconnect_all_sync") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index eebd73988bf6..c468a9332e05 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1166,6 +1166,9 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, hci_dev_hold(hdev); + /* Initialize the device before publishing it to RCU readers. */ + hci_conn_init_sysfs(conn); + hci_conn_hash_add(hdev, conn); /* The SCO and eSCO connections will only be notified when their @@ -1177,7 +1180,6 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, hdev->notify(hdev, HCI_NOTIFY_CONN_ADD); } - hci_conn_init_sysfs(conn); return conn; } From 58d8a0955065fb00824865dca5b573a1becbb1ca Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sun, 25 Oct 2026 00:15:17 +0800 Subject: [PATCH 07/26] Bluetooth: vhci: Flush suspend work after removing debugfs The VHCI controller must remain alive until suspend_work finishes. vhci_release() flushes the work before removing the force_suspend debugfs entry, so an active writer can queue work after that flush. A force_suspend write changing the suspend state can overlap the last close of /dev/vhci as follows: /dev/vhci close Debugfs writer Suspend worker --------------- -------------- -------------- vhci_release() force_suspend_write() flush_work() returns [not queued yet] schedule_work() --> hci_suspend_dev() check powered check !HCI_UNREGISTER hci_suspend_sync() unlock(req_lock) vhci_debugfs_remove() wait for writer hci_unregister_dev() hci_free_dev() drop last reference free hdev hci_clear_wake_reason() lock freed mutex use-after-free The controller locks serialize state access but do not retain the allocation. Unregister drains HCI-owned work, but does not cover VHCI's suspend_work on the system workqueue. Flush suspend_work again after removing the debugfs entries and before unregistering the controller. Removal waits for active writers and prevents new callbacks, so the second flush drains all remaining work while the controller and driver data are still alive. Retain the initial flush to preserve the existing teardown order. Runtime testing of this change was not performed. KASAN report as below: ================================================================== BUG: KASAN: use-after-free in __mutex_lock+0x1e68/0x2590 Read of size 8 at addr ffff8881011b80b0 by task kworker/0:0/9 Workqueue: events vhci_suspend_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? __mutex_lock+0x1e68/0x2590 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? __mutex_lock+0x1e68/0x2590 kasan_report+0xe0/0x110 ? __mutex_lock+0x1e68/0x2590 __mutex_lock+0x1e68/0x2590 ? hci_suspend_dev+0x1ff/0x650 ? srso_alias_return_thunk+0x5/0xfbef5 ? mark_held_locks+0x40/0x70 ? _raw_spin_unlock_irqrestore+0x44/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx___mutex_lock+0x10/0x10 ? _raw_spin_unlock_irqrestore+0x44/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? pmbd_gate_site_armed+0x31/0x1c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_pmbd_probe_hit_cookie+0x10/0x10 ? hci_suspend_dev+0x1ff/0x650 hci_suspend_dev+0x1ff/0x650 vhci_suspend_work+0xa5/0x190 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff8881011b9040 pfn:0x1011b8 flags: 0x200000000000000(node=0|zone=2) raw: 0200000000000000 ffffea0004073308 ffff88818863f180 0000000000000000 raw: ffff8881011b9040 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8881011b7f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff8881011b8000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >ffff8881011b8080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff8881011b8100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff8881011b8180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== Fixes: d16e6d19ccc6 ("Bluetooth: hci_vhci: Fix calling hci_{suspend,resume}_dev") Assisted-by: LLM Signed-off-by: Cen Zhang Tested-by: Chad Aldreda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index 8f7db0102b25..bedba3c140ac 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -701,6 +701,8 @@ static int vhci_release(struct inode *inode, struct file *file) if (hdev) { if (!IS_ERR_OR_NULL(hdev->debugfs)) vhci_debugfs_remove(hdev); + /* Drain work queued by the last force_suspend writers. */ + flush_work(&data->suspend_work); hci_unregister_dev(hdev); hci_free_dev(hdev); } From f8ba3e2e82f06cbd469d6ee249fbf86c138247c9 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sat, 24 Oct 2026 23:28:23 +0800 Subject: [PATCH 08/26] Bluetooth: vhci: Serialize packet reception with device creation The hci_dev passed to hci_recv_frame() must stay alive until the receive operation finishes. __vhci_create_device() stores data->hdev before hci_register_dev() and frees the device if registration fails. vhci_get_user() checks and uses that pointer without taking the open_mutex held by the creator or a device reference. An incoming packet write can overlap the delayed default-create work scheduled by vhci_open(). If registration fails before acquiring the registration reference, the following order is possible: Default-create work Packet write vhci_create_device() mutex_lock(open_mutex) data->hdev = hdev vhci_get_user() load data->hdev hci_register_dev() fails hci_free_dev(hdev) bt_host_release(): kfree(hdev) data->hdev = NULL mutex_unlock(open_mutex) hci_recv_frame(hdev, skb) read hdev->flags The packet retains the pointer before the final put and reads flags after the allocation is freed. The HCI_UP/HCI_INIT test therefore accesses freed memory before it can reject the packet. Hold open_mutex from the packet-side pointer check until hci_recv_frame() returns. Creation and its error cleanup already hold this mutex, so the writer waits until they finish and cannot retain a failed device allocation. Release the mutex on the missing-device error path too. KASAN report as below: BUG: KASAN: use-after-free in hci_recv_frame+0x4e/0x7e0 Read of size 8 at addr ffff888107034138 by task python3/500 Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? hci_recv_frame+0x4e/0x7e0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? hci_recv_frame+0x4e/0x7e0 kasan_report+0xe0/0x110 ? hci_recv_frame+0x4e/0x7e0 kasan_check_range+0x105/0x1b0 hci_recv_frame+0x4e/0x7e0 vhci_write+0x35a/0x4c0 vfs_write+0x637/0x1010 ? __pfx_vhci_write+0x10/0x10 ? __might_fault+0xdd/0x190 ? __pfx_vfs_write+0x10/0x10 ? __pfx_hrtimer_wakeup+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? common_nsleep_timens+0xa8/0x160 ksys_write+0x111/0x200 ? __pfx_ksys_write+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? restore_fpregs_from_fpstate+0x55/0x100 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888107036a40 pfn:0x107034 flags: 0x200000000000000(node=0|zone=2) raw: 0200000000000000 ffffea00041c0308 ffff8881887bf180 0000000000000000 raw: ffff888107036a40 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888107034000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888107034080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >ffff888107034100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff888107034180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888107034200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== Fixes: 23424c0d3169 ("Bluetooth: Add support creating virtual AMP controllers") Assisted-by: LLM Signed-off-by: Cen Zhang Tested-by: Chad Aldreda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index bedba3c140ac..7fec02705e58 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -524,7 +524,9 @@ static inline ssize_t vhci_get_user(struct vhci_data *data, case HCI_ACLDATA_PKT: case HCI_SCODATA_PKT: case HCI_ISODATA_PKT: + mutex_lock(&data->open_mutex); if (!data->hdev) { + mutex_unlock(&data->open_mutex); kfree_skb(skb); return -ENODEV; } @@ -532,6 +534,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *data, hci_skb_pkt_type(skb) = pkt_type; ret = hci_recv_frame(data->hdev, skb); + mutex_unlock(&data->open_mutex); break; case HCI_VENDOR_PKT: From df33621e70363df4d6963ad5ff19a3ae740c7703 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sun, 25 Oct 2026 00:35:21 +0800 Subject: [PATCH 09/26] Bluetooth: L2CAP: Protect the receive reject-list lookup Reject-list entries must remain alive throughout a lookup. Management updates the list under hdev->lock, but l2cap_recv_frame() traverses it under conn->lock after l2cap_recv_acldata() has released hdev->lock. An established LE connection can still receive ACL data after its peer has been added to the reject list. If a management socket unblocks that peer during the receive-side lookup, the following ordering is possible: HCI receive Management l2cap_recv_acldata() release hdev->lock acquire conn->lock l2cap_recv_frame() lookup selects entry unblock_device() acquire hdev->lock hci_bdaddr_list_del() unlink and kfree(entry) read entry->bdaddr_type Management does not take conn->lock, so deletion can free the selected entry before the lookup reads its fields. This causes a use-after-free read in hci_bdaddr_list_lookup(). Compute the reject decision under the existing device lock in l2cap_recv_acldata() and pass only the boolean to l2cap_recv_frame(). For pending receive data, take the snapshot in l2cap_conn_ready() and l2cap_security_cfm(), which already hold hdev->lock. Publish it under conn->lock before queuing the worker on the existing device workqueue: HCI callback Pending RX worker hold hdev->lock acquire conn->lock lookup reject list save boolean; queue work release conn->lock acquire conn->lock consume boolean drain pending frames The snapshot belongs to the scheduled batch. A subsequent scheduling callback refreshes it under both locks, including when queue_work() coalesces with already pending work. No reject-list pointer survives the lookup, and the worker reads the boolean under conn->lock. Taking the device lock in the worker would deadlock against l2cap_conn_del(), which holds it while cancelling the work synchronously. A failed trylock followed by immediate self-requeue would instead keep retrying without a delay and extend a concurrent workqueue drain. Keep the lookup in the scheduling callbacks so the worker needs neither the device lock nor a retry. Skip scheduling when pending_rx is empty. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in hci_bdaddr_list_lookup+0x145/0x160 Read of size 1 at addr ffff88810cba64d6 by task kworker/u17:0/493 Workqueue: hci0 hci_rx_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? hci_bdaddr_list_lookup+0x145/0x160 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? hci_bdaddr_list_lookup+0x145/0x160 kasan_report+0xe0/0x110 ? hci_bdaddr_list_lookup+0x145/0x160 hci_bdaddr_list_lookup+0x145/0x160 l2cap_recv_frame+0x865/0x8830 ? srso_alias_return_thunk+0x5/0xfbef5 ? __mutex_lock+0x182c/0x2590 ? __pfx_l2cap_recv_frame+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? find_held_lock+0x2b/0x80 ? l2cap_recv_acldata+0x1eb/0x10e0 ? __pfx___mutex_lock+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __mutex_unlock_slowpath+0x147/0x920 ? __pfx_l2cap_conn_hold_unless_zero+0x10/0x10 ? __pfx_hci_conn_enter_active_mode+0x10/0x10 ? l2cap_recv_acldata+0x13d/0x10e0 ? srso_alias_return_thunk+0x5/0xfbef5 l2cap_recv_acldata+0xe9f/0x10e0 ? srso_alias_return_thunk+0x5/0xfbef5 hci_rx_work+0x5a6/0xf00 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 604: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 hci_bdaddr_list_add+0xdf/0x2c0 block_device+0x112/0x260 hci_sock_sendmsg+0x128b/0x22e0 sock_write_iter+0x4c0/0x550 do_iter_readv_writev+0x59c/0x860 vfs_writev+0x30e/0xc10 do_writev+0x241/0x2f0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 606: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 hci_bdaddr_list_del+0x1a9/0x2a0 unblock_device+0x112/0x260 hci_sock_sendmsg+0x128b/0x22e0 sock_write_iter+0x4c0/0x550 do_iter_readv_writev+0x59c/0x860 vfs_writev+0x30e/0xc10 do_writev+0x241/0x2f0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88810cba64c0 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 22 bytes inside of freed 32-byte region [ffff88810cba64c0, ffff88810cba64e0) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10cba6 flags: 0x200000000000000(node=0|zone=2) page_type: f5(slab) raw: 0200000000000000 ffff888100042780 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000400040 00000000f5000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810cba6380: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff88810cba6400: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc >ffff88810cba6480: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ^ ffff88810cba6500: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff88810cba6580: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ================================================================== Fixes: cc8dba2bc302 ("Bluetooth: Block ATT connection on LE when device is blocked") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 61 +++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 2a05bda8ab43..bb2839972cf3 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -636,6 +636,7 @@ struct l2cap_conn { struct sk_buff_head pending_rx; struct work_struct pending_rx_work; + bool pending_rx_blocked __guarded_by(&lock); struct delayed_work id_addr_timer; diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 0398cc5a2dc0..486b968143d3 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1747,10 +1747,40 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) } } -static void l2cap_conn_ready(struct l2cap_conn *conn) +static bool l2cap_is_blocked(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) { + /* Since we can't actively block incoming LE connections we must + * at least ensure that we ignore incoming data from them. + */ + return hcon->type == LE_LINK && + hci_bdaddr_list_lookup(&hcon->hdev->reject_list, &hcon->dst, + bdaddr_dst_type(hcon)); +} + +static void l2cap_queue_pending_rx(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) +{ + struct l2cap_conn *conn = hcon->l2cap_data; + + mutex_lock(&conn->lock); + + if (!skb_queue_empty(&conn->pending_rx)) { + /* Teardown holds hdev->lock while cancelling the worker. + * Pass the decision under conn->lock to avoid that lock. + */ + conn->pending_rx_blocked = l2cap_is_blocked(hcon); + queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + } + + mutex_unlock(&conn->lock); +} + +static void l2cap_conn_ready(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) +{ + struct l2cap_conn *conn = hcon->l2cap_data; struct l2cap_chan *chan; - struct hci_conn *hcon = conn->hcon; BT_DBG("conn %p", conn); @@ -1782,7 +1812,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) if (hcon->type == LE_LINK) l2cap_le_conn_ready(conn); - queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + l2cap_queue_pending_rx(hcon); } /* Notify sockets that we cannot guaranty reliability anymore */ @@ -7391,7 +7421,8 @@ free_skb: kfree_skb(skb); } -static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) +static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb, + bool blocked) __must_hold(&conn->lock) { struct l2cap_hdr *lh = (void *) skb->data; @@ -7418,12 +7449,7 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) return; } - /* Since we can't actively block incoming LE connections we must - * at least ensure that we ignore incoming data from them. - */ - if (hcon->type == LE_LINK && - hci_bdaddr_list_lookup(&hcon->hdev->reject_list, &hcon->dst, - bdaddr_dst_type(hcon))) { + if (blocked) { kfree_skb(skb); return; } @@ -7471,7 +7497,7 @@ static void process_pending_rx(struct work_struct *work) */ while (!test_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->hcon->flags) && (skb = skb_dequeue(&conn->pending_rx))) - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, conn->pending_rx_blocked); mutex_unlock(&conn->lock); } @@ -7923,7 +7949,7 @@ next: mutex_unlock(&conn->lock); - l2cap_conn_ready(conn); + l2cap_conn_ready(hcon); } int l2cap_disconn_ind(struct hci_conn *hcon) @@ -8062,8 +8088,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) mutex_unlock(&conn->lock); /* Process data held back while the encryption key size was read */ - if (!skb_queue_empty(&conn->pending_rx)) - queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + l2cap_queue_pending_rx(hcon); } /* Append fragment into frame respecting the maximum len of rx_skb */ @@ -8152,6 +8177,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, { struct hci_conn *hcon; struct l2cap_conn *conn; + bool blocked; int len; /* Lock hdev for hci_conn, and race on l2cap_data vs. l2cap_conn_del */ @@ -8174,6 +8200,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, conn = l2cap_conn_add(hcon); conn = l2cap_conn_hold_unless_zero(conn); + blocked = l2cap_is_blocked(hcon); hcon = NULL; hci_dev_unlock(hdev); @@ -8210,7 +8237,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, if (len == skb->len) { /* Complete frame received */ - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, blocked); goto unlock; } @@ -8234,7 +8261,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, * setting the socket unreliable. */ skb->len = len; - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, blocked); l2cap_conn_unreliable(conn, ECOMM); goto unlock; } @@ -8284,7 +8311,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, */ struct sk_buff *rx_skb = conn->rx_skb; conn->rx_skb = NULL; - l2cap_recv_frame(conn, rx_skb); + l2cap_recv_frame(conn, rx_skb, blocked); } break; } From daf949c968d485badd6c1fc5b6965ea8175e7dda Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:30 +0000 Subject: [PATCH 10/26] Bluetooth: hci_sync: Set random address on the set's handle When the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, and the parameters, data and enable commands for an instance use adv->handle. LE Set Advertising Set Random Address, from hci_set_adv_set_random_addr_sync(), still sends the instance number, 0x01, a set the controller doesn't have, so an instance using a random address, such as a non-connectable one, never starts: $ btmgmt add-adv -d 0A09434841445654455354 1 Add Advertising failed with status 0x0d (Invalid Parameters) < HCI Command: LE Set Extended Advertising Parameters Handle: 0x00 < HCI Command: LE Set Extended Advertising Data Handle: 0x00 < HCI Command: LE Set Advertising Set Random Address Advertising handle: 0x01 Send the instance's handle, looked up with hdev->lock held. hci_cc_le_set_adv_set_random_addr() records the address in the instance numbered as the handle and leaves handle 0x00 alone, as that handle's address is hdev->random_addr for instance 0. Instance 1's address on handle 0x00 would then go unrecorded, and its RPA timer never start, so record it in hci_set_adv_set_random_addr_sync() once the command succeeds, as the completion does for the other handles. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 9213e3ef9f26..320c5ba0d555 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1258,6 +1258,8 @@ static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, bdaddr_t *random_addr) { struct hci_cp_le_set_adv_set_rand_addr cp; + struct adv_info *adv; + u8 handle = instance; int err; if (!instance) { @@ -1269,15 +1271,46 @@ static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, err = hci_set_random_addr_sync(hdev, random_addr); if (err) return err; + } else { + hci_dev_lock(hdev); + adv = hci_find_adv_instance(hdev, instance); + if (adv) + handle = adv->handle; + hci_dev_unlock(hdev); } memset(&cp, 0, sizeof(cp)); - cp.handle = instance; + cp.handle = handle; bacpy(&cp.bdaddr, random_addr); - return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, + sizeof(cp), &cp, HCI_CMD_TIMEOUT); + if (err || handle == instance) + return err; + + /* hci_cc_le_set_adv_set_random_addr() records the address of the + * instance numbered as the handle, and leaves handle 0x00 to + * hdev->random_addr, so record it here for an instance using another + * handle: instance 1 on handle 0x00, on a controller supporting a + * single advertising set. + */ + hci_dev_lock(hdev); + + adv = hci_find_adv_instance(hdev, instance); + if (adv) { + bacpy(&adv->random_addr, random_addr); + if (!bacmp(&hdev->rpa, random_addr)) { + adv->rpa_expired = false; + queue_delayed_work(hdev->workqueue, + &adv->rpa_expired_cb, + secs_to_jiffies(hdev->rpa_timeout)); + } + } + + hci_dev_unlock(hdev); + + return 0; } static int From e7e877bf658acd15fc7dda1bff3e66d0fa69a061 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:31 +0000 Subject: [PATCH 11/26] Bluetooth: hci_sync: Remove an advertising set by its handle When the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, but hci_remove_ext_adv_instance_sync() sends the instance number as the handle of LE Remove Advertising Set, so removing instance 1 fails: $ btmgmt rm-adv 1 Remove Advertising failed with status 0x03 (Failed) < HCI Command: LE Remove Advertising Set Handle: 1 > HCI Event: Command Complete Status: Unknown Advertising Identifier (0x42) Send the instance's handle, looked up with hdev->lock held. Two more things follow from the instance and the handle differing: - hci_cc_le_remove_adv_set() removes the instance numbered as the handle it sent, which for handle 0x00 is instance 0, so instance 1 would stay in hdev->adv_instances with its RPA timer running, and no MGMT_EV_ADVERTISING_REMOVED. The completion can't tell instance 1 from instance 0, which the MGMT Set Advertising path removes on the same handle, so remove instance 1 in hci_remove_ext_adv_instance_sync() once the command succeeds. - While Global Advertising is on, it owns handle 0x00 (adv_overridden_by_global()), and the set may be enabled for it, so the controller would refuse to remove it, with Command Disallowed. Remove only the instance then, leaving the set to Global Advertising. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 320c5ba0d555..d4a4f49df5ac 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2110,6 +2110,9 @@ int hci_enable_advertising(struct hci_dev *hdev) int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, struct sock *sk) { + struct adv_info *adv = NULL; + u8 handle = instance; + bool global = false; int err; if (!ext_adv_capable(hdev)) @@ -2119,13 +2122,53 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, if (err) return err; - /* If request specifies an instance that doesn't exist, fail */ - if (instance > 0 && !hci_find_adv_instance(hdev, instance)) - return -EINVAL; + if (instance) { + hci_dev_lock(hdev); - return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, - sizeof(instance), &instance, 0, - HCI_CMD_TIMEOUT, sk); + adv = hci_find_adv_instance(hdev, instance); + if (adv) { + handle = adv->handle; + + /* An instance sharing handle 0x00 with Global + * Advertising doesn't own the set while Global + * Advertising is on, and the set may still be enabled + * for it, which the controller would refuse to remove. + */ + global = !handle && + (hci_dev_test_flag(hdev, HCI_ADVERTISING) || + hci_dev_test_flag(hdev, HCI_LE_ADV_0)); + } + + hci_dev_unlock(hdev); + + /* If request specifies an instance that doesn't exist, fail */ + if (!adv) + return -EINVAL; + } + + if (!global) { + err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, + sizeof(handle), &handle, 0, + HCI_CMD_TIMEOUT, sk); + if (err) + return err; + } + + /* hci_cc_le_remove_adv_set() removes the instance numbered as the + * handle it sent, so remove here an instance using another handle: + * instance 1 on handle 0x00, on a controller supporting a single + * advertising set. The completion can't tell it from instance 0. + */ + if (handle != instance) { + hci_dev_lock(hdev); + + if (!hci_remove_adv_instance(hdev, instance)) + mgmt_advertising_removed(sk, hdev, instance); + + hci_dev_unlock(hdev); + } + + return 0; } int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) From 8b1eff978e66efb5ed66b79591851203d05ab303 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:32 +0000 Subject: [PATCH 12/26] Bluetooth: hci_core: Add hci_free_adv_instance() hci_remove_adv_instance() looks the instance up by its number and then frees it. A caller that already holds the instance, found some other way, has to look it up again by number to remove it. Split the freeing into hci_free_adv_instance(), which takes the instance itself, and have hci_remove_adv_instance() call it after the lookup. No functional change. Suggested-by: Luiz Augusto von Dentz Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 6fb713d5e4be..fd4da751a24f 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1972,6 +1972,7 @@ struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, u8 sid, int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, u16 adv_data_len, u8 *adv_data, u16 scan_rsp_len, u8 *scan_rsp_data); +void hci_free_adv_instance(struct hci_dev *hdev, struct adv_info *adv_instance); int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c97aec3caba0..846e6eb2d1bc 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1610,17 +1610,11 @@ struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) } /* This function requires the caller holds hdev->lock */ -int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) +void hci_free_adv_instance(struct hci_dev *hdev, struct adv_info *adv_instance) { - struct adv_info *adv_instance; + BT_DBG("%s removing %dMR", hdev->name, adv_instance->instance); - adv_instance = hci_find_adv_instance(hdev, instance); - if (!adv_instance) - return -ENOENT; - - BT_DBG("%s removing %dMR", hdev->name, instance); - - if (hdev->cur_adv_instance == instance) { + if (hdev->cur_adv_instance == adv_instance->instance) { if (hdev->adv_instance_timeout) { cancel_delayed_work(&hdev->adv_instance_expire); hdev->adv_instance_timeout = false; @@ -1634,6 +1628,18 @@ int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) kfree(adv_instance); hdev->adv_instance_cnt--; +} + +/* This function requires the caller holds hdev->lock */ +int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) +{ + struct adv_info *adv_instance; + + adv_instance = hci_find_adv_instance(hdev, instance); + if (!adv_instance) + return -ENOENT; + + hci_free_adv_instance(hdev, adv_instance); return 0; } From 4dce35adafb5d258a58788c0282a0dd43e7ccd73 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:33 +0000 Subject: [PATCH 13/26] Bluetooth: hci_event: Find the owner of a terminated adv set hci_le_ext_adv_term_evt() looks the instance up by the event's handle, but when the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, which is also the handle of Global Advertising. For instance 1 the event then finds no instance, and: - a connection from it gets hdev->random_addr as its responder address, rather than the instance's random address, which SMP then checks against; - the connection stores handle 0x00 in conn->adv_instance, which is later restored as hdev->cur_adv_instance, so after the disconnection instance 0 is re-enabled rather than instance 1; - when the set terminates with an error, instance 0 is removed rather than instance 1, so instance 1 stays with no MGMT_EV_ADVERTISING_REMOVED. Find the instance owning the set: for handle 0x00 the instance enabled on it, as hci_le_ext_adv_set_enabled() tracks, and use its instance number and random address. On an error, free the instance found with hci_free_adv_instance() rather than looking it up again. Global Advertising, and any other handle, are handled as before. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 5e6b25eb5053..10c8b7b8e329 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -6158,6 +6158,26 @@ static void hci_le_pa_sync_lost_evt(struct hci_dev *hdev, void *data, hci_dev_unlock(hdev); } +/* The instance advertising on the set identified by handle. Handle 0x00 may + * be shared by Global Advertising and an instance, e.g. instance 1 when the + * controller supports a single advertising set, in which case the instance + * enabled on it, if any, owns the set (see hci_le_ext_adv_set_enabled()). + */ +static struct adv_info *hci_le_ext_adv_owner(struct hci_dev *hdev, u8 handle) +{ + struct adv_info *adv; + + if (handle) + return hci_find_adv_instance(hdev, handle); + + list_for_each_entry(adv, &hdev->adv_instances, list) { + if (!adv->handle && adv->enabled) + return adv; + } + + return NULL; +} + static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) { @@ -6181,15 +6201,18 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, hci_dev_lock(hdev); - adv = hci_find_adv_instance(hdev, ev->handle); + adv = hci_le_ext_adv_owner(hdev, ev->handle); if (ev->status) { + u8 instance; + if (!adv) goto unlock; /* Remove advertising as it has been terminated */ - hci_remove_adv_instance(hdev, ev->handle); - mgmt_advertising_removed(NULL, hdev, ev->handle); + instance = adv->instance; + hci_free_adv_instance(hdev, adv); + mgmt_advertising_removed(NULL, hdev, instance); list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { if (adv->enabled) @@ -6206,22 +6229,19 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle)); if (conn) { - /* Store handle in the connection so the correct advertising - * instance can be re-enabled when disconnected. + /* Store the instance in the connection so the correct + * advertising instance can be re-enabled when disconnected. */ - conn->adv_instance = ev->handle; + conn->adv_instance = adv ? adv->instance : ev->handle; if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM || bacmp(&conn->resp_addr, BDADDR_ANY)) goto unlock; - if (!ev->handle) { - bacpy(&conn->resp_addr, &hdev->random_addr); - goto unlock; - } - if (adv) bacpy(&conn->resp_addr, &adv->random_addr); + else if (!ev->handle) + bacpy(&conn->resp_addr, &hdev->random_addr); } unlock: From fd038b82c71baa8dfb80e1781e53c0dbbda84e70 Mon Sep 17 00:00:00 2001 From: Chun-Yi Lee Date: Wed, 11 Nov 2026 17:45:18 +0800 Subject: [PATCH 14/26] Bluetooth: SMP: Fail if local and remote public key X coords match The commit 6d19628f539f ("Bluetooth: SMP: Fail if remote and local public keys are identical") patch be introduced since v5.13. Looks this patch can handle the CVE-2021-37577 issue. However, it only checks if the full 64-byte public key (X and Y coordinates) is identical, which is insufficient. In CVE-2021-37577: Bluetooth LE and BR/EDR Secure Connections pairing and Secure Simple Pairing using the Passkey entry protocol in Bluetooth Core Specifications 2.1 through 5.3 may permit an unauthenticated man-in-the-middle attacker to identify the Passkey used during pairing by reflection of a crafted public key with the same X coordinate as the offered public key and by reflection of the authentication evidence of the initiating device, potentially permitting this attacker to complete authenticated pairing with the responding device using the correct Passkey for the pairing session. This is a related issue to CVE-2020-26558. Furthermore, according to the Bluetooth Core Specification, the remote and local public keys should not have the same X coordinate: Bluetooth Core Specification Version: v5.4 (7.1 PHASE 1: PUBLIC KEY EXCHANGE) "If the two public keys have the same X coordinate and neither is the debug key (see [Vol 4] Part E, Section 7.6.4), each device should fail the pairing process." Bluetooth Core Specification Version: v6.0 (7.1 Phase 1: Public key exchange) "If the two public keys have the same X coordinate and neither is the debug key (see [Vol 4] Part E, Section 7.6.4), each device shall fail the pairing process." To ensure both initiator and responder roles strictly enforce this rule: - In smp_cmd_public_key(), restrict the check for the initiator to compare only the 32-byte X coordinate of the public keys rather than the full 64 bytes. - In sc_send_public_key(), add the corresponding check for the responder to verify that the 32-byte X coordinate of remote_pk does not match local_pk before transmitting its own public key. This makes the validation compliant with the specification and mitigates CVE-2021-37577 across both pairing roles. Fixes: 6d19628f539f ("Bluetooth: SMP: Fail if remote and local public keys are identical") Link: https://nvd.nist.gov/vuln/detail/cve-2021-37577 Signed-off-by: Chun-Yi Lee Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/smp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index b7015e37e1f1..6ccb38b1d56d 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -1898,6 +1898,16 @@ static u8 sc_send_public_key(struct smp_chan *smp) } done: + /* Check if remote and local public keys are the same and debug key is + * not in use. + */ + if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) && + !test_bit(SMP_FLAG_INITIATOR, &smp->flags) && + !crypto_memneq(smp->remote_pk, smp->local_pk, 32)) { + bt_dev_err(hdev, "Remote and local public keys are identical"); + return SMP_DHKEY_CHECK_FAILED; + } + SMP_DBG("Local Public Key X: %32phN", smp->local_pk); SMP_DBG("Local Public Key Y: %32phN", smp->local_pk + 32); @@ -2749,7 +2759,8 @@ static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb) * not in use. */ if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) && - !crypto_memneq(key, smp->local_pk, 64)) { + test_bit(SMP_FLAG_INITIATOR, &smp->flags) && + !crypto_memneq(key, smp->local_pk, 32)) { bt_dev_err(hdev, "Remote and local public keys are identical"); return SMP_DHKEY_CHECK_FAILED; } From 1752a2c40059f845123946e01646b8a1798eeea4 Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Wed, 11 Nov 2026 19:48:22 +0530 Subject: [PATCH 15/26] Bluetooth: btintel_pcie: Fix SCP DBGC base address BTINTEL_PCIE_DBGC_BASE_ADDR_SCP was entered as 0xf0d5d500 by mistake when the define was added. The base of the SCP debug controller is 0xf0d5d400, as documented in the Intel SCP SAS document, so the value is one register row too high. The status and wrap-around registers derived from it at offsets 0x1C and 0x2C therefore point at the wrong addresses, and the debug buffer status and wrap-around state read while dumping SCP debug traces are incorrect. Use 0xf0d5d400 so that the derived offsets land on the intended registers. Tested on an SCP platform by triggering a firmware exception and collecting the resulting devcoredump. With the corrected base address, the debug buffer status and wrap-around registers read back valid values and the DRAM monitor buffers in the dump are decoded correctly; with the old address they are read from the wrong registers. Fixes: e43b33bf8d67 ("Bluetooth: btintel_pcie: Load IOSF debug regs by controller variant") Signed-off-by: Chandrashekar Devegowda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 3030b4e8b750..5f315ebb4123 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -72,7 +72,7 @@ #define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS (BTINTEL_PCIE_DBGC_BASE_ADDR + 0x1C) #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND (BTINTEL_PCIE_DBGC_BASE_ADDR + 0x2C) -#define BTINTEL_PCIE_DBGC_BASE_ADDR_SCP (0xf0d5d500) +#define BTINTEL_PCIE_DBGC_BASE_ADDR_SCP (0xf0d5d400) #define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x1C) #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x2C) #define BTINTEL_PCIE_DBGC_ALLOCATION_OFFSET 0x100 From f3183d7ad10120437bcc3f4a751cd256ba69793f Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Thu, 12 Nov 2026 03:34:28 +0000 Subject: [PATCH 16/26] Bluetooth: hci_sync: Drop the command's sk reference hci_cmd_sync_alloc() takes a reference on the sk a command is sent for (sock_hold()), and hci_cmd_sync_complete() means to drop it, but looks for the sk in the response skb, which never carries one. The reference is never dropped: every command sent with an sk leaks it, and with it the sk and a reference on the bluetooth module. The commands sent with an sk are LE Remove Advertising Set and LE Clear Advertising Sets, for MGMT's Remove Advertising and the instance removals, and Read Local OOB (Extended) Data. After each, the module's refcnt stays one higher with no socket left open, and the module can't be unloaded until a reboot. Drop the reference from the request command, hdev->req_skb, before freeing it. Fixes: cba6b758711c ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index d4a4f49df5ac..e771f0f2f308 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -31,21 +31,23 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, hdev->req_result = result; WRITE_ONCE(hdev->req_status, HCI_REQ_DONE); - /* Free the request command so it is not used as response */ + /* Free the request command so it is not used as response, and drop + * the reference hci_cmd_sync_alloc() took on its sk, if set: the + * response skb doesn't carry it. + */ hci_dev_lock(hdev); + if (hdev->req_skb) { + struct sock *sk = hci_skb_sk(hdev->req_skb); + + if (sk) + sock_put(sk); + } kfree_skb(hdev->req_skb); hdev->req_skb = NULL; hci_dev_unlock(hdev); - if (skb) { - struct sock *sk = hci_skb_sk(skb); - - /* Drop sk reference if set */ - if (sk) - sock_put(sk); - + if (skb) hdev->req_rsp = skb_get(skb); - } wake_up_interruptible(&hdev->req_wait_q); } From 3b069de8a5d688c7e8381b99d6cdb7467fcae0de Mon Sep 17 00:00:00 2001 From: Amir Abudubai Date: Wed, 11 Nov 2026 15:49:05 -0600 Subject: [PATCH 17/26] Bluetooth: L2CAP: Fix size check for receive buffer space Check that available receive space covers a full MTU-sized SDU and its overhead, rather than just the overhead. Otherwise, credits can be exhausted before an SDU is completed. This could result in a deadlock under some configurations and SDU combinations. This follows the SDU-sized credit policy from commit 96cd8eaa131f ("Bluetooth: L2CAP: Derive rx credits from MTU and MPS"). Clarify the comment by replacing "packet" with "SDU". Fixes: ce60b9231b66 ("Bluetooth: compute LE flow credits based on recvbuf space") Signed-off-by: Amir Abudubai Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index e5c15c083c1a..304ebafdfeaa 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1229,11 +1229,11 @@ static void l2cap_publish_rx_avail(struct l2cap_chan *chan) /* Correct available memory by estimated sk_buff overhead. * This is significant due to small transfer sizes. However, accept - * at least one full packet if receive space is non-zero. + * at least one full SDU if receive space is non-zero. */ expected_skbs = DIV_ROUND_UP(avail, chan->mps); skb_overhead = expected_skbs * sizeof(struct sk_buff); - if (skb_overhead < avail) + if (avail - skb_overhead >= chan->imtu + L2CAP_SDULEN_SIZE) l2cap_chan_rx_avail(chan, avail - skb_overhead); else l2cap_chan_rx_avail(chan, -1); From 76248359ac32e97cd7d1bd55a4c94a2ad4009871 Mon Sep 17 00:00:00 2001 From: Piyus Kedia Date: Thu, 12 Nov 2026 23:08:12 +0530 Subject: [PATCH 18/26] Bluetooth: L2CAP: clear the SDU before the receive callback l2cap_ecred_data_rcv() completes a reassembled SDU by calling l2cap_ecred_recv() with chan->sdu still set, and only clears the reassembly state after it returns: if (chan->sdu->len == chan->sdu_len) { err = l2cap_ecred_recv(chan, chan->sdu); if (!err) { chan->sdu = NULL; ... l2cap_ecred_recv() hands the SDU to the channel's receive callback, which takes ownership of it on success, and then updates the credits: err = chan->ops->recv(chan, skb); ... l2cap_chan_le_send_credits(chan); l2cap_chan_le_send_credits() calls l2cap_le_rx_credits(), which reads size_t sdu_len = chan->sdu ? chan->sdu->len : 0; so between the callback consuming the skb and the assignment above, chan->sdu is a dangling pointer that is dereferenced. For the 6LoWPAN channel the callback frees the skb outright - chan_recv_cb() -> recv_pkt() ends in consume_skb(skb) and returns NET_RX_SUCCESS - so the read is a straightforward use-after-free that KASAN reports: BUG: KASAN: slab-use-after-free in l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] BUG: KASAN: slab-use-after-free in l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 Read of size 4 at addr ffff88800e134070 by task kworker/u21:2/11352 Workqueue: hci0 hci_rx_work l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 l2cap_ecred_recv+0x63/0x120 net/bluetooth/l2cap_core.c:6873 l2cap_ecred_data_rcv net/bluetooth/l2cap_core.c:6976 [inline] l2cap_data_channel net/bluetooth/l2cap_core.c:7028 [inline] l2cap_recv_frame+0x6c3c/0x9650 net/bluetooth/l2cap_core.c:7162 l2cap_recv_acldata+0x6fd/0xe60 net/bluetooth/l2cap_core.c:7902 hci_acldata_packet net/bluetooth/hci_core.c:3865 [inline] hci_rx_work+0x3c0/0xbe0 net/bluetooth/hci_core.c:4092 Freed by task 11352: recv_pkt net/bluetooth/6lowpan.c chan_recv_cb+0x88/0x150 net/bluetooth/6lowpan.c:367 l2cap_ecred_recv+0x61/0x160 net/bluetooth/l2cap_core.c:6864 The buggy address belongs to the object at ffff88800e134000 which belongs to the cache skbuff_head_cache of size 240 The buggy address is located 112 bytes inside of freed 240-byte region Offset 112 is sk_buff.len. Only a multi-frame SDU is affected: the single-frame path already calls l2cap_ecred_recv() with chan->sdu NULL, so l2cap_le_rx_credits() reads a zero sdu_len there. l2cap_reassemble_sdu() completes a segmented SDU the same way and has the same defect. On an ERTM or streaming channel l2cap_sock_recv_cb() calls l2cap_publish_rx_avail(), which reaches l2cap_chan_le_send_credits() through l2cap_chan_rx_avail(), and that function evaluates u16 return_credits = l2cap_le_rx_credits(chan); in its initializer - before the mode test that makes the rest of it a no-op for a non-LE channel. So chan->sdu is dereferenced on that path too, and the result is discarded. What makes it a use-after-free rather than a stale read is a consumer that frees the skb from another thread: BNEP's session kthread takes it off the socket with a lockless skb_dequeue() (net/bluetooth/bnep/core.c:530, freed at :533) and never takes the socket lock, so lock_sock() is no defence. Fix both sites. Clear the reassembly state before handing the SDU to the callback, which makes the fragmented path behave like the single-frame one, and free the SDU on the spot if the callback refused it - the error path's kfree_skb(chan->sdu) used to do that, and the callbacks leave the skb to the caller when they fail. Clearing it first is also the arithmetically correct input, not merely a safe one. l2cap_le_rx_credits() subtracts sdu_len from chan->rx_avail because a partially reassembled SDU will claim that much receive buffer once it completes: if (chan->rx_avail <= sdu_len) return 0; return DIV_ROUND_UP(chan->rx_avail - sdu_len, chan->mps); A completed SDU is no longer waiting for that space. If the callback queued it, l2cap_sock_recv_cb() has already called l2cap_publish_rx_avail(), which recomputes rx_avail from sk_rcvbuf - sk_rmem_alloc with that skb included in sk_rmem_alloc; if the callback consumed it, as the 6LoWPAN one does, it occupies nothing at all. Either way the reassembly buffer is empty, so zero is the right sdu_len, and a NULL chan->sdu is how l2cap_le_rx_credits() expresses that - the same value l2cap_le_flowctl_init() depends on when it seeds chan->rx_credits on an idle channel. Carrying the old length into the calculation instead would subtract the SDU a second time and under-grant credits on every delivery, and once rx_avail fell to the size of one SDU the channel would be granted none at all. Per Documentation/process/generated-content.rst: the use-after-free was found by an AI-driven fuzzing harness built on syzkaller, developed jointly by Kapil Vaswani and myself, which drove a virtual HCI controller and a 6LoWPAN channel under KASAN on x86_64. The root-cause analysis, this changelog and the patch were written with the assistance of a large language model over an extended session, and reviewed by hand; the before/after testing below the --- was run by us. Fixes: ce60b9231b66 ("Bluetooth: compute LE flow credits based on recvbuf space") Signed-off-by: Kapil Vaswani Signed-off-by: Piyus Kedia Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 486b968143d3..4ee1e62ded7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6226,6 +6226,7 @@ static void append_skb_frag(struct sk_buff *skb, struct sk_buff *new_frag, static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, struct l2cap_ctrl *control) { + struct sk_buff *sdu; int err = -EINVAL; switch (control->sar) { @@ -6286,15 +6287,25 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, if (chan->sdu->len != chan->sdu_len) break; - err = chan->ops->recv(chan, chan->sdu); + /* Reassembly complete. Hand the SDU over before the + * callback, for the reason given in l2cap_ecred_data_rcv(): + * the callback takes ownership and may free it, while + * l2cap_chan_rx_avail() -> l2cap_chan_le_send_credits() reads + * chan->sdu->len on the way out - it does so before the mode + * test that makes the rest of that function a no-op here. + * Return directly, since the state this leaves is what the + * trailing error block would otherwise set again. + */ + sdu = chan->sdu; + chan->sdu = NULL; + chan->sdu_last_frag = NULL; + chan->sdu_len = 0; - if (!err) { - /* Reassembly complete */ - chan->sdu = NULL; - chan->sdu_last_frag = NULL; - chan->sdu_len = 0; - } - break; + err = chan->ops->recv(chan, sdu); + if (err) + kfree_skb(sdu); + + return err; } if (err) { @@ -7285,12 +7296,26 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) skb = NULL; if (chan->sdu->len == chan->sdu_len) { - err = l2cap_ecred_recv(chan, chan->sdu); - if (!err) { - chan->sdu = NULL; - chan->sdu_last_frag = NULL; - chan->sdu_len = 0; - } + struct sk_buff *sdu = chan->sdu; + + /* The receive callback takes ownership of a reassembled SDU and + * may free it, while l2cap_ecred_recv() goes on to update the + * credits - which reads chan->sdu->len. Drop the reassembly + * state before handing the SDU over, and release it here if the + * callback refused it, so that it is still freed exactly once. + * The reassembly state is already clear at that point, so + * return instead of falling into the failed: block, whose + * kfree_skb(chan->sdu) would have nothing left to free. + */ + chan->sdu = NULL; + chan->sdu_last_frag = NULL; + chan->sdu_len = 0; + + err = l2cap_ecred_recv(chan, sdu); + if (err) + kfree_skb(sdu); + + return 0; } failed: From 0d8f6981f55e28d8fac703bbd0e29bd9496c8b5b Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 13 Nov 2026 11:15:44 -0500 Subject: [PATCH 19/26] Bluetooth: 6lowpan: Always consume the skb in chan_recv_cb The l2cap_chan_ops recv callback takes ownership of the skb on success and leaves it to the caller on failure. chan_recv_cb() violates this: when recv_pkt() fails it returns -EAGAIN even though skb_share_check() may already have dropped the caller's reference to a shared skb and replaced it with a clone. The L2CAP caller then calls kfree_skb() on the original skb, over-releasing it, while the clone is leaked. Make recv_pkt() free the skb on its drop path and have chan_recv_cb() always consume the skb and return 0, including the lookup failures, so the caller never frees it again. A dropped packet is accounted in rx_dropped and no longer reported as a receive error to L2CAP. Fixes: 11e3ff707278 ("6lowpan: Use skb_cow in IPHC decompression.") Assisted-by: OpenCode:claude-sonnet-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 8c51c20f6c4b..68ca2f49dadc 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -345,6 +345,7 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev, return NET_RX_SUCCESS; drop: + kfree_skb(skb); dev->stats.rx_dropped++; return NET_RX_DROP; } @@ -356,21 +357,26 @@ static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) struct lowpan_peer *peer; int err; + /* The skb is always consumed, so never return an error that would + * make the caller free it again. + */ peer = lookup_peer(chan->conn); if (!peer) - return -ENOENT; + goto drop; dev = lookup_dev(chan->conn); if (!dev || !dev->netdev) - return -ENOENT; + goto drop; err = recv_pkt(skb, dev->netdev, peer); - if (err) { + if (err) BT_DBG("recv pkt %d", err); - err = -EAGAIN; - } - return err; + return 0; + +drop: + kfree_skb(skb); + return 0; } static int setup_header(struct sk_buff *skb, struct net_device *netdev, From b05fb50e255a3214683ee3f6a9433ea442c0ce04 Mon Sep 17 00:00:00 2001 From: Hex Lindqvist Date: Fri, 13 Nov 2026 14:20:24 -0800 Subject: [PATCH 20/26] Bluetooth: btintel: Don't log unsupported debug features as an error Since commit af395330abed ("Bluetooth: btintel: Add Intel devcoredump support"), setup sends Read Supported Features (0xfca6) to decide whether to register devcoredump. Older controllers such as the 8260 and 8265 reject it with Command Disallowed, so every probe logs: Bluetooth: hci0: Reading supported features failed (-16) Bluetooth: hci0: Error reading debug features This is harmless: it happens after the firmware is loaded and only means devcoredump is not registered. Log the failure at debug level there, and keep the error in btintel_set_quality_report(), where the user asked for the feature. Tested on an 8265 (8087:0a2b): the messages are gone and Bluetooth works as before. AI was used to help write and test this patch. Fixes: af395330abed ("Bluetooth: btintel: Add Intel devcoredump support") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219387 Signed-off-by: Hex Lindqvist Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 929018428c19..4cc5273fb175 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -1511,11 +1511,8 @@ static int btintel_read_debug_features(struct hci_dev *hdev, */ skb = __hci_cmd_sync(hdev, 0xfca6, sizeof(page_no), &page_no, HCI_INIT_TIMEOUT); - if (IS_ERR(skb)) { - bt_dev_err(hdev, "Reading supported features failed (%ld)", - PTR_ERR(skb)); + if (IS_ERR(skb)) return PTR_ERR(skb); - } if (skb->len != (sizeof(features->page1) + 3)) { bt_dev_err(hdev, "Supported features event size mismatch"); @@ -1632,8 +1629,10 @@ int btintel_set_quality_report(struct hci_dev *hdev, bool enable) * supported, need to load the additional DDC config to enable. */ err = btintel_read_debug_features(hdev, &features); - if (err) + if (err) { + bt_dev_err(hdev, "Reading supported features failed (%d)", err); return err; + } /* Set or reset the debug features. */ if (enable) @@ -1684,7 +1683,7 @@ static int btintel_register_devcoredump_support(struct hci_dev *hdev) err = btintel_read_debug_features(hdev, &features); if (err) { - bt_dev_info(hdev, "Error reading debug features"); + bt_dev_dbg(hdev, "Reading supported features failed (%d)", err); return err; } From 1f150a0bb8a1a2302f6895ac410f0aaaaa63b756 Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:42 +0000 Subject: [PATCH 21/26] Bluetooth: hci_conn: Free the unset handle when adding a connection fails hci_conn_add_unset() reserves a handle from hdev->unset_handle_ida and passes it to __hci_conn_add(). When __hci_conn_add() returns an error, no hci_conn exists, so hci_conn_cleanup() never runs and the handle is never returned to the IDA. It stays reserved until the device is released. The Sashiko AI reviewer found this while reviewing a change that adds another error return to __hci_conn_add(). Free the handle in hci_conn_add_unset() when __hci_conn_add() fails. Fixes: 181a42edddf5 ("Bluetooth: Make handle of hci_conn be unique") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index c468a9332e05..e44d9b29ab78 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1186,6 +1186,7 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, bdaddr_t *dst, u8 dst_type, u8 role) { + struct hci_conn *conn; int handle; bt_dev_dbg(hdev, "dst %pMR", dst); @@ -1194,7 +1195,11 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, if (unlikely(handle < 0)) return ERR_PTR(-ECONNREFUSED); - return __hci_conn_add(hdev, type, dst, dst_type, role, handle); + conn = __hci_conn_add(hdev, type, dst, dst_type, role, handle); + if (IS_ERR(conn)) + ida_free(&hdev->unset_handle_ida, handle); + + return conn; } struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, From 56abe5c17b4d7e3bdc83b9671549f407a7113ceb Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:43 +0000 Subject: [PATCH 22/26] Bluetooth: hci_conn: Refuse new connections once HCI_UP is cleared hci_dev_close_sync() clears HCI_UP and later calls hci_conn_hash_flush() to delete every connection. A connection created by __hci_conn_add() after the flush has run is never deleted. It keeps the hci_dev_hold() reference and the sysfs device taken in __hci_conn_add(), so the hci_dev is never freed, and its works can still be queued after the workqueue is drained. Check HCI_UP in __hci_conn_add(), which serves both hci_conn_add() and hci_conn_add_unset(). All callers hold hdev->lock: the HCI event handlers, create_pa_complete() in hci_sync.c, and the l2cap, sco, iso and mgmt paths that reach the hci_connect_*() and hci_bind_*() helpers. hci_conn_hash_flush() runs under hdev->lock too, so a connection is either added before the flush and deleted by it, or refused. Also include lockdep_assert_held() so the locking rule is checked. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index e44d9b29ab78..2fb37e078d73 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1019,6 +1019,15 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, struct hci_conn *conn; struct smp_irk *irk = NULL; + lockdep_assert_held(&hdev->lock); + + /* hci_dev_close_sync() clears HCI_UP before hci_conn_hash_flush(). + * A connection added after that would never be flushed, so refuse + * it. The caller holds hdev->lock, which the flush also takes. + */ + if (!test_bit(HCI_UP, &hdev->flags)) + return ERR_PTR(-ENETDOWN); + switch (type) { case ACL_LINK: if (!hdev->acl_mtu) From 1ea7a0946b9ea0a962640fc314bdef268e7c2791 Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:44 +0000 Subject: [PATCH 23/26] Bluetooth: hci_sync: Disable connection works before draining A connection delayed work whose timer was armed before hci_dev_close_sync() can expire while drain_workqueue() runs. delayed_work_timer_fn() then queues it on the draining workqueue and triggers the "cannot queue ... on wq" warning. hci_conn_drop() can also queue disc_work from another context during the drain. Disable the per-connection delayed works under hdev->lock before draining. A disabled work is cancelled and any later attempt to queue it fails, so neither the timers nor hci_conn_drop() can queue it. The connections are deleted by hci_conn_hash_flush() below, so nothing needs to re-enable the works. Fixes: 76727c02c1e1 ("Bluetooth: Call drain_workqueue() before resetting state") Reported-by: syzbot+5897b3c764f5989ea942@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=5897b3c764f5989ea942 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index e771f0f2f308..44ce776890d1 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5772,6 +5772,7 @@ static int hci_dev_shutdown(struct hci_dev *hdev) int hci_dev_close_sync(struct hci_dev *hdev) { + struct hci_conn *conn; bool auto_off; int err = 0; @@ -5839,6 +5840,22 @@ int hci_dev_close_sync(struct hci_dev *hdev) cancel_delayed_work_sync(&adv_instance->rpa_expired_cb); } + /* A delayed work whose timer was armed before close would queue + * itself while the workqueue is draining. Disable the connection + * works so that hci_conn_drop() and the timers can no longer queue + * them. The connections are deleted below, so nothing re-enables + * them. HCI_UP is clear, so no new connection can be added after + * this walk. + */ + hci_dev_lock(hdev); + list_for_each_entry(conn, &hdev->conn_hash.list, list) { + disable_delayed_work(&conn->disc_work); + disable_delayed_work(&conn->auto_accept_work); + disable_delayed_work(&conn->idle_work); + disable_delayed_work(&conn->le_conn_timeout); + } + hci_dev_unlock(hdev); + /* Avoid potential lockdep warnings from the *_flush() calls by * ensuring the workqueue is empty up front. */ From ee43bade37c4578b52a76cf0cdb199d3c0019506 Mon Sep 17 00:00:00 2001 From: Zhao Li Date: Mon, 16 Nov 2026 16:05:38 +0800 Subject: [PATCH 24/26] Bluetooth: hci_serdev: serialize flush with transmit work hci_uart_flush() runs on HCI close and reset and frees hu->tx_skb while write_work may still be sending the same partial frame. The worker can then resume with a freed skb, or both paths can free the frame. The tty flush has stopped write_work before freeing the partial frame since commit 1b0d946d6f08 ("Bluetooth: hci_uart: clear HCI_UART_SENDING when write_work is canceled"). Do the same in the serdev flush: disable and drain write_work before releasing the frame, and hold HCI_UART_SENDING meanwhile so that hci_uart_tx_wakeup() only records HCI_UART_TX_WAKEUP. Then re-enable the work, release SENDING and replay a wakeup that arrived in between. AI assistance was used. Fixes: 82f5169bf3d3 ("Bluetooth: hci_uart: add serdev driver support library") Cc: stable@vger.kernel.org # needs adjustments for <= 7.4 Signed-off-by: Zhao Li Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_serdev.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index d2c48df34199..194f11251cc5 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -97,17 +97,26 @@ static int hci_uart_flush(struct hci_dev *hdev) BT_DBG("hdev %p serdev %p", hdev, hu->serdev); + /* Stop write_work and hold SENDING so wakeups only set TX_WAKEUP. */ + disable_work_sync(&hu->write_work); + set_bit(HCI_UART_SENDING, &hu->tx_state); + if (hu->tx_skb) { kfree_skb(hu->tx_skb); hu->tx_skb = NULL; } - if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) - return 0; + if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { + /* Flush any pending characters in the driver and discipline. */ + serdev_device_write_flush(hu->serdev); - /* Flush any pending characters in the driver and discipline. */ - serdev_device_write_flush(hu->serdev); + hu->proto->flush(hu); + } - hu->proto->flush(hu); + /* Resume TX and replay a wakeup recorded while it was stopped. */ + enable_work(&hu->write_work); + clear_bit(HCI_UART_SENDING, &hu->tx_state); + if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) + hci_uart_tx_wakeup(hu); return 0; } From c9eb955c4fe2c2611a57625767c4cc57ab8c7558 Mon Sep 17 00:00:00 2001 From: Michael McAllister Date: Mon, 16 Nov 2026 16:35:14 +0000 Subject: [PATCH 25/26] Bluetooth: hci_mrvl: Leave the serdev port lifetime to hci_serdev hci_uart_register_device_priv() opens the port before calling mrvl_open(), so Marvell opens it twice. Likewise, mrvl_close() closes it before the transport closes it again during unregister or registration error cleanup. Remove the extra calls and let hci_serdev own the port lifetime. This also avoids failing probe when serdev rejects a second open with -EALREADY. Fixes: be70e5e774a6 ("Bluetooth: hci_mrvl: Add serdev support") Reported-by: Markus Probst Closes: https://lore.kernel.org/341e56b1ff7d8a5b109e26e30dfed61faa54d603.camel@posteo.de/ Signed-off-by: Michael McAllister Reviewed-by: Loic Poulain Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_mrvl.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/bluetooth/hci_mrvl.c b/drivers/bluetooth/hci_mrvl.c index 5798a8db016e..def19907c172 100644 --- a/drivers/bluetooth/hci_mrvl.c +++ b/drivers/bluetooth/hci_mrvl.c @@ -57,7 +57,6 @@ struct hci_mrvl_pkt { static int mrvl_open(struct hci_uart *hu) { struct mrvl_data *mrvl; - int ret; BT_DBG("hu %p", hu); @@ -75,17 +74,7 @@ static int mrvl_open(struct hci_uart *hu) hu->priv = mrvl; - if (hu->serdev) { - ret = serdev_device_open(hu->serdev); - if (ret) - goto err; - } - return 0; -err: - kfree(mrvl); - - return ret; } static int mrvl_close(struct hci_uart *hu) @@ -94,9 +83,6 @@ static int mrvl_close(struct hci_uart *hu) BT_DBG("hu %p", hu); - if (hu->serdev) - serdev_device_close(hu->serdev); - skb_queue_purge(&mrvl->txq); skb_queue_purge(&mrvl->rawq); kfree_skb(mrvl->rx_skb); From 5beb86f98c3d45f6d64be5b6d6c77480487b41b4 Mon Sep 17 00:00:00 2001 From: Nguyen Ngoc Thang Date: Tue, 17 Nov 2026 21:49:37 +0700 Subject: [PATCH 26/26] Bluetooth: L2CAP: return LE credits from recvmsg under the conn lock l2cap_chan_le_send_credits() allocates an ident from conn->tx_ida, sends L2CAP_LE_CREDITS and frees the ident right away, since the command has no response. The RX path frees idents in l2cap_put_ident() under conn->lock. That only works if the credits path holds conn->lock too, so that no response can be processed between the allocation and the free. The RX path does, but l2cap_sock_recvmsg() calls l2cap_publish_rx_avail() -> l2cap_chan_rx_avail() -> l2cap_chan_le_send_credits() with only the socket lock held. If the remote answers the credits packet with L2CAP_COMMAND_REJ, l2cap_put_ident() can free the ident first, and the credits path then frees it again: ida_free called for id=3 which is not allocated. WARNING: lib/idr.c:594 at ida_free+0x24c/0x2d4 lib/idr.c:594 Call trace: ida_free+0x24c/0x2d4 lib/idr.c:594 l2cap_chan_le_send_credits+0x17c/0x29c net/bluetooth/l2cap_core.c:7113 l2cap_chan_rx_avail+0xb4/0x134 net/bluetooth/l2cap_core.c:7126 l2cap_publish_rx_avail+0x110/0x168 net/bluetooth/l2cap_sock.c l2cap_sock_recvmsg+0x280/0x7b8 net/bluetooth/l2cap_sock.c:1317 The same unlocked call also updates chan->rx_credits and reads chan->sdu concurrently with the RX path. Publish rx_avail from recvmsg under conn->lock and chan->lock, taken with l2cap_chan_lock_conn() as l2cap_sock_defer() already does, before taking the socket lock to keep the conn->lock -> chan->lock -> sk_lock order. Assert conn->lock in l2cap_chan_le_send_credits() so that an unlocked caller is caught by lockdep. Fixes: 6e1930ece855 ("Bluetooth: L2CAP: fix tx ident leak for commands without a response") Reported-by: syzbot+9dc8780713b11155dd74@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9dc8780713b11155dd74 Signed-off-by: Nguyen Ngoc Thang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 3 +++ net/bluetooth/l2cap_sock.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4ee1e62ded7e..686e86c04d7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -7150,6 +7150,9 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan) pkt.cid = cpu_to_le16(chan->scid); pkt.credits = cpu_to_le16(return_credits); + /* Keeps l2cap_put_ident() from releasing ident before we do */ + lockdep_assert_held(&conn->lock); + ident = l2cap_get_ident(conn); l2cap_send_cmd(conn, ident, L2CAP_LE_CREDITS, sizeof(pkt), &pkt); diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 304ebafdfeaa..6b65710845dc 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1292,6 +1292,7 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct l2cap_pinfo *pi = l2cap_pi(sk); + bool have_conn; int err; if (unlikely(flags & MSG_ERRQUEUE)) @@ -1312,9 +1313,12 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, pi->chan->mode != L2CAP_MODE_EXT_FLOWCTL) return err; - lock_sock(sk); - + /* Returning credits must be serialized with the RX path */ + have_conn = l2cap_chan_lock_conn(pi->chan); l2cap_publish_rx_avail(pi->chan); + l2cap_chan_unlock_conn(pi->chan, have_conn); + + lock_sock(sk); /* Attempt to put pending rx data in the socket buffer */ while (!list_empty(&pi->rx_busy)) {