* [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity
@ 2026-11-25 23:36 Radek Podgorny
2026-11-25 23:36 ` [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Radek Podgorny @ 2026-11-25 23:36 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski,
linux-bluetooth, linux-kernel, Radek Podgorny
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@mail.gmail.com/
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@podgorny.cz
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@podgorny.cz
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@podgorny.cz
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@podgorny.cz
---
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@podgorny.cz>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU 2026-11-25 23:36 [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny @ 2026-11-25 23:36 ` Radek Podgorny 2026-11-26 3:51 ` Bluetooth: find an RPA peer's connection parameters by its identity bluez.test.bot 2026-11-25 23:36 ` [PATCH v5 2/4] Bluetooth: find a peer's LE connection by its IRK as well Radek Podgorny ` (2 subsequent siblings) 3 siblings, 1 reply; 8+ messages in thread From: Radek Podgorny @ 2026-11-25 23:36 UTC (permalink / raw) To: Marcel Holtmann, Luiz Augusto von Dentz Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski, linux-bluetooth, linux-kernel, Radek Podgorny hci_connect_le() looks up the peer's IRK with hci_find_irk_by_addr() and points dst at irk->rpa, which it later copies into the connection. The IRK list is RCU protected, and SMP removes and frees an IRK with kfree_rcu() without hdev->lock, which is all the caller holds, so the IRK can be freed while dst still points into it. Copy the RPA out under rcu_read_lock() instead. Fixes: 759331d7cc66 ("Bluetooth: Fix clearing SMP keys if pairing fails") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Radek Podgorny <radek@podgorny.cz> --- net/bluetooth/hci_conn.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 0b76df1bc5fd..8638b7f8dee3 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1526,6 +1526,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, { struct hci_conn *conn; struct smp_irk *irk; + bdaddr_t rpa; int err; /* Let's make sure that le is enabled.*/ @@ -1564,11 +1565,14 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, * be resolved back into the original identity address * from the connect request. */ + rcu_read_lock(); irk = hci_find_irk_by_addr(hdev, dst, dst_type); if (irk && bacmp(&irk->rpa, BDADDR_ANY)) { - dst = &irk->rpa; + bacpy(&rpa, &irk->rpa); + dst = &rpa; dst_type = ADDR_LE_DEV_RANDOM; } + rcu_read_unlock(); } if (conn) { -- 2.56.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: Bluetooth: find an RPA peer's connection parameters by its identity 2026-11-25 23:36 ` [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny @ 2026-11-26 3:51 ` bluez.test.bot 0 siblings, 0 replies; 8+ messages in thread From: bluez.test.bot @ 2026-11-26 3:51 UTC (permalink / raw) To: linux-bluetooth, radek [-- Attachment #1: Type: text/plain, Size: 4899 bytes --] This is automated email and please do not reply to this email! Dear submitter, Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series: PW Link:https://patchwork.kernel.org/series/1222693/ ---Test result--- Test Summary: CheckPatch FAIL 3.95 seconds VerifyFixes PASS 0.06 seconds VerifySignedoff PASS 0.06 seconds GitLint PASS 0.83 seconds SubjectPrefix PASS 0.21 seconds BuildKernel PASS 31.69 seconds CheckAllWarning PASS 35.56 seconds CheckSparse WARNING 37.78 seconds BuildKernel32 PASS 31.05 seconds CheckKernelLLVM PASS 35.35 seconds TestRunnerSetup PASS 746.14 seconds TestRunner_l2cap-tester PASS 14.96 seconds TestRunner_iso-tester PASS 13.07 seconds TestRunner_bnep-tester PASS 3.12 seconds TestRunner_mgmt-tester PASS 88.87 seconds TestRunner_rfcomm-tester PASS 4.46 seconds TestRunner_sco-tester PASS 5.57 seconds TestRunner_ioctl-tester PASS 4.63 seconds TestRunner_mesh-tester PASS 4.49 seconds TestRunner_smp-tester PASS 4.35 seconds TestRunner_userchan-tester PASS 3.16 seconds TestRunner_6lowpan-tester PASS 4.40 seconds IncrementalBuild PASS 87.45 seconds Details ############################## Test: CheckPatch - FAIL Desc: Run checkpatch.pl script Output: [v5,1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU WARNING: Non-standard signature: Assisted-by: #104: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #104: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 22 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15024021.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v5,2/4] Bluetooth: find a peer's LE connection by its IRK as well WARNING: Non-standard signature: Assisted-by: #128: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #128: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 128 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15024022.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v5,3/4] Bluetooth: connect to an RPA as to the identity behind it WARNING: Non-standard signature: Assisted-by: #120: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #120: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 55 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15024023.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v5,4/4] Bluetooth: find an RPA peer's connection parameters by its identity WARNING: Non-standard signature: Assisted-by: #135: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #135: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 286 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15024024.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. ############################## Test: CheckSparse - WARNING Desc: Run sparse tool with linux kernel Output: net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): https://github.com/bluez/bluetooth-next/pull/1230 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 2/4] Bluetooth: find a peer's LE connection by its IRK as well 2026-11-25 23:36 [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny @ 2026-11-25 23:36 ` Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 3/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 4/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny 3 siblings, 0 replies; 8+ messages in thread From: Radek Podgorny @ 2026-11-25 23:36 UTC (permalink / raw) To: Marcel Holtmann, Luiz Augusto von Dentz Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski, linux-bluetooth, linux-kernel, Radek Podgorny hci_connect_le() creates the connection under the peer's RPA when the controller cannot resolve it, and the connection stays there until it completes. hci_conn_hash_lookup_le() given the peer's identity misses it, and so does every caller looking the peer up by its identity in that window. hci_connect_le() itself is one: the connection stays BT_OPEN, out of sight of hci_lookup_le_connect(), until hci_le_create_conn_sync() runs, and 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 no connection is kept under the address given, have hci_conn_hash_lookup_le() find the one under an RPA of the peer whose identity it is, by the peer's IRK, which also finds it after the peer has moved to a new RPA. smp_irk_matches() is private to net/bluetooth, so the function moves out of line. The rcu_read_lock() it already takes covers the IRK list as well. hci_connect_le() refuses a connection found this way with -EBUSY, also while scanning: 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. hci_connect_le_scan() reuses it, as it does one found by address, except in that last case. That explicit connect, still scanning under the RPA with params of its own there, is never started, since the peer's advertising reports now resolve to its identity. Other connects to the peer get -EBUSY until its owner gives it up. A connection of their own would be dialled to the same RPA while the peer keeps it, and le_conn_complete_evt(), which matches a completion by address, would complete the older one and leave the new one in BT_CONNECT, refusing every LE connect after it. 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@podgorny.cz> --- include/net/bluetooth/hci_core.h | 27 ++------------ net/bluetooth/hci_conn.c | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 25 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 4aa0b49ae104..071131f08c0a 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1348,31 +1348,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_role(struct hci_dev *hdev, return NULL; } -static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev, - bdaddr_t *ba, - __u8 ba_type) -{ - struct hci_conn_hash *h = &hdev->conn_hash; - struct hci_conn *c; - - HCI_CONN_HASH_LOCKDEP_CHECK(hdev); - - rcu_read_lock(); - - list_for_each_entry_rcu(c, &h->list, list) { - if (c->type != LE_LINK) - continue; - - if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) { - rcu_read_unlock(); - return c; - } - } - - rcu_read_unlock(); - - return NULL; -} +struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev, bdaddr_t *ba, + __u8 ba_type); static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev, bdaddr_t *ba, diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 8638b7f8dee3..5676671d813c 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1520,6 +1520,59 @@ u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle) return 0; } +/* A connection to a peer the controller cannot resolve is kept under the + * peer's RPA until it completes, and the peer may have moved to a new RPA + * since. When there is no connection under the address given, find the one + * under an RPA of the peer whose identity it is, by the peer's IRK. A + * connection returned is therefore found by IRK only if its dst is not the + * address given. + * + * This function requires the caller holds hdev->lock, or rcu_read_lock() + * and req_lock as hci_cmd_sync_work() does: matching by IRK uses + * hdev->smp_data, which RCU does not protect, and which is set up and + * torn down under hdev->lock with req_lock held. + */ +struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev, bdaddr_t *ba, + __u8 ba_type) +{ + struct hci_conn_hash *h = &hdev->conn_hash; + struct hci_conn *c; + struct smp_irk *irk; + + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + + rcu_read_lock(); + + list_for_each_entry_rcu(c, &h->list, list) { + if (c->type != LE_LINK) + continue; + + if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) { + rcu_read_unlock(); + return c; + } + } + + irk = hci_find_irk_by_addr(hdev, ba, ba_type); + if (irk) { + list_for_each_entry_rcu(c, &h->list, list) { + if (c->type != LE_LINK || + !hci_bdaddr_is_rpa(&c->dst, c->dst_type)) + continue; + + if (smp_irk_matches(hdev, irk->val, &c->dst)) { + rcu_read_unlock(); + return c; + } + } + } + + rcu_read_unlock(); + + return NULL; +} +EXPORT_SYMBOL(hci_conn_hash_lookup_le); + struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, u8 dst_type, bool dst_resolved, u8 sec_level, u16 conn_timeout, u8 role, u8 phy, u8 sec_phy) @@ -1552,6 +1605,17 @@ 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. A connection of our own would be dialled to the + * same RPA, and le_conn_complete_evt(), which matches by address, + * would complete the older one. + */ + if (conn && (conn->dst_type != dst_type || bacmp(&conn->dst, dst))) + 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. */ @@ -1806,6 +1870,19 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, * and return the object found. */ conn = hci_conn_hash_lookup_le(hdev, dst, dst_type); + + /* Found by the peer's IRK, still scanning under an RPA with params + * of its own there, this is an explicit connect made to the RPA + * before the IRK was known, which is never started. Refuse, as + * hci_connect_le() does, rather than wait on it or dial a second + * connection to the same RPA. + */ + if (conn && test_bit(HCI_CONN_SCANNING, conn->flags) && + (conn->dst_type != dst_type || bacmp(&conn->dst, dst)) && + hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, + conn->dst_type)) + return ERR_PTR(-EBUSY); + if (conn) { if (conn->pending_sec_level < sec_level) conn->pending_sec_level = sec_level; -- 2.56.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 3/4] Bluetooth: connect to an RPA as to the identity behind it 2026-11-25 23:36 [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 2/4] Bluetooth: find a peer's LE connection by its IRK as well Radek Podgorny @ 2026-11-25 23:36 ` Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 4/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny 3 siblings, 0 replies; 8+ messages in thread From: Radek Podgorny @ 2026-11-25 23:36 UTC (permalink / raw) To: Marcel Holtmann, Luiz Augusto von Dentz Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski, linux-bluetooth, linux-kernel, Radek Podgorny A connect made to a peer's RPA through hci_connect_le_scan(), from Pair Device, an L2CAP socket or a CIS, looks for an existing connection by that RPA only. A bonded peer's established connection is kept under its identity, so the lookup misses it and a second hci_conn is created under the RPA. An L2CAP connect to the RPA of a connected peer does exactly that on v7.3.5. The connect also marks params under the RPA for itself, while the peer's advertising reports are resolved to its identity before check_pending_le_conn() looks params up, so it is never started and waits until it is cancelled. Resolve an RPA to the identity first, through a new hci_rpa_to_identity(), so the connect proceeds as one made to the identity: it finds the peer's connection, also one hci_connect_le() is still creating under an RPA, through the fallback by IRK the previous patch adds to hci_conn_hash_lookup_le(), and marks the identity's params. hci_connect_le() still puts the RPA on air when the controller cannot resolve it. SMP can free the IRK without hdev->lock, so the identity is copied out under rcu_read_lock(). An L2CAP channel keeps the address it was connected to, here the RPA, also when its connection is under the identity, as it already does when le_conn_complete_evt() moves a new connection to the identity. Fixes: f75113a26008 ("Bluetooth: add hci_connect_le_scan") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Radek Podgorny <radek@podgorny.cz> --- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_conn.c | 7 +++++++ net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 071131f08c0a..fa2d139574d2 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1904,6 +1904,8 @@ int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, u8 type); void hci_bdaddr_list_clear(struct list_head *list); +void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr, + u8 *addr_type, bdaddr_t *id_addr); struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 5676671d813c..fdebaf3c1982 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1851,6 +1851,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, enum conn_reasons conn_reason) { struct hci_conn *conn; + bdaddr_t id_addr; /* Let's make sure that le is enabled.*/ if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { @@ -1860,6 +1861,12 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, return ERR_PTR(-EOPNOTSUPP); } + /* Connect to the peer as if by its identity, under which its + * connection and parameters are kept. hci_connect_le() puts its RPA + * on air when the controller cannot resolve it. + */ + hci_rpa_to_identity(hdev, &dst, &dst_type, &id_addr); + /* Some devices send ATT messages as soon as the physical link is * established. To be able to handle these ATT messages, the user- * space first establishes the connection and then starts the pairing diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 024960e9af66..eb48488ab395 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2359,6 +2359,28 @@ int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, return 0; } +/* A peer we hold the IRK of is tracked under its identity address, so + * point *addr and *addr_type at the identity behind an RPA we can resolve. + * SMP can free the IRK without hdev->lock, so the identity is copied to + * @id_addr before leaving the RCU read-side section. + * + * This function requires the caller holds hdev->lock. + */ +void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr, + u8 *addr_type, bdaddr_t *id_addr) +{ + struct smp_irk *irk; + + rcu_read_lock(); + irk = hci_get_irk(hdev, *addr, *addr_type); + if (irk) { + bacpy(id_addr, &irk->bdaddr); + *addr = id_addr; + *addr_type = irk->addr_type; + } + rcu_read_unlock(); +} + /* This function requires the caller holds hdev->lock */ struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) -- 2.56.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 4/4] Bluetooth: find an RPA peer's connection parameters by its identity 2026-11-25 23:36 [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny ` (2 preceding siblings ...) 2026-11-25 23:36 ` [PATCH v5 3/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny @ 2026-11-25 23:36 ` Radek Podgorny 3 siblings, 0 replies; 8+ messages in thread From: Radek Podgorny @ 2026-11-25 23:36 UTC (permalink / raw) To: Marcel Holtmann, Luiz Augusto von Dentz Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski, linux-bluetooth, linux-kernel, Radek Podgorny A bonded peer's connection parameters are stored under its identity address, but hci_conn_params_lookup() matches only the exact address it is given. hci_le_create_conn_sync() is given the peer's RPA, since hci_connect_le() dials the cached RPA when the controller cannot resolve it, so it misses the entry and creates the connection with the controller-wide defaults instead of the peer's own parameters. Resolve an RPA to its identity in hci_conn_params_lookup() and in hci_conn_params_add(), which uses the result both to search and as the key of a new entry, so every caller finds the same entry whichever of the peer's addresses it holds. The identity is looked up instead of the RPA, not after it: Pair Device leaves an entry under the RPA the peer had before bonding, which matching first would hand out for as long as the peer keeps that RPA. Such an entry is cleared with the other disabled ones the next time all connection parameters are loaded. The entry found can then be under another address type than the one given; load_conn_subrate() looks the connection up with the entry's. SMP adds an IRK without hdev->lock, so a caller that resolves twice, in a lookup and then in an add, can see the two disagree. Such callers resolve once and use __hci_conn_params_lookup() and a new __hci_conn_params_add(), which do not resolve again: hci_explicit_conn_params_set(), given an address hci_connect_le_scan() has resolved, and Load Connection Parameters. Set Device Flags uses a single add. hci_conn_params_del() and Unpair Device keep matching exactly. What userspace sees, given an RPA: - Set and Get Device Flags act on the identity's entry, where Set used to create a separate one under the RPA and Get failed. The reply still carries the address given; Device Flags Changed names the identity. - Load Connection Parameters and Load Connection Subrate store the parameters under the identity. - New Connection Parameter, sent when a connection still under an RPA gets new parameters, names the identity whose entry was updated. It only carries identity addresses, so it used to be dropped there. 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@podgorny.cz> --- include/net/bluetooth/hci_core.h | 4 +++ net/bluetooth/hci_conn.c | 20 ++++++++++++--- net/bluetooth/hci_core.c | 55 +++++++++++++++++++++++++++++++++------- net/bluetooth/hci_event.c | 10 ++++++-- net/bluetooth/mgmt.c | 44 +++++++++++++++++--------------- 5 files changed, 99 insertions(+), 34 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index fa2d139574d2..213b3b56aeff 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1906,8 +1906,12 @@ void hci_bdaddr_list_clear(struct list_head *list); void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr, u8 *addr_type, bdaddr_t *id_addr); +struct hci_conn_params *__hci_conn_params_lookup(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type); struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); +struct hci_conn_params *__hci_conn_params_add(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type); struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index fdebaf3c1982..8150ea0fc21a 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -515,8 +515,10 @@ static int le_conn_update_sync(struct hci_dev *hdev, void *data) struct hci_conn *conn = d->conn; struct hci_conn_params *params; struct hci_cp_le_conn_update cp; + bdaddr_t addr; u16 timeout; u8 store_hint; + u8 addr_type; int err; /* Verify connection is still alive and read conn fields under @@ -554,6 +556,9 @@ static int le_conn_update_sync(struct hci_dev *hdev, void *data) */ hci_dev_lock(hdev); + bacpy(&addr, &conn->dst); + addr_type = conn->dst_type; + params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); if (params) { params->conn_min_interval = d->min; @@ -561,13 +566,17 @@ static int le_conn_update_sync(struct hci_dev *hdev, void *data) params->conn_latency = d->latency; params->supervision_timeout = d->to_multiplier; store_hint = 0x01; + + /* Report the entry updated, the identity's for an RPA */ + bacpy(&addr, ¶ms->addr); + addr_type = params->addr_type; } else { store_hint = 0x00; } hci_dev_unlock(hdev); - mgmt_new_conn_param(hdev, &conn->dst, conn->dst_type, store_hint, + mgmt_new_conn_param(hdev, &addr, addr_type, store_hint, d->min, d->max, d->latency, d->to_multiplier); return 0; @@ -1699,9 +1708,14 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev, if (is_connected(hdev, addr, addr_type)) return -EISCONN; - params = hci_conn_params_lookup(hdev, addr, addr_type); + /* hci_connect_le_scan() has resolved addr already. Resolving it + * again in each of the lookup and the add would let an IRK that + * arrives in between make the add return existing params, which + * would then be taken for new ones. + */ + params = __hci_conn_params_lookup(hdev, addr, addr_type); if (!params) { - params = hci_conn_params_add(hdev, addr, addr_type); + params = __hci_conn_params_add(hdev, addr, addr_type); if (!params) return -ENOMEM; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index eb48488ab395..32703c4d1ebd 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2381,9 +2381,13 @@ void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr, rcu_read_unlock(); } -/* This function requires the caller holds hdev->lock */ -struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, - bdaddr_t *addr, u8 addr_type) +/* Like hci_conn_params_lookup(), but without resolving an RPA to its + * identity. + * + * This function requires the caller holds hdev->lock. + */ +struct hci_conn_params *__hci_conn_params_lookup(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type) { struct hci_conn_params *params; @@ -2397,6 +2401,17 @@ struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, return NULL; } +/* This function requires the caller holds hdev->lock */ +struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type) +{ + bdaddr_t id_addr; + + hci_rpa_to_identity(hdev, &addr, &addr_type, &id_addr); + + return __hci_conn_params_lookup(hdev, addr, addr_type); +} + /* This function requires the caller holds hdev->lock or rcu_read_lock */ struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list, bdaddr_t *addr, u8 addr_type) @@ -2436,13 +2451,17 @@ void hci_pend_le_list_add(struct hci_conn_params *param, list_add_rcu(¶m->action, list); } -/* This function requires the caller holds hdev->lock */ -struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, - bdaddr_t *addr, u8 addr_type) +/* Like hci_conn_params_add(), but without resolving an RPA to its + * identity. + * + * This function requires the caller holds hdev->lock. + */ +struct hci_conn_params *__hci_conn_params_add(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type) { struct hci_conn_params *params; - params = hci_conn_params_lookup(hdev, addr, addr_type); + params = __hci_conn_params_lookup(hdev, addr, addr_type); if (params) return params; @@ -2469,6 +2488,20 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, return params; } +/* This function requires the caller holds hdev->lock */ +struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, + bdaddr_t *addr, u8 addr_type) +{ + bdaddr_t id_addr; + + /* Resolve once, and use the result both to search and as the key + * of a new entry. + */ + hci_rpa_to_identity(hdev, &addr, &addr_type, &id_addr); + + return __hci_conn_params_add(hdev, addr, addr_type); +} + void hci_conn_params_free(struct hci_conn_params *params) { hci_pend_le_list_del_init(params); @@ -2482,12 +2515,16 @@ void hci_conn_params_free(struct hci_conn_params *params) kfree(params); } -/* This function requires the caller holds hdev->lock */ +/* Unlike hci_conn_params_lookup() and hci_conn_params_add(), this matches + * addr exactly. + * + * This function requires the caller holds hdev->lock. + */ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) { struct hci_conn_params *params; - params = hci_conn_params_lookup(hdev, addr, addr_type); + params = __hci_conn_params_lookup(hdev, addr, addr_type); if (!params) return; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index b6c7f9a9f55a..125795339509 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -7580,6 +7580,8 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, void *data, if (hcon->role == HCI_ROLE_MASTER) { struct hci_conn_params *params; + bdaddr_t *addr = &hcon->dst; + u8 addr_type = hcon->dst_type; u8 store_hint; params = hci_conn_params_lookup(hdev, &hcon->dst, @@ -7590,12 +7592,16 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, void *data, params->conn_latency = latency; params->supervision_timeout = timeout; store_hint = 0x01; + + /* Report the entry updated, the identity's */ + addr = ¶ms->addr; + addr_type = params->addr_type; } else { store_hint = 0x00; } - mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, - store_hint, min, max, latency, timeout); + mgmt_new_conn_param(hdev, addr, addr_type, store_hint, min, max, + latency, timeout); } cp.handle = ev->handle; diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index d21538634bc3..41bb8f53f3d7 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -3422,7 +3422,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, set_bit(HCI_CONN_PARAM_REMOVAL_PEND, conn->flags); /* Disable auto-connection parameters if present */ - params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); + params = __hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); if (params) { if (params->explicit_connect) params->auto_connect = HCI_AUTO_CONN_EXPLICIT; @@ -5492,6 +5492,7 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, struct mgmt_cp_set_device_flags *cp = data; struct bdaddr_list_with_flags *br_params; struct hci_conn_params *params; + struct mgmt_addr_info ev_addr = cp->addr; u8 status = MGMT_STATUS_INVALID_PARAMS; u32 supported_flags; u32 current_flags = __le32_to_cpu(cp->current_flags); @@ -5526,19 +5527,16 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, goto unlock; } - params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, - le_addr_type(cp->addr.type)); + /* Create a new hci_conn_params if it doesn't exist. One add, which + * resolves an RPA once, rather than a lookup and an add that each + * resolve it and can disagree if the IRK arrives in between. + */ + params = hci_conn_params_add(hdev, &cp->addr.bdaddr, + le_addr_type(cp->addr.type)); if (!params) { - /* Create a new hci_conn_params if it doesn't exist */ - params = hci_conn_params_set(hdev, &cp->addr.bdaddr, - le_addr_type(cp->addr.type), - HCI_AUTO_CONN_DISABLED); - if (!params) { - bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", - &cp->addr.bdaddr, - le_addr_type(cp->addr.type)); - goto unlock; - } + bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", + &cp->addr.bdaddr, le_addr_type(cp->addr.type)); + goto unlock; } supported_flags = hdev->conn_flags; @@ -5552,6 +5550,10 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, WRITE_ONCE(params->flags, current_flags); status = MGMT_STATUS_SUCCESS; + /* Given an RPA, the flags changed are the identity's */ + bacpy(&ev_addr.bdaddr, ¶ms->addr); + ev_addr.type = link_to_bdaddr(LE_LINK, params->addr_type); + /* Update passive scan if HCI_CONN_FLAG_DEVICE_PRIVACY * has been set. */ @@ -5563,7 +5565,7 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, done: if (status == MGMT_STATUS_SUCCESS) - device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, + device_flags_changed(sk, hdev, &ev_addr.bdaddr, ev_addr.type, supported_flags, current_flags); return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, @@ -8392,6 +8394,7 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, for (i = 0; i < param_count; i++) { struct mgmt_conn_param *param = &cp->params[i]; + bdaddr_t *addr = ¶m->addr.bdaddr, id_addr; struct hci_conn_params *hci_param; u16 min, max, latency, timeout; bool update = false; @@ -8422,21 +8425,22 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, continue; } + /* Resolve once, so the lookup and the add below agree */ + hci_rpa_to_identity(hdev, &addr, &addr_type, &id_addr); + /* Detect when the loading is for an existing parameter then * attempt to trigger the connection update procedure. */ if (!i && param_count == 1) { - hci_param = hci_conn_params_lookup(hdev, - ¶m->addr.bdaddr, - addr_type); + hci_param = __hci_conn_params_lookup(hdev, addr, + addr_type); if (hci_param) update = true; else hci_conn_params_clear_disabled(hdev); } - hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, - addr_type); + hci_param = __hci_conn_params_add(hdev, addr, addr_type); if (!hci_param) { bt_dev_err(hdev, "failed to add connection parameters"); continue; @@ -8571,7 +8575,7 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data, conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr, - addr_type); + hci_param->addr_type); if (conn && conn->state == BT_CONNECTED && (conn->le_rate_interval < min || conn->le_rate_interval > max || -- 2.56.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU
@ 2026-11-24 9:30 Radek Podgorny
2026-11-24 18:48 ` Bluetooth: find an RPA peer's connection parameters by its identity bluez.test.bot
0 siblings, 1 reply; 8+ messages in thread
From: Radek Podgorny @ 2026-11-24 9:30 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski,
linux-bluetooth, linux-kernel, Radek Podgorny
hci_connect_le() looks up the peer's IRK with hci_find_irk_by_addr()
and points dst at irk->rpa, which it later copies into the connection.
The IRK list is RCU protected, and SMP removes and frees an IRK with
kfree_rcu() without hdev->lock, which is all the caller holds, so the
IRK can be freed while dst still points into it.
Copy the RPA out under rcu_read_lock() instead.
Fixes: 759331d7cc66 ("Bluetooth: Fix clearing SMP keys if pairing fails")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Radek Podgorny <radek@podgorny.cz>
---
net/bluetooth/hci_conn.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 0b76df1bc5fd..8638b7f8dee3 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1526,6 +1526,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
{
struct hci_conn *conn;
struct smp_irk *irk;
+ bdaddr_t rpa;
int err;
/* Let's make sure that le is enabled.*/
@@ -1564,11 +1565,14 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
* be resolved back into the original identity address
* from the connect request.
*/
+ rcu_read_lock();
irk = hci_find_irk_by_addr(hdev, dst, dst_type);
if (irk && bacmp(&irk->rpa, BDADDR_ANY)) {
- dst = &irk->rpa;
+ bacpy(&rpa, &irk->rpa);
+ dst = &rpa;
dst_type = ADDR_LE_DEV_RANDOM;
}
+ rcu_read_unlock();
}
if (conn) {
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* RE: Bluetooth: find an RPA peer's connection parameters by its identity 2026-11-24 9:30 [PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny @ 2026-11-24 18:48 ` bluez.test.bot 0 siblings, 0 replies; 8+ messages in thread From: bluez.test.bot @ 2026-11-24 18:48 UTC (permalink / raw) To: linux-bluetooth, radek [-- Attachment #1: Type: text/plain, Size: 4907 bytes --] This is automated email and please do not reply to this email! Dear submitter, Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series: PW Link:https://patchwork.kernel.org/series/1220594/ ---Test result--- Test Summary: CheckPatch FAIL 2.22 seconds VerifyFixes PASS 0.04 seconds VerifySignedoff PASS 0.04 seconds GitLint PASS 0.59 seconds SubjectPrefix PASS 0.16 seconds BuildKernel PASS 20.13 seconds CheckAllWarning PASS 22.73 seconds CheckSparse WARNING 24.24 seconds BuildKernel32 PASS 20.04 seconds CheckKernelLLVM PASS 21.69 seconds TestRunnerSetup PASS 480.48 seconds TestRunner_l2cap-tester PASS 13.51 seconds TestRunner_iso-tester PASS 11.72 seconds TestRunner_bnep-tester PASS 3.12 seconds TestRunner_mgmt-tester PASS 84.73 seconds TestRunner_rfcomm-tester PASS 4.34 seconds TestRunner_sco-tester PASS 5.39 seconds TestRunner_ioctl-tester PASS 4.47 seconds TestRunner_mesh-tester PASS 4.38 seconds TestRunner_smp-tester PASS 4.29 seconds TestRunner_userchan-tester PASS 3.17 seconds TestRunner_6lowpan-tester PASS 4.33 seconds IncrementalBuild PASS 35.62 seconds Details ############################## Test: CheckPatch - FAIL Desc: Run checkpatch.pl script Output: [v4,1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU WARNING: Non-standard signature: Assisted-by: #104: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #104: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 22 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15015926.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v4,2/4] Bluetooth: connect to an RPA as to the identity behind it WARNING: Non-standard signature: Assisted-by: #118: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #118: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 115 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15015925.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v4,3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA WARNING: Non-standard signature: Assisted-by: #113: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #113: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 15 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15015927.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. [v4,4/4] Bluetooth: find an RPA peer's connection parameters by its identity WARNING: Non-standard signature: Assisted-by: #137: Assisted-by: Claude:claude-opus-5-5 ERROR: Unrecognized email address: 'Claude:claude-opus-5-5' #137: Assisted-by: Claude:claude-opus-5-5 total: 1 errors, 1 warnings, 0 checks, 84 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /home/runner/work/bluetooth-next/bluetooth-next/src/patch/15015928.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. ############################## Test: CheckSparse - WARNING Desc: Run sparse tool with linux kernel Output: net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): https://github.com/bluez/bluetooth-next/pull/1213 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] Bluetooth: find an RPA peer's connection parameters by its identity
@ 2026-11-01 17:20 Radek Podgorny
2026-11-01 19:57 ` bluez.test.bot
0 siblings, 1 reply; 8+ messages in thread
From: Radek Podgorny @ 2026-11-01 17:20 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
Radek Podgorny
hci_le_create_conn_sync() looks up the peer's connection parameters by
conn->dst. Those parameters are stored under the identity address, but
hci_connect_le() puts the peer's cached RPA in conn->dst, and
__hci_conn_add() no longer converts it back when the controller cannot
translate an identity address.
The lookup then misses, and the connection is created with the
controller-wide defaults in hdev instead of the peer's interval, latency
and supervision timeout.
Resolve an RPA to its identity before the lookup, as
hci_connect_le_scan_cleanup() does. The other lookups by conn->dst run
after le_conn_complete_evt() has resolved it, so they are not affected.
Measured with btmon on a BCM4345C0 against a bonded peer that rotates
RPAs, with stored parameters of interval 12, latency 0 and timeout 600,
over six forced reconnects each way on v7.3.1:
before after
requested interval 30.00-50.00 ms 15.00-15.00 ms
requested timeout 420 ms 6000 ms
link interval 48.75 ms 15.00 ms
link timeout 420 ms 6000 ms
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@podgorny.cz>
---
This is the follow-up to the on-air address patch that Luiz said could
be done on top:
https://lore.kernel.org/linux-bluetooth/CABBYNZ+5zV8xzhHZKTUQYT4tLHaZAO7iiKOEsKuT8aA+YNLjPQ@mail.gmail.com/
What this does not establish:
- tested on v7.3.1, not on bluetooth-next; the patch applies to both
and bluetooth-next was only build-tested
- it shows the stored parameters now reach the controller. It does not
show that links are more reliable: all twelve reconnects succeeded,
with or without the patch
Per Documentation/process/generated-content.rst: the patch, this message
and the btmon test runs were done with the Claude coding assistant
(model as in the Assisted-by trailer). The prompts asked it to fix the
lookup miss named in the on-air address review, then to measure the
result on the author's van, with and without the patch. The author
directed the work and reviewed the result.
---
net/bluetooth/hci_sync.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 9d829c20c31604..810d6f5143342a 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7018,6 +7018,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
{
struct hci_cp_le_create_conn cp;
struct hci_conn_params *params;
+ struct smp_irk *irk;
u8 own_addr_type;
int err;
struct hci_conn *conn = data;
@@ -7057,7 +7058,16 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
hci_dev_lock(hdev);
- params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
+ /* conn->dst may hold the peer's RPA, but connection parameters are
+ * stored under its identity address.
+ */
+ irk = hci_get_irk(hdev, &conn->dst, conn->dst_type);
+ if (irk)
+ params = hci_conn_params_lookup(hdev, &irk->bdaddr,
+ irk->addr_type);
+ else
+ params = hci_conn_params_lookup(hdev, &conn->dst,
+ conn->dst_type);
if (params) {
conn->le_conn_min_interval = params->conn_min_interval;
conn->le_conn_max_interval = params->conn_max_interval;
---
base-commit: 42b8c2d729268a65a2d98064e8dc59ff53646b14
change-id: 20261101-for-upstream-le-conn-params-rpa-f2334fb5dda7
--
Radek Podgorny <radek@podgorny.cz>
^ permalink raw reply related [flat|nested] 8+ messages in thread* RE: Bluetooth: find an RPA peer's connection parameters by its identity 2026-11-01 17:20 [PATCH] " Radek Podgorny @ 2026-11-01 19:57 ` bluez.test.bot 0 siblings, 0 replies; 8+ messages in thread From: bluez.test.bot @ 2026-11-01 19:57 UTC (permalink / raw) To: linux-bluetooth, radek [-- Attachment #1: Type: text/plain, Size: 3251 bytes --] This is automated email and please do not reply to this email! Dear submitter, Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series: PW Link:https://patchwork.kernel.org/series/1198202/ ---Test result--- Test Summary: CheckPatch PASS 3.92 seconds VerifyFixes PASS 1.28 seconds VerifySignedoff PASS 0.11 seconds GitLint PASS 0.31 seconds SubjectPrefix PASS 0.11 seconds BuildKernel PASS 28.99 seconds CheckAllWarning PASS 33.23 seconds CheckSparse PASS 35.53 seconds BuildKernel32 PASS 29.33 seconds CheckKernelLLVM PASS 31.75 seconds TestRunnerSetup PASS 678.99 seconds TestRunner_l2cap-tester FAIL 12.14 seconds TestRunner_iso-tester PASS 10.45 seconds TestRunner_bnep-tester PASS 2.99 seconds TestRunner_mgmt-tester PASS 86.50 seconds TestRunner_rfcomm-tester PASS 4.29 seconds TestRunner_sco-tester PASS 5.38 seconds TestRunner_ioctl-tester PASS 4.50 seconds TestRunner_mesh-tester PASS 5.32 seconds TestRunner_smp-tester PASS 4.17 seconds TestRunner_userchan-tester PASS 3.06 seconds TestRunner_6lowpan-tester PASS 4.24 seconds IncrementalBuild PASS 27.60 seconds Details ############################## Test: TestRunner_l2cap-tester - FAIL Desc: Run l2cap-tester with test-runner Output: Sanitizer errors: ==36==ERROR: AddressSanitizer: heap-use-after-free on address 0x7b926a3e33d0 at pc 0x556ffff58e8e bp 0x7ffc6f1889b0 sp 0x7ffc6f1889a0 READ of size 4 at 0x7b926a3e33d0 thread T0 #0 0x556ffff58e8d in timeout_callback src/shared/timeout-mainloop.c:33 #1 0x556ffff59b75 in timeout_callback src/shared/mainloop.c:270 #2 0x556ffff5aaa6 in mainloop_run src/shared/mainloop.c:124 #3 0x556ffff5d3fa in mainloop_run_with_signal src/shared/mainloop-notify.c:196 #4 0x556ffff6264b in tester_run src/shared/tester.c:1223 #5 0x556fffe8c17d in main tools/l2cap-tester.c:3918 #6 0x7f526b350600 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:59 #7 0x7f526b350717 in __libc_start_main_impl ../csu/libc-start.c:360 #8 0x556fffe92c84 in _start (/home/runner/work/bluetooth-next/bluetooth-next/src/bluez/tools/l2cap-tester+0x16cc84) (BuildId: 91c9d49e9766c394468e27ffa29b05e7d348169f) 0x7b926a3e33d0 is located 0 bytes inside of 40-byte region [0x7b926a3e33d0,0x7b926a3e33f8) freed by thread T0 here: #0 0x7f526bc8e3ff in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:51 #1 0x556ffff5936a in timeout_destroy src/shared/mainloop.c:251 previously allocated by thread T0 here: #0 0x7f526bc8f60f in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:67 #1 0x556ffff432d5 in util_malloc src/shared/util.c:46 SUMMARY: AddressSanitizer: heap-use-after-free src/shared/timeout-mainloop.c:33 in timeout_callback No test result found https://github.com/bluez/bluetooth-next/pull/1037 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-26 3:51 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-25 23:36 [PATCH v5 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny 2026-11-26 3:51 ` Bluetooth: find an RPA peer's connection parameters by its identity bluez.test.bot 2026-11-25 23:36 ` [PATCH v5 2/4] Bluetooth: find a peer's LE connection by its IRK as well Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 3/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny 2026-11-25 23:36 ` [PATCH v5 4/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny -- strict thread matches above, loose matches on Subject: below -- 2026-11-24 9:30 [PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny 2026-11-24 18:48 ` Bluetooth: find an RPA peer's connection parameters by its identity bluez.test.bot 2026-11-01 17:20 [PATCH] " Radek Podgorny 2026-11-01 19:57 ` bluez.test.bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox