[PATCH v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA
From: Radek Podgorny
Date: Tue Nov 24 2026 - 04:31:35 EST
hci_connect_le() creates the connection under the peer's RPA when the
controller cannot resolve it, and the connection stays BT_OPEN, out of
sight of hci_lookup_le_connect(), until hci_le_create_conn_sync() runs.
A second advertising report in that window looks the connection up by
the identity, misses it, creates another hci_conn and overwrites
params->conn.
When the lookup by address misses, look the peer's connection up by its
IRK and refuse with -EBUSY. That includes a scanning connection: under
an RPA, it has either been started by an earlier advertising report
already, or it belongs to an explicit connect made before the IRK was
known, and so to other params, which taking it over would hand a
reference they do not own. In that last case the explicit connect can
no longer be started either, since the peer's advertising reports now
resolve to its identity, and auto-connect to the identity waits until
the owner of the explicit connect gives it up.
Fixes: 4914c4998961 ("Bluetooth: put the peer's on-air address on air when we cannot resolve")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Radek Podgorny <radek@xxxxxxxxxxx>
---
net/bluetooth/hci_conn.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index c1583cb6c28a..791df930650e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1600,6 +1600,15 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
if (conn && !test_bit(HCI_CONN_SCANNING, conn->flags))
return ERR_PTR(-EBUSY);
+ /* A connection found by the peer's IRK instead is under one of its
+ * RPAs. It is refused even while scanning: it has then either been
+ * started by an earlier advertising report already, or it belongs
+ * to an explicit connect made before the IRK was known, and so to
+ * other params.
+ */
+ if (!conn && le_conn_lookup_irk(hdev, dst, dst_type))
+ return ERR_PTR(-EBUSY);
+
/* Check if the destination address has been resolved by the controller
* since if it did then the identity address shall be used.
*/
--
2.56.1