Linux bluetooth development
 help / color / mirror / Atom feed
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 2/2] Bluetooth: btintel: hold req_lock when triggering coredump
Date: Fri,  4 Dec 2026 22:36:10 -0800	[thread overview]
Message-ID: <20261205063610.2523018-3-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063610.2523018-1-praneethb2002@gmail.com>

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


      parent reply	other threads:[~2026-12-05  6:36 UTC|newest]

Thread overview: 3+ 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 ` [PATCH 1/2] Bluetooth: btusb: Fix double free of ISO skb when reset races disconnect Praneeth Balasubramanian
2026-12-05  6:36 ` Praneeth Balasubramanian [this message]

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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox