Skip to content

Commit 5f7fbb6

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: Fix LTK cannot be derived issue
The LTK cannot be derived by LK when LK is not weaker than the old LTK. Improve the function `smp_br_pairing_allowed()` to avoid the LTK be overwrote when old LTK has MITM protection but new LK has not MITM protection. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 68f300d commit 5f7fbb6

File tree

1 file changed

+5
-3
lines changed
  • subsys/bluetooth/host

1 file changed

+5
-3
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ static bool smp_br_pairing_allowed(struct bt_smp_br *smp)
12631263
bt_addr_le_t addr;
12641264
struct bt_conn *conn;
12651265
struct bt_keys_link_key *key;
1266-
bool le_bonded;
1266+
struct bt_keys *le_keys;
12671267

12681268
if (!smp->chan.chan.conn) {
12691269
return false;
@@ -1273,7 +1273,7 @@ static bool smp_br_pairing_allowed(struct bt_smp_br *smp)
12731273

12741274
addr.type = BT_ADDR_LE_PUBLIC;
12751275
bt_addr_copy(&addr.a, &conn->br.dst);
1276-
le_bonded = bt_le_bond_exists(BT_ID_DEFAULT, &addr);
1276+
le_keys = bt_keys_find_addr(BT_ID_DEFAULT, &addr);
12771277

12781278
key = bt_keys_find_link_key(&conn->br.dst);
12791279
if (!key) {
@@ -1287,7 +1287,9 @@ static bool smp_br_pairing_allowed(struct bt_smp_br *smp)
12871287
* or MITM protection, then neither device shall generate an LE LTK using cross-transport
12881288
* key derivation from a BR/EDR link key.
12891289
*/
1290-
if (le_bonded && !(key->flags & BT_LINK_KEY_AUTHENTICATED)) {
1290+
if ((le_keys != NULL) && ((le_keys->flags & BT_KEYS_AUTHENTICATED) != 0) &&
1291+
((key->flags & BT_LINK_KEY_AUTHENTICATED) == 0)) {
1292+
LOG_WRN("Stronger LTK (MITM) cannot be overwrote by weaker LK");
12911293
return false;
12921294
}
12931295

0 commit comments

Comments
 (0)