From: Michael Bommarito <michael.bommarito@gmail.com>
To: "Marcel Holtmann" <marcel@holtmann.org>,
"Luiz Augusto von Dentz" <luiz.dentz@gmail.com>,
"Jonas Dreßler" <verdre@v0yd.nl>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Mat Martineau <martineau@kernel.org>,
netdev@vger.kernel.org, stable@vger.kernel.org,
Pauli Virtanen <pav@iki.fi>, Aaron Esau <git@aaronesau.com>,
Michael Bommarito <michael.bommarito@gmail.com>
Subject: [PATCH 4/4] Bluetooth: hci_sync: pin conn across hci_acl_create_conn_sync
Date: Mon, 11 May 2026 10:34:04 -0400 [thread overview]
Message-ID: <a586369f30357a4efe549f567f0629ba5ee0e7f9.1778506829.git.michael.bommarito@gmail.com> (raw)
In-Reply-To: <cover.1778506829.git.michael.bommarito@gmail.com>
hci_acl_create_conn_sync() shares the TOCTOU pattern with the
three sibling cmd_sync callbacks just fixed: the work item's
void *data is interpreted as a struct hci_conn pointer, validated
with hci_conn_valid() at entry, then immediately written
(conn->state, conn->out, conn->role, conn->attempt++) followed by
a memcpy(conn->dev_class, ie->data.dev_class, 3). If the TOCTOU
race fires the memcpy lands on a freed slot; the three dev_class
bytes are sourced from a remote BR/EDR inquiry response, so a
successful exploit can land attacker-chosen bytes into the heap
object that reused conn's slot.
A KASAN slab-use-after-free splat in cache kmalloc-8k at
conn->state confirms the bug on linux-next tip commit bee6ea30c487
("Add linux-next specific files for 20260421") with the synthetic
harness driving the conn->state write.
The existing queue site at hci_connect_acl_sync() passed a NULL
destroy callback, so the conn was never pinned for the cmd_sync
workqueue dispatch. Introduce create_acl_conn_complete() to balance
the conn pin and convert the queue site to the
hci_cmd_sync_queue_conn_once() helper. The dequeue-on-cancel path
in hci_cancel_connect_sync() now looks up the entry with the same
destroy callback, keeping the hci_cmd_sync_lookup_entry() triple
match consistent.
Prior art: Pauli Virtanen's PATCH v2 8/8 at
https://lore.kernel.org/linux-bluetooth/e18591f264c50e15917cb8b9e5f9798d9880979d.1762100290.git.pav@iki.fi/.
Fixes: 45340097ce6e ("Bluetooth: hci_conn: Only do ACL connections sequentially")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
---
net/bluetooth/hci_sync.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 47ce9ba63fe2..9a133de16f63 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6994,12 +6994,21 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
conn->conn_timeout, NULL);
}
+static void create_acl_conn_complete(struct hci_dev *hdev, void *data, int err)
+{
+ struct hci_conn *conn = data;
+
+ bt_dev_dbg(hdev, "err %d", err);
+
+ hci_conn_put(conn);
+}
+
int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn)
{
int err;
- err = hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn,
- NULL);
+ err = hci_cmd_sync_queue_conn_once(hdev, hci_acl_create_conn_sync, conn,
+ create_acl_conn_complete);
return (err == -EEXIST) ? 0 : err;
}
@@ -7054,7 +7063,8 @@ int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn)
case ACL_LINK:
return !hci_cmd_sync_dequeue_once(hdev,
hci_acl_create_conn_sync,
- conn, NULL);
+ conn,
+ create_acl_conn_complete);
case LE_LINK:
return !hci_cmd_sync_dequeue_once(hdev, hci_le_create_conn_sync,
conn, create_le_conn_complete);
--
2.53.0
prev parent reply other threads:[~2026-05-11 14:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 14:34 [PATCH 0/4] Bluetooth: hci_sync: fix TOCTOU UAF in cmd_sync callbacks Michael Bommarito
2026-05-11 14:34 ` [PATCH 1/4] Bluetooth: hci_sync: pin conn across hci_le_create_conn_sync Michael Bommarito
2026-05-11 14:53 ` Luiz Augusto von Dentz
2026-05-11 17:01 ` Michael Bommarito
2026-05-11 17:35 ` Luiz Augusto von Dentz
2026-05-11 14:34 ` [PATCH 2/4] Bluetooth: hci_sync: pin conn across hci_le_pa_create_sync Michael Bommarito
2026-05-11 14:34 ` [PATCH 3/4] Bluetooth: hci_sync: pin conn across hci_le_big_create_sync Michael Bommarito
2026-05-11 14:34 ` Michael Bommarito [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=a586369f30357a4efe549f567f0629ba5ee0e7f9.1778506829.git.michael.bommarito@gmail.com \
--to=michael.bommarito@gmail.com \
--cc=git@aaronesau.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=martineau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pav@iki.fi \
--cc=stable@vger.kernel.org \
--cc=verdre@v0yd.nl \
/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