Skip to content

Commit c5d2b6f

Browse files
committed
Bluetooth: Fix use-after-free in hci_remove_ltk/hci_remove_irk
Similar to commit 0f7d9b3 ("netfilter: nf_tables: fix use-after-free in nft_set_catchall_destroy()"). We can not access k after kfree_rcu() call. Cc: stable@vger.kernel.org Signed-off-by: Min Li <lm0963hack@gmail.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent e6a7a46 commit c5d2b6f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/bluetooth/hci_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,10 @@ int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
14161416

14171417
int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type)
14181418
{
1419-
struct smp_ltk *k;
1419+
struct smp_ltk *k, *tmp;
14201420
int removed = 0;
14211421

1422-
list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
1422+
list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) {
14231423
if (bacmp(bdaddr, &k->bdaddr) || k->bdaddr_type != bdaddr_type)
14241424
continue;
14251425

@@ -1435,9 +1435,9 @@ int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type)
14351435

14361436
void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
14371437
{
1438-
struct smp_irk *k;
1438+
struct smp_irk *k, *tmp;
14391439

1440-
list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) {
1440+
list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) {
14411441
if (bacmp(bdaddr, &k->bdaddr) || k->addr_type != addr_type)
14421442
continue;
14431443

0 commit comments

Comments
 (0)