[PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect

From: Praneeth Balasubramanian

Date: Sat Dec 05 2026 - 01:36:37 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Praneeth Balasubramanian <praneethb2002@xxxxxxxxx>
---

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