Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect
       [not found] <20261205063610.2523018-1-praneethb2002@gmail.com>
@ 2026-12-05  6:36 ` Praneeth Balasubramanian
  2026-12-05  6:36 ` [PATCH 2/2] Bluetooth: btintel: hold req_lock when triggering coredump Praneeth Balasubramanian
  1 sibling, 0 replies; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:36 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Praneeth Balasubramanian, stable, linux-bluetooth, linux-kernel

btusb_mtk_release_iso_intf() can run twice on the same device. An HCI
command timeout schedules btusb_mtk_reset() as cmd_sync work and that
reset releases the MediaTek ISO interface through this helper. The USB
disconnect path calls the same helper via the disconnect callback, and
btusb_disconnect() runs that callback before hci_unregister_dev() drains
the cmd_sync work. When a command timeout and a USB disconnect overlap
both calls can see the same non-NULL btmtk_data->isopkt_skb and each pass
it to dev_kfree_skb_irq(). The second free of the skb is a double free.

Change the entry test of BTMTK_ISOPKT_OVER_INTR to
test_and_clear_bit(). The first caller performs the cleanup. A caller
that loses the race finds the flag already cleared and returns without
touching the skb or the interface. The trailing unconditional
clear_bit() of the flag is now redundant and is removed.

A losing caller on the disconnect side no longer frees the skb itself.
It still waits for the reset work inside hci_unregister_dev() before it
finishes.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: 489304e67087 ("Bluetooth: btusb: mediatek: add intf release flow when usb disconnect")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3 and
    checked against the source with Claude Opus 5.5. I reviewed the patch
    and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.
    
    Leon Romanovsky's series (v5 02/33, 2026-12-03) fixes the locking on the
    claim side in btusb_mtk_claim_iso_intf(). This patch is about the
    release side.
    
    usb_driver_release_interface() expects the USB device lock, and the
    reset path does not hold it. This patch does not add it. Taking it in
    the reset work would deadlock with btusb_disconnect(), which waits for
    that work in hci_unregister_dev(). So that part is left as is.

 drivers/bluetooth/btusb_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c
index 7d510c399ec3..1fca69477292 100644
--- a/drivers/bluetooth/btusb_main.c
+++ b/drivers/bluetooth/btusb_main.c
@@ -3056,7 +3056,7 @@ static void btusb_mtk_release_iso_intf(struct hci_dev *hdev)
 	if (!btmtk_data)
 		return;
 
-	if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
+	if (test_and_clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
 		usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor);
 		clear_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags);
 
@@ -3072,8 +3072,6 @@ static void btusb_mtk_release_iso_intf(struct hci_dev *hdev)
 			btmtk_data->isopkt_intf = NULL;
 		}
 	}
-
-	clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
 }
 
 static int btusb_mtk_disconnect(struct hci_dev *hdev)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] Bluetooth: btintel: hold req_lock when triggering coredump
       [not found] <20261205063610.2523018-1-praneethb2002@gmail.com>
  2026-12-05  6:36 ` [PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect Praneeth Balasubramanian
@ 2026-12-05  6:36 ` Praneeth Balasubramanian
  1 sibling, 0 replies; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:36 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Praneeth Balasubramanian, stable, linux-bluetooth, linux-kernel

btintel_coredump() calls __hci_cmd_sync() while running from the
devcoredump sysfs store, which only holds the device lock. The
__hci_cmd_sync() contract requires hdev->req_lock. Without it the
coredump trigger command shares hdev->req_status and hdev->req_rsp with
the cmd_sync work.

A management command issued through MGMT_OP_HCI_CMD_SYNC runs in that
work with req_lock held. If both callers are in flight, a single
completion stores one skb in hdev->req_rsp and wakes both waiters. Each
can read that skb before the other clears the pointer. One path frees it
and the other frees it again, a use-after-free followed by a double
free.

The coredump sysfs file is only writable by root, so the exposure is
limited. I found no path in btusb that takes req_lock before the device
lock, so taking req_lock here should not deadlock.

Wrap the trigger command with hci_req_sync_lock() and
hci_req_sync_unlock() so it is serialized against the cmd_sync work as
the contract requires.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: af395330abed ("Bluetooth: btintel: Add Intel devcoredump support")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3,
    then checked against the source and partly rewritten with Claude Opus
    5.5. I reviewed the patch and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.

 drivers/bluetooth/btintel.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index ca98bd106b86..c6cfbfcfed09 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -1713,7 +1713,10 @@ static void btintel_coredump(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
 
+	hci_req_sync_lock(hdev);
 	skb = __hci_cmd_sync(hdev, 0xfc4e, 0, NULL, HCI_CMD_TIMEOUT);
+	hci_req_sync_unlock(hdev);
+
 	if (IS_ERR(skb)) {
 		bt_dev_err(hdev, "Coredump failed (%ld)", PTR_ERR(skb));
 		return;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05  6:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261205063610.2523018-1-praneethb2002@gmail.com>
2026-12-05  6:36 ` [PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect Praneeth Balasubramanian
2026-12-05  6:36 ` [PATCH 2/2] Bluetooth: btintel: hold req_lock when triggering coredump Praneeth Balasubramanian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox