All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/7] Bluetooth: hci_conn: hold conn references in hci_sync tasks
@ 2026-07-25  9:59 Pauli Virtanen
  2026-07-25  9:59 ` [PATCH v5 1/7] Bluetooth: hci_conn: hold conn reference in abort_conn_sync() Pauli Virtanen
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Pauli Virtanen @ 2026-07-25  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen, marcel, luiz.dentz, oss, linux-kernel

Have hci_sync tasks hold reference to hci_conn pointer they want to use
later.

Avoids UAFs and passing potentially reused (possible even if very
unlikely) pointers to hci_conn_valid().

hci_conn_del() dequeues running works for the same connection, but this
has no effect if the work is already started running, which is the race
condition here.

v5:
- resend
- no need to check hci_conn_valid() in create_big_complete, the bit is
  safe to clear also if hci_conn_del() has run

v4:
- Check !conn in hci_connect_big_sync() first.
  It's probably bug in iso.c that it may call this with NULL, but
  probably better fixed separately.

v3:
- resending some rebased parts from
  https://lore.kernel.org/linux-bluetooth/cover.1762100290.git.pav@iki.fi/
  https://lore.kernel.org/linux-bluetooth/cover.1758481869.git.pav@iki.fi/

Pauli Virtanen (7):
  Bluetooth: hci_conn: hold conn reference in abort_conn_sync()
  Bluetooth: hci_sync: hold conn in hci_connect_acl/le_sync() callbacks
  Bluetooth: hci_sync: hold conn in hci_connect_big_sync() callback
  Bluetooth: hci_sync: hold conn in hci_connect_pa_sync() callback
  Bluetooth: hci_sync: hold conn in hci_past_sync() callback
  Bluetooth: hci_sync: fix hci_conn_del() use in hci_le_create_conn_sync
  Bluetooth: hci_sync: remove unnecessary hci_conn_get in
    create_conn_sync

 net/bluetooth/hci_conn.c | 12 +++++-
 net/bluetooth/hci_sync.c | 85 +++++++++++++++++++++++++---------------
 2 files changed, 65 insertions(+), 32 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [PATCH v4 1/7] Bluetooth: hci_conn: hold conn reference in abort_conn_sync()
@ 2026-06-28 13:20 Pauli Virtanen
  2026-06-28 15:07 ` Bluetooth: hci_conn: hold conn references in hci_sync tasks bluez.test.bot
  0 siblings, 1 reply; 10+ messages in thread
From: Pauli Virtanen @ 2026-06-28 13:20 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen, marcel, luiz.dentz, oss, linux-kernel

There is theoretical UAF if the conn is freed while the hci_sync task is
running.

Hold refcount to avoid that.

Fixes: 227a0cdf4a02 ("Bluetooth: MGMT: Fix not generating command complete for MGMT_OP_DISCONNECT")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
---

Notes:
    v4:
    - no change
    v3:
    - split to multiple patches per different Fixes:

 net/bluetooth/hci_conn.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 1966cd153d97..6036ff66d8d9 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -3163,6 +3163,13 @@ static int abort_conn_sync(struct hci_dev *hdev, void *data)
 	return hci_abort_conn_sync(hdev, conn, conn->abort_reason);
 }
 
+static void abort_conn_destroy(struct hci_dev *hdev, void *data, int err)
+{
+	struct hci_conn *conn = data;
+
+	hci_conn_put(conn);
+}
+
 int hci_abort_conn(struct hci_conn *conn, u8 reason)
 {
 	struct hci_dev *hdev = conn->hdev;
@@ -3188,7 +3195,10 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
 	 * as a result to MGMT_OP_DISCONNECT/MGMT_OP_UNPAIR which does
 	 * already queue its callback on cmd_sync_work.
 	 */
-	err = hci_cmd_sync_run_once(hdev, abort_conn_sync, conn, NULL);
+	err = hci_cmd_sync_run_once(hdev, abort_conn_sync, hci_conn_get(conn),
+				    abort_conn_destroy);
+	if (err)
+		hci_conn_put(conn);
 	return (err == -EEXIST) ? 0 : err;
 }
 
-- 
2.54.0


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

end of thread, other threads:[~2026-07-25 10:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25  9:59 [PATCH v5 0/7] Bluetooth: hci_conn: hold conn references in hci_sync tasks Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 1/7] Bluetooth: hci_conn: hold conn reference in abort_conn_sync() Pauli Virtanen
2026-07-25 10:50   ` Bluetooth: hci_conn: hold conn references in hci_sync tasks bluez.test.bot
2026-07-25  9:59 ` [PATCH v5 2/7] Bluetooth: hci_sync: hold conn in hci_connect_acl/le_sync() callbacks Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 3/7] Bluetooth: hci_sync: hold conn in hci_connect_big_sync() callback Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 4/7] Bluetooth: hci_sync: hold conn in hci_connect_pa_sync() callback Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 5/7] Bluetooth: hci_sync: hold conn in hci_past_sync() callback Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 6/7] Bluetooth: hci_sync: fix hci_conn_del() use in hci_le_create_conn_sync Pauli Virtanen
2026-07-25  9:59 ` [PATCH v5 7/7] Bluetooth: hci_sync: remove unnecessary hci_conn_get in create_conn_sync Pauli Virtanen
  -- strict thread matches above, loose matches on Subject: below --
2026-06-28 13:20 [PATCH v4 1/7] Bluetooth: hci_conn: hold conn reference in abort_conn_sync() Pauli Virtanen
2026-06-28 15:07 ` Bluetooth: hci_conn: hold conn references in hci_sync tasks bluez.test.bot

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.