From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org, linux-bluetooth@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect
Date: Fri, 4 Dec 2026 22:36:09 -0800 [thread overview]
Message-ID: <20261205063610.2523018-2-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063610.2523018-1-praneethb2002@gmail.com>
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
next prev parent reply other threads:[~2026-12-05 6:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:36 [PATCH 0/2] Bluetooth: fix an ISO skb double free and coredump locking Praneeth Balasubramanian
2026-12-05 6:36 ` Praneeth Balasubramanian [this message]
2026-12-05 12:34 ` bluez.test.bot
2026-12-05 6:36 ` [PATCH 2/2] Bluetooth: btintel: hold req_lock when triggering coredump Praneeth Balasubramanian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205063610.2523018-2-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.