Skip to content

Commit

Permalink
Bluetooth: smp: Fix biased random passkey generation
Browse files Browse the repository at this point in the history
Since u32 range size is not a multiple of 1,000,000, current passkey generation logic is biased.

Fixed this by adding a routine that selects passkey again if passkey is 4,200,000,000 or more.

Signed-off-by: Mincheol Son <encrypted.def@gmail.com>
  • Loading branch information
encrypted-def authored and intel-lab-lkp committed Dec 7, 2020
1 parent 02be5f1 commit 80c9c18
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/bluetooth/smp.c
Expand Up @@ -922,7 +922,9 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
/* Generate random passkey. */
if (smp->method == CFM_PASSKEY) {
memset(smp->tk, 0, sizeof(smp->tk));
get_random_bytes(&passkey, sizeof(passkey));
do {
get_random_bytes(&passkey, sizeof(passkey));
} while (passkey >= (u32)4200000000);
passkey %= 1000000;
put_unaligned_le32(passkey, smp->tk);
BT_DBG("PassKey: %d", passkey);
Expand Down

0 comments on commit 80c9c18

Please sign in to comment.