Skip to content

Commit 8d75e8e

Browse files
fnde-otnashif
authored andcommitted
bluetooth: host: Fix simultaneous pairings getting the same keys slot
Fix an issue where a slot in the key pool was considered free when either the address was cleared or no keys were written in the entry (enc_size == 0). This caused a problem with simultaneous pairing attempts that would be assigned the same entry. This patch makes it so a a slot is considered free even when keys are not yet present in the entry, and makes sure the address is cleared in case of pairing failure or timeout so to mark the slot as free. Signed-off-by: François Delawarde <[email protected]>
1 parent 7498ffb commit 8d75e8e

File tree

1 file changed

+12
-20
lines changed
  • subsys/bluetooth/host

1 file changed

+12
-20
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,18 @@ static void smp_pairing_complete(struct bt_smp *smp, u8_t status)
15791579
bt_auth->pairing_complete(smp->chan.chan.conn,
15801580
bond_flag);
15811581
}
1582-
} else if (bt_auth && bt_auth->pairing_failed) {
1583-
bt_auth->pairing_failed(smp->chan.chan.conn);
1582+
} else {
1583+
/*
1584+
* Clear the key pool entry in case of pairing failure.
1585+
*/
1586+
if (smp->chan.chan.conn->le.keys) {
1587+
bt_keys_clear(smp->chan.chan.conn->le.keys);
1588+
smp->chan.chan.conn->le.keys = NULL;
1589+
}
1590+
1591+
if (bt_auth && bt_auth->pairing_failed) {
1592+
bt_auth->pairing_failed(smp->chan.chan.conn);
1593+
}
15841594
}
15851595

15861596
smp_reset(smp);
@@ -1592,15 +1602,6 @@ static void smp_timeout(struct k_work *work)
15921602

15931603
BT_ERR("SMP Timeout");
15941604

1595-
/*
1596-
* If SMP timeout occurred during key distribution we should assume
1597-
* pairing failed and don't store any keys from this pairing.
1598-
*/
1599-
if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR) &&
1600-
smp->chan.chan.conn->le.keys) {
1601-
bt_keys_clear(smp->chan.chan.conn->le.keys);
1602-
}
1603-
16041605
smp_pairing_complete(smp, BT_SMP_ERR_UNSPECIFIED);
16051606

16061607
atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT);
@@ -3092,15 +3093,6 @@ static u8_t smp_pairing_failed(struct bt_smp *smp, struct net_buf *buf)
30923093
}
30933094
}
30943095

3095-
/*
3096-
* Pairing Failed command may be sent at any time during the pairing,
3097-
* so if there are any keys distributed, shall be cleared.
3098-
*/
3099-
if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR) &&
3100-
smp->chan.chan.conn->le.keys) {
3101-
bt_keys_clear(smp->chan.chan.conn->le.keys);
3102-
}
3103-
31043096
smp_pairing_complete(smp, req->reason);
31053097

31063098
/* return no error to avoid sending Pairing Failed in response */

0 commit comments

Comments
 (0)