Skip to content

bluetooth: smp: CTKD issue when cross br and ble connections and security #90574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MarkWangChinese
Copy link
Collaborator

The peer uses the RPA address.
A BR connection is created firstly, a subsequent BLE connection is created secondly, the BR SMP CTKD occur thirdly (The BLE LTK is derived from BR and the BR SMP distribute peer's IRK and identity address here), but the BLE LTK is saved to key pool that is not matched with the previous BLE connection because the derived LTK is saved with identity address and BLE connection uses RPA. Fix it by: Resolve the BLE connections' RPA with the derived IRK to find the previous BLE connections and match the connections with derived LTK key.

@github-actions github-actions bot added area: Bluetooth area: Bluetooth Host Bluetooth Host (excluding BR/EDR) labels May 26, 2025
@Thalley Thalley removed their request for review May 26, 2025 10:53
@alwa-nordic alwa-nordic added the area: Bluetooth Classic Bluetooth Classic (BR/EDR) label May 27, 2025
@alwa-nordic alwa-nordic requested review from lylezhu2012 and removed request for alwa-nordic May 27, 2025 13:58
@MarkWangChinese MarkWangChinese force-pushed the feature/cross_br_ble_conns_security_ctkd_issue branch from c0cf761 to 5d6b8f1 Compare May 28, 2025 01:45
{
struct bt_keys *keys = data;

if (!bt_addr_le_is_identity(&conn->le.dst) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!bt_addr_le_is_identity(&conn->le.dst) &&
if (!bt_addr_le_is_rpa(&conn->le.dst)) {
return;
}
if (

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@MarkWangChinese MarkWangChinese force-pushed the feature/cross_br_ble_conns_security_ctkd_issue branch from 5d6b8f1 to 3da815d Compare May 28, 2025 13:47
@MarkWangChinese MarkWangChinese force-pushed the feature/cross_br_ble_conns_security_ctkd_issue branch from 3da815d to 202aaa9 Compare June 6, 2025 01:20
Comment on lines +1526 to +1535
if (conn->le.keys != NULL && conn->le.keys != keys) {
bt_keys_clear(conn->le.keys);
}

conn->le.keys = keys;
/* always update last use RPA */
bt_addr_copy(&keys->irk.rpa, &conn->le.dst.a);
bt_addr_le_copy(&conn->le.dst, &keys->addr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two questions here,
Question 1, if the ACL of LE has been encrypted and the LTK is changed now, how to handle this case? key refresh? or disconnect the link?
Question 2, if the ACL of LE is not encrypted and the LTK is available now, whether the ACL needs to be encrypted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Q1, I think it is initiator side's issue because the BLE connection is existed and encrypted, but initiator still trigger the CTKD. I prefer to disconnect the ble connection here. what do you think?
For Q2, I don't think stack need to enable the encryption. It is the application to determine whether to encrypt the BLE connection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think the Q1 issue exist too for the normal CTKD case. Maybe we can improve/fix it in further pr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lylezhu2012 Could you please help to check again?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add comments here for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comments are added.

…rity

The peer uses the RPA address.
A BR connection is created firstly, a subsequent BLE connection is
created secondly, the BR SMP CTKD occur thirdly (The BLE LTK is
derived from BR and the BR SMP distribute peer's IRK and identity address
here), but the BLE LTK is saved to key pool that is not
matched with the previous BLE connection because the derived LTK is saved
with identity address and BLE connection uses RPA. Fix it by: Resolve the
BLE connections' RPA with the derived IRK to find the previous BLE
connections and match the connections with derived LTK key.

Signed-off-by: Mark Wang <[email protected]>
need to consider corner cases of ctkd as the added code comments.

Signed-off-by: Mark Wang <[email protected]>
@MarkWangChinese MarkWangChinese force-pushed the feature/cross_br_ble_conns_security_ctkd_issue branch from 202aaa9 to e18810b Compare July 3, 2025 02:49
Copy link

sonarqubecloud bot commented Jul 3, 2025

@jhedberg jhedberg added this to the v4.2.0 milestone Jul 3, 2025
@danieldegrasse danieldegrasse merged commit 80c1e69 into zephyrproject-rtos:main Jul 4, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Classic Bluetooth Classic (BR/EDR) area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants