* [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* 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 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* 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
* [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