Skip to content

Commit fb048ca

Browse files
nielsdosholtmann
authored andcommitted
Bluetooth: use hdev lock for accept_list and reject_list in conn req
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 <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 50a3633 commit fb048ca

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

net/bluetooth/hci_event.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,10 +3225,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32253225
return;
32263226
}
32273227

3228+
hci_dev_lock(hdev);
3229+
32283230
if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr,
32293231
BDADDR_BREDR)) {
32303232
hci_reject_conn(hdev, &ev->bdaddr);
3231-
return;
3233+
goto unlock;
32323234
}
32333235

32343236
/* Require HCI_CONNECTABLE or an accept list entry to accept the
@@ -3240,13 +3242,11 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32403242
!hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr,
32413243
BDADDR_BREDR)) {
32423244
hci_reject_conn(hdev, &ev->bdaddr);
3243-
return;
3245+
goto unlock;
32443246
}
32453247

32463248
/* Connection accepted */
32473249

3248-
hci_dev_lock(hdev);
3249-
32503250
ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
32513251
if (ie)
32523252
memcpy(ie->data.dev_class, ev->dev_class, 3);
@@ -3258,8 +3258,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32583258
HCI_ROLE_SLAVE);
32593259
if (!conn) {
32603260
bt_dev_err(hdev, "no memory for new connection");
3261-
hci_dev_unlock(hdev);
3262-
return;
3261+
goto unlock;
32633262
}
32643263
}
32653264

@@ -3299,6 +3298,10 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32993298
conn->state = BT_CONNECT2;
33003299
hci_connect_cfm(conn, 0);
33013300
}
3301+
3302+
return;
3303+
unlock:
3304+
hci_dev_unlock(hdev);
33023305
}
33033306

33043307
static u8 hci_to_mgmt_reason(u8 err)

0 commit comments

Comments
 (0)