Skip to content

Commit

Permalink
Bluetooth: use hdev lock for accept_list and reject_list in conn req
Browse files Browse the repository at this point in the history
[ Upstream commit fb048ca ]

All accesses (both reads and modifications) to
hdev->{accept,reject}_list are protected by hdev lock,
except the ones in hci_conn_request_evt. This can cause a race
condition in the form of a list corruption.
The solution is to protect these lists in hci_conn_request_evt as well.

I was unable to find the exact commit that introduced the issue for the
reject list, I was only able to find it for the accept list.

Fixes: a55bd29 ("Bluetooth: Add white list lookup for incoming connection requests")
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
nielsdos authored and gregkh committed Jun 9, 2022
1 parent 6baa8c0 commit e534e5c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions net/bluetooth/hci_event.c
Expand Up @@ -3224,10 +3224,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
return;
}

hci_dev_lock(hdev);

if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr,
BDADDR_BREDR)) {
hci_reject_conn(hdev, &ev->bdaddr);
return;
goto unlock;
}

/* Require HCI_CONNECTABLE or an accept list entry to accept the
Expand All @@ -3239,13 +3241,11 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
!hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr,
BDADDR_BREDR)) {
hci_reject_conn(hdev, &ev->bdaddr);
return;
goto unlock;
}

/* Connection accepted */

hci_dev_lock(hdev);

ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
if (ie)
memcpy(ie->data.dev_class, ev->dev_class, 3);
Expand All @@ -3257,8 +3257,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
HCI_ROLE_SLAVE);
if (!conn) {
bt_dev_err(hdev, "no memory for new connection");
hci_dev_unlock(hdev);
return;
goto unlock;
}
}

Expand Down Expand Up @@ -3298,6 +3297,10 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
conn->state = BT_CONNECT2;
hci_connect_cfm(conn, 0);
}

return;
unlock:
hci_dev_unlock(hdev);
}

static u8 hci_to_mgmt_reason(u8 err)
Expand Down

0 comments on commit e534e5c

Please sign in to comment.