You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Bluetooth: Fix differentiating stored master vs slave LTK types
If LTK distribution happens in both directions we will have two LTKs for the same remote device: one which is used when we're connecting as master and another when we're connecting as slave. When looking up LTKs from the locally stored list we shouldn't blindly return the first match but also consider which type of key is in question. If we do not do this we may end up selecting an incorrect encryption key for a connection. This patch fixes the issue by always specifying to the LTK lookup functions whether we're looking for a master or a slave key. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
This commit is contained in:
@@ -2605,7 +2605,16 @@ static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
|
||||
return false;
|
||||
}
|
||||
|
||||
struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
|
||||
static bool ltk_type_master(u8 type)
|
||||
{
|
||||
if (type == HCI_SMP_STK || type == HCI_SMP_LTK)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8],
|
||||
bool master)
|
||||
{
|
||||
struct smp_ltk *k;
|
||||
|
||||
@@ -2614,6 +2623,9 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
|
||||
memcmp(rand, k->rand, sizeof(k->rand)))
|
||||
continue;
|
||||
|
||||
if (ltk_type_master(k->type) != master)
|
||||
continue;
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
@@ -2621,13 +2633,14 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
|
||||
}
|
||||
|
||||
struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
|
||||
u8 addr_type)
|
||||
u8 addr_type, bool master)
|
||||
{
|
||||
struct smp_ltk *k;
|
||||
|
||||
list_for_each_entry(k, &hdev->long_term_keys, list)
|
||||
if (addr_type == k->bdaddr_type &&
|
||||
bacmp(bdaddr, &k->bdaddr) == 0)
|
||||
bacmp(bdaddr, &k->bdaddr) == 0 &&
|
||||
ltk_type_master(k->type) == master)
|
||||
return k;
|
||||
|
||||
return NULL;
|
||||
@@ -2691,8 +2704,9 @@ int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
|
||||
ediv, u8 rand[8])
|
||||
{
|
||||
struct smp_ltk *key, *old_key;
|
||||
bool master = ltk_type_master(type);
|
||||
|
||||
old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type);
|
||||
old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type, master);
|
||||
if (old_key)
|
||||
key = old_key;
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user