[PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity
From: Radek Podgorny
Date: Wed Nov 25 2026 - 18:37:32 EST
v5 folds the lookup of a peer's connection by its IRK into
hci_conn_hash_lookup_le(), as Luiz asked on v4:
https://lore.kernel.org/all/CABBYNZKCSXsMb++hkgxk+Q8m1W1=+=Z_sgpaQFgWtnSJg8G43w@xxxxxxxxxxxxxx/
Patch 4 is the v3 fix itself, and the first three fix bugs in
bluetooth-next that it exposes or sits next to. By patch:
1. hci_connect_le() keeps pointing into an IRK after leaving RCU.
2. A lookup by a peer's identity misses its connection while
hci_connect_le() is creating it under an RPA, so a second
advertising report before LE Create Connection is sent adds a
second hci_conn.
3. A connect to a peer's RPA misses the connection the peer already
has under its identity and adds a second hci_conn.
4. The connection is created with the controller-wide defaults instead
of the peer's own parameters.
Patch 4 uses the helper added in patch 3, and patch 3 relies on patch 2
to find a connection still being created; patches 1 and 2 stand on
their own.
Tested on v7.3.5 (the flags tests need &c->flags there) on a Raspberry
Pi CYW43455 central and a peer on a resolvable private address whose
parameters are loaded under its identity: first with three successive
builds of v4 applied as one patch (17 of 17 connects), then with the v4
series for three days (6 of 6 forced reconnects and 179 connects in
normal use), and then with v5 through its review rounds, each build with
three forced reconnects, Device Flags by RPA and the probes below. Every
connect was one Create Connection to the RPA, including across RPA
rotations between attempts, and those captured on air carried the
identity's parameters. With the peer connected, an L2CAP connect to its
current or a previous RPA now finds the existing connection, as one to
its identity does; without the changes it adds a second hci_conn under
the RPA, which is never started. Not exercised: a controller that
resolves the address itself and a peer with no cached RPA, which this
controller and peer cannot reach, a second advertising report before LE
Create Connection is sent, and an IRK arriving while an explicit connect
to the RPA waits.
Known limitations, raised by local Sashiko runs and left as they are:
- Patch 2: if an explicit connect was made to a peer's RPA before its
IRK was known, it is never started, and other connects to the peer,
auto-connect included, get -EBUSY until whoever made it cancels it,
which for Pair Device is userspace; Disconnect by the identity now
cancels it too. Reusing that connection hands its
reference to params that do not own it, and a connection of their
own would be dialled to the same RPA, where le_conn_complete_evt(),
which matches by address, completes the older one and leaves the new
one blocking every LE connect after it, as happens without the
series. Avoiding all of these needs the explicit connect moved to the
identity when the IRK is added, which is a separate change.
- Patch 3: Cancel Pair Device by an RPA no longer finds a pairing
started by that RPA when the IRK was already known. It now behaves as
a pairing started by the identity, which is how bluetoothd starts one
for a peer whose IRK it holds.
Per Documentation/process/generated-content.rst: the patches and this
message were done with the Claude coding assistant (model as in the
Assisted-by trailer). The prompts asked it to fix the issues Sashiko
raised on v2 and v3 and answer the questions raised on v3 and v4, then
to review the result with a local run of Sashiko and with Sashiko's
published review prompts run on the GLM model through the oh-my-pi
agent, and fix what that turned up. The author directed the work and
reviewed the result.
---
Changes in v5:
- hci_conn_hash_lookup_le(): fall back to finding the peer's
connection by its IRK when given its identity, out of line since
smp_irk_matches() is private to net/bluetooth (Luiz). This replaces
le_conn_lookup_irk() in hci_connect_le() and hci_connect_le_scan()
- hci_connect_le(): refuse a connection found by IRK by comparing its
dst with the address given
- hci_connect_le_scan(): refuse with -EBUSY a connection still
scanning under an RPA with params of its own there, an explicit
connect made before the IRK was known that is never started, instead
of waiting on it (local Sashiko)
- hci_explicit_conn_params_set(): look up and add without resolving
again, through __hci_conn_params_lookup() and a new
__hci_conn_params_add(), and so does Load Connection Parameters after
resolving once; Set Device Flags: a single add instead of a lookup
and an add; hci_conn_params_del() and Unpair Device: match exactly,
as before. An IRK arriving in between can then not make any
of them act on the identity's entry (local Sashiko)
- hci_connect_le_scan_cleanup() and le_conn_complete_evt(): back to
hci_conn_params_del(), which matches exactly; load_conn_param() looks
the connection up with the type it resolved
- Set Device Flags: send Device Flags Changed for the identity whose
flags changed when given an RPA (local Sashiko)
- New Connection Parameter: name the identity whose entry was updated
when the connection is still under an RPA (local Sashiko)
- Patches 2 and 3 reordered: 2 is now the lookup and the refusal,
3 the resolve in hci_connect_le_scan()
- Link to v4: https://patch.msgid.link/20261124-for-upstream-le-conn-params-rpa-v4-0-f2dd5eb41f45@xxxxxxxxxxx
Changes in v4:
- Split into four patches (Sashiko)
- hci_conn_params_add(): resolve once, through a new
__hci_conn_params_lookup() that does not resolve again (Luiz, Sashiko)
- New patch 2, hci_connect_le_scan(): resolve an RPA to the identity
first, so a connect to an RPA neither creates its connection under
the RPA nor misses one the peer already has under its identity
(Sashiko). Add Device, which Sashiko also named, accepts only
identity addresses
- New patch 3, hci_connect_le(): when the lookup by address misses,
find the peer's connection by IRK and refuse it with -EBUSY, also
while scanning, since a scanning one then belongs to other params. A
second advertising report before LE Create Connection is sent no
longer creates a second hci_conn (Sashiko). This replaces v3's reuse
of a scanning connection found by IRK, which patch 2 makes
unnecessary
- New patch 1: copy the RPA dialled out of the IRK under RCU
- Rebased on bluetooth-next
- Link to v3: https://patch.msgid.link/20261109-for-upstream-le-conn-params-rpa-v3-1-ad1225bb0b8f@xxxxxxxxxxx
Changes in v3:
- Look up the identity instead of the RPA, not after it, so an entry
left under the peer's pre-bonding RPA cannot shadow it
- Copy the identity out of the IRK under rcu_read_lock(), since SMP can
free the IRK without hdev->lock
- hci_conn_params_add() stores a new entry under the identity
- load_conn_param() and load_conn_subrate(): look up the connection with
the entry's address type
- hci_connect_le(): find the scanning connection of a connect made to
the peer's RPA by its IRK, so it is not duplicated once the identity
entry is pending, even after the peer has moved to a new RPA, and
also when the controller resolved the advertisement or no RPA is
cached for the peer. Kept in this patch, since on its own it would
leave a reference imbalance until the lookup is fixed
- Rebased on bluetooth-next
- Link to v2: https://patch.msgid.link/20261104120138.1165715-1-radek@xxxxxxxxxxx
Changes in v2:
- Resolve the RPA inside hci_conn_params_lookup() rather than at the
hci_le_create_conn_sync() call site, as Luiz suggested, so no other
caller can miss the entry
- Rebased on bluetooth-next
- Link to v1: https://patch.msgid.link/20261101-for-upstream-le-conn-params-rpa-v1-1-988629a09bc9@xxxxxxxxxxx
---
Radek Podgorny (4):
Bluetooth: copy the peer's RPA out of its IRK under RCU
Bluetooth: find a peer's LE connection by its IRK as well
Bluetooth: connect to an RPA as to the identity behind it
Bluetooth: find an RPA peer's connection parameters by its identity
include/net/bluetooth/hci_core.h | 33 +++---------
net/bluetooth/hci_conn.c | 110 +++++++++++++++++++++++++++++++++++++--
net/bluetooth/hci_core.c | 77 +++++++++++++++++++++++----
net/bluetooth/hci_event.c | 10 +++-
net/bluetooth/mgmt.c | 44 +++++++++-------
5 files changed, 214 insertions(+), 60 deletions(-)
---
base-commit: ffb95458a0f70dcab620eee0ecf5ef7750971b2f
change-id: 20261101-for-upstream-le-conn-params-rpa-f2334fb5dda7
--
Radek Podgorny <radek@xxxxxxxxxxx>