[PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU
From: Radek Podgorny
Date: Tue Nov 24 2026 - 04:31:58 EST
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@xxxxxxxxxxx>
---
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