* 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
* [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity
@ 2026-11-24 9:30 Radek Podgorny
2026-11-24 9:30 ` [PATCH v4 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-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
v4 answers Luiz's question on v3 about hci_conn_params_add() resolving
the address before a lookup that resolves it again, and fixes what
Sashiko raised on v3:
https://lore.kernel.org/all/CABBYNZLFtpr8xFjnimRZ9VKOsEgUV-Gzf61bomK4u+SMEyqBxA@mail.gmail.com/
https://sashiko.dev/#/patchset/20261109-for-upstream-le-conn-params-rpa-v3-1-ad1225bb0b8f%40podgorny.cz
The single v3 patch is now four. Patch 4 is the v3 fix itself. The
first three fix bugs in bluetooth-next that it exposes or sits next to,
and each stands on its own:
1. hci_connect_le() keeps pointing into an IRK after leaving RCU.
2. A connect to a peer's RPA misses the connection the peer already
has under its identity and adds a second hci_conn.
3. A second advertising report before LE Create Connection is sent
adds a second hci_conn for a peer dialled under its RPA.
4. The connection is created with the controller-wide defaults instead
of the peer's own parameters.
Patches 3 and 4 use helpers added in patch 2; patch 1 is independent.
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 this
series for three days (6 of 6 forced reconnects and 179 connects in
normal use). 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 and waits until it times out. Not
exercised: a controller that resolves the address itself and a peer
with no cached RPA, which this controller and peer cannot reach, and a
second advertising report before LE Create Connection is sent.
Known limitations, raised by a local Sashiko run and left as they are:
- Patch 3: if an explicit connect was made to a peer's RPA before its
IRK was known, auto-connect to the identity gets -EBUSY until whoever
made that connect cancels it, which for Pair Device is userspace: a
connect that was never started has no timeout. Reusing that
connection instead hands the auto-connect params a reference they do
not own. Avoiding both needs the explicit connect moved to the
identity when the IRK is added, which is a separate change.
- Patch 2: 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 the question raised on v3, then to review the
result with a local run of Sashiko and with Sashiko's published review
prompts, and fix what that turned up. The author directed the work and
reviewed the result.
---
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: connect to an RPA as to the identity behind it
Bluetooth: refuse to dial a peer whose connection is under its RPA
Bluetooth: find an RPA peer's connection parameters by its identity
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 75 ++++++++++++++++++++++++++++++++++++++--
net/bluetooth/hci_core.c | 50 ++++++++++++++++++++++++---
net/bluetooth/hci_event.c | 4 +--
net/bluetooth/mgmt.c | 4 +--
5 files changed, 125 insertions(+), 10 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 v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU
2026-11-24 9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
@ 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
2026-11-24 9:30 ` [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny
` (2 subsequent siblings)
3 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
* [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it
2026-11-24 9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
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 9:30 ` Radek Podgorny
2026-11-24 16:35 ` Luiz Augusto von Dentz
2026-11-24 9:30 ` [PATCH v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA Radek Podgorny
2026-11-24 9:31 ` [PATCH v4 4/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
3 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
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, which waits until the connect times out. 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 either.
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 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().
A connection hci_connect_le() is already creating for the peer is kept
under the RPA it dials, which the lookup by the identity now misses.
Fall back to finding the peer's connection by its IRK, which also finds
it after the peer has moved to a new RPA.
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 | 57 ++++++++++++++++++++++++++++++++++++++++
net/bluetooth/hci_core.c | 20 ++++++++++++++
3 files changed, 79 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 4aa0b49ae104..28eb79dd51f0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1927,6 +1927,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 8638b7f8dee3..c1583cb6c28a 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1520,6 +1520,54 @@ 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. Match it by the peer's IRK instead of by address.
+ *
+ * This function requires the caller holds hdev->lock.
+ */
+static struct hci_conn *le_conn_by_irk(struct hci_dev *hdev,
+ const u8 irk_val[16])
+{
+ struct hci_conn_hash *h = &hdev->conn_hash;
+ struct hci_conn *c;
+
+ rcu_read_lock();
+ 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;
+}
+
+/* Find the LE connection of the peer at addr by the peer's IRK, for when it
+ * is kept under one of the peer's RPAs instead of addr.
+ *
+ * This function requires the caller holds hdev->lock.
+ */
+static struct hci_conn *le_conn_lookup_irk(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type)
+{
+ struct hci_conn *conn = NULL;
+ struct smp_irk *irk;
+
+ rcu_read_lock();
+ irk = hci_find_irk_by_addr(hdev, addr, addr_type);
+ if (irk)
+ conn = le_conn_by_irk(hdev, irk->val);
+ rcu_read_unlock();
+
+ return conn;
+}
+
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)
@@ -1787,6 +1835,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)) {
@@ -1796,6 +1845,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
@@ -1806,6 +1861,8 @@ 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);
+ if (!conn)
+ conn = le_conn_lookup_irk(hdev, dst, dst_type);
if (conn) {
if (conn->pending_sec_level < sec_level)
conn->pending_sec_level = sec_level;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 024960e9af66..a87c92dccd4f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2359,6 +2359,26 @@ 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.
+ */
+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 v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA
2026-11-24 9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
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 9:30 ` [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny
@ 2026-11-24 9:30 ` Radek Podgorny
2026-11-24 9:31 ` [PATCH v4 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-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() 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@podgorny.cz>
---
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 4/4] Bluetooth: find an RPA peer's connection parameters by its identity
2026-11-24 9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
` (2 preceding siblings ...)
2026-11-24 9:30 ` [PATCH v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA Radek Podgorny
@ 2026-11-24 9:31 ` Radek Podgorny
3 siblings, 0 replies; 8+ messages in thread
From: Radek Podgorny @ 2026-11-24 9:31 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, so a caller holding the peer's RPA misses the entry.
hci_le_create_conn_sync() is such a caller: 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
connection is then created with the controller-wide defaults in hdev
instead of the peer's interval, latency and supervision timeout.
Resolve an RPA to its identity in hci_conn_params_lookup(), 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
creates an entry under the RPA the peer had before bonding, and that
entry stays behind with default parameters. Matching it first would hand
it out for as long as the peer keeps that RPA. Such an entry is no
longer reachable by its RPA once the IRK is known; it is cleared with
the other disabled entries the next time all connection parameters are
loaded.
hci_conn_params_del() goes through the same lookup, so given a
resolvable RPA it now acts on the identity entry. hci_conn_params_add()
resolves the address once and uses the result both to look for an
existing entry and as the key of a new one, so a new entry is created
under the identity and a later lookup by the identity or by a rotated
RPA finds it. hci_connect_le_scan_cleanup() and le_conn_complete_evt()
free the explicit connect's entry they already hold instead of deleting
it by address, since that lookup now resolves the address again and
could reach another entry if the IRK arrived in between.
The returned entry can therefore hold a different address type than
the one the caller passed. load_conn_param() and load_conn_subrate()
look up the connection by the entry's address with the caller's type;
use the entry's type with it.
Set Device Flags and Get Device Flags given an RPA now act on the
identity's entry, where Set used to create a separate one under the RPA,
which only a lookup by that same RPA could find, and Get failed. Their
reply and the Device Flags Changed event still carry the address the
caller gave, as other mgmt commands do.
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>
---
net/bluetooth/hci_conn.c | 3 ++-
net/bluetooth/hci_core.c | 30 ++++++++++++++++++++++++++----
net/bluetooth/hci_event.c | 4 ++--
net/bluetooth/mgmt.c | 4 ++--
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 791df930650e..c37271586345 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -117,7 +117,8 @@ void hci_connect_le_scan_cleanup(struct hci_conn *conn, u8 status)
switch (params->auto_connect) {
case HCI_AUTO_CONN_EXPLICIT:
- hci_conn_params_del(hdev, bdaddr, bdaddr_type);
+ hci_conn_params_free(params);
+ hci_update_passive_scan(hdev);
/* return instead of break to avoid duplicate scan update */
return;
case HCI_AUTO_CONN_DIRECT:
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index a87c92dccd4f..568c99bf86db 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2379,9 +2379,14 @@ 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.
+ */
+static struct hci_conn_params *__hci_conn_params_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr,
+ u8 addr_type)
{
struct hci_conn_params *params;
@@ -2395,6 +2400,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)
@@ -2439,8 +2455,14 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
bdaddr_t *addr, u8 addr_type)
{
struct hci_conn_params *params;
+ bdaddr_t id_addr;
- params = hci_conn_params_lookup(hdev, addr, addr_type);
+ /* 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);
+
+ params = __hci_conn_params_lookup(hdev, addr, addr_type);
if (params)
return params;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b6c7f9a9f55a..f7dbfb484d01 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -6551,8 +6551,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
switch (params->auto_connect) {
case HCI_AUTO_CONN_EXPLICIT:
- hci_conn_params_del(hdev, &conn->dst,
- conn->dst_type);
+ hci_conn_params_free(params);
+ hci_update_passive_scan(hdev);
break;
case HCI_AUTO_CONN_REPORT:
hci_pend_le_list_add(params,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d21538634bc3..64886b0a9091 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -8456,7 +8456,7 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
* a connection update.
*/
conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr,
- addr_type);
+ hci_param->addr_type);
if (conn && conn->role == HCI_ROLE_MASTER &&
(conn->le_conn_min_interval != min ||
conn->le_conn_max_interval != max ||
@@ -8571,7 +8571,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
* Re: [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it
2026-11-24 9:30 ` [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny
@ 2026-11-24 16:35 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-24 16:35 UTC (permalink / raw)
To: Radek Podgorny
Cc: Marcel Holtmann, Luiz Augusto von Dentz, Johan Hedberg,
Jakub Pawlowski, linux-bluetooth, linux-kernel
Hi Radek,
On Tue, Nov 24, 2026 at 4:31 AM Radek Podgorny <radek@podgorny.cz> wrote:
>
> 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, which waits until the connect times out. 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 either.
>
> 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 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().
>
> A connection hci_connect_le() is already creating for the peer is kept
> under the RPA it dials, which the lookup by the identity now misses.
> Fall back to finding the peer's connection by its IRK, which also finds
> it after the peer has moved to a new RPA.
>
> 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 | 57 ++++++++++++++++++++++++++++++++++++++++
> net/bluetooth/hci_core.c | 20 ++++++++++++++
> 3 files changed, 79 insertions(+)
>
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 4aa0b49ae104..28eb79dd51f0 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1927,6 +1927,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 8638b7f8dee3..c1583cb6c28a 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -1520,6 +1520,54 @@ 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. Match it by the peer's IRK instead of by address.
> + *
> + * This function requires the caller holds hdev->lock.
> + */
> +static struct hci_conn *le_conn_by_irk(struct hci_dev *hdev,
> + const u8 irk_val[16])
> +{
> + struct hci_conn_hash *h = &hdev->conn_hash;
> + struct hci_conn *c;
> +
> + rcu_read_lock();
> + 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;
> +}
> +
> +/* Find the LE connection of the peer at addr by the peer's IRK, for when it
> + * is kept under one of the peer's RPAs instead of addr.
> + *
> + * This function requires the caller holds hdev->lock.
> + */
> +static struct hci_conn *le_conn_lookup_irk(struct hci_dev *hdev,
> + bdaddr_t *addr, u8 addr_type)
> +{
> + struct hci_conn *conn = NULL;
> + struct smp_irk *irk;
> +
> + rcu_read_lock();
> + irk = hci_find_irk_by_addr(hdev, addr, addr_type);
> + if (irk)
> + conn = le_conn_by_irk(hdev, irk->val);
> + rcu_read_unlock();
> +
> + return conn;
> +}
> +
> 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)
> @@ -1787,6 +1835,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)) {
> @@ -1796,6 +1845,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
> @@ -1806,6 +1861,8 @@ 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);
> + if (!conn)
> + conn = le_conn_lookup_irk(hdev, dst, dst_type);
Any reason why le_conn_lookup_irk is not incorporated into
hci_conn_hash_lookup_le? That would mean other plcares that want to
resolve a hci_conn to a peer always lookup by both address or irk not
just by address.
> if (conn) {
> if (conn->pending_sec_level < sec_level)
> conn->pending_sec_level = sec_level;
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 024960e9af66..a87c92dccd4f 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -2359,6 +2359,26 @@ 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.
> + */
> +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
>
--
Luiz Augusto von Dentz
^ permalink raw reply [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
end of thread, other threads:[~2026-11-24 18:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
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-24 9:30 ` [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny
2026-11-24 16:35 ` Luiz Augusto von Dentz
2026-11-24 9:30 ` [PATCH v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA Radek Podgorny
2026-11-24 9:31 ` [PATCH v4 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-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