Skip to content

Commit b541260

Browse files
committed
Bluetooth: hci_event: Fix using memcmp when comparing keys
memcmp is not consider safe to use with cryptographic secrets: 'Do not use memcmp() to compare security critical data, such as cryptographic secrets, because the required CPU time depends on the number of equal bytes.' While usage of memcmp for ZERO_KEY may not be considered a security critical data, it can lead to more usage of memcmp with pairing keys which could introduce more security problems. Fixes: 455c2ff ("Bluetooth: Fix BR/EDR out-of-band pairing with only initiator data") Fixes: 33155c4 ("Bluetooth: hci_event: Ignore NULL link key") Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent c7f5946 commit b541260

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

net/bluetooth/hci_event.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/* Bluetooth HCI event handling. */
2727

2828
#include <asm/unaligned.h>
29+
#include <linux/crypto.h>
30+
#include <crypto/algapi.h>
2931

3032
#include <net/bluetooth/bluetooth.h>
3133
#include <net/bluetooth/hci_core.h>
@@ -4754,7 +4756,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data,
47544756
goto unlock;
47554757

47564758
/* Ignore NULL link key against CVE-2020-26555 */
4757-
if (!memcmp(ev->link_key, ZERO_KEY, HCI_LINK_KEY_SIZE)) {
4759+
if (!crypto_memneq(ev->link_key, ZERO_KEY, HCI_LINK_KEY_SIZE)) {
47584760
bt_dev_dbg(hdev, "Ignore NULL link key (ZERO KEY) for %pMR",
47594761
&ev->bdaddr);
47604762
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
@@ -5294,8 +5296,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn)
52945296
* available, then do not declare that OOB data is
52955297
* present.
52965298
*/
5297-
if (!memcmp(data->rand256, ZERO_KEY, 16) ||
5298-
!memcmp(data->hash256, ZERO_KEY, 16))
5299+
if (!crypto_memneq(data->rand256, ZERO_KEY, 16) ||
5300+
!crypto_memneq(data->hash256, ZERO_KEY, 16))
52995301
return 0x00;
53005302

53015303
return 0x02;
@@ -5305,8 +5307,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn)
53055307
* not supported by the hardware, then check that if
53065308
* P-192 data values are present.
53075309
*/
5308-
if (!memcmp(data->rand192, ZERO_KEY, 16) ||
5309-
!memcmp(data->hash192, ZERO_KEY, 16))
5310+
if (!crypto_memneq(data->rand192, ZERO_KEY, 16) ||
5311+
!crypto_memneq(data->hash192, ZERO_KEY, 16))
53105312
return 0x00;
53115313

53125314
return 0x01;

0 commit comments

Comments
 (0)