Skip to content

Commit 1fc62c5

Browse files
Johan Hedbergholtmann
authored andcommitted
Bluetooth: Fix exposing full value of shortened LTKs
When we notify user space of a new LTK or distribute an LTK to the remote peer the value passed should be the shortened version so that it's easy to compare values in various traces. The core spec also sets the requirements for the shortening/masking as: "The masking shall be done after generation and before being distributed, used or stored." Signed-off-by: Johan Hedberg <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 61b2fc2 commit 1fc62c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

net/bluetooth/mgmt.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7603,7 +7603,12 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
76037603
if (key->type == SMP_LTK)
76047604
ev.key.master = 1;
76057605

7606-
memcpy(ev.key.val, key->val, sizeof(key->val));
7606+
/* Make sure we copy only the significant bytes based on the
7607+
* encryption key size, and set the rest of the value to zeroes.
7608+
*/
7609+
memcpy(ev.key.val, key->val, sizeof(key->enc_size));
7610+
memset(ev.key.val + key->enc_size, 0,
7611+
sizeof(ev.key.val) - key->enc_size);
76077612

76087613
mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL);
76097614
}

net/bluetooth/smp.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,14 @@ static void smp_distribute_keys(struct smp_chan *smp)
12711271
__le16 ediv;
12721272
__le64 rand;
12731273

1274-
get_random_bytes(enc.ltk, sizeof(enc.ltk));
1274+
/* Make sure we generate only the significant amount of
1275+
* bytes based on the encryption key size, and set the rest
1276+
* of the value to zeroes.
1277+
*/
1278+
get_random_bytes(enc.ltk, smp->enc_key_size);
1279+
memset(enc.ltk + smp->enc_key_size, 0,
1280+
sizeof(enc.ltk) - smp->enc_key_size);
1281+
12751282
get_random_bytes(&ediv, sizeof(ediv));
12761283
get_random_bytes(&rand, sizeof(rand));
12771284

0 commit comments

Comments
 (0)