@@ -3087,8 +3087,18 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
30873087
30883088 hci_dev_lock (hdev );
30893089
3090+ /* Check for existing connection:
3091+ *
3092+ * 1. If it doesn't exist then it must be receiver/slave role.
3093+ * 2. If it does exist confirm that it is connecting/BT_CONNECT in case
3094+ * of initiator/master role since there could be a collision where
3095+ * either side is attempting to connect or something like a fuzzing
3096+ * testing is trying to play tricks to destroy the hcon object before
3097+ * it even attempts to connect (e.g. hcon->state == BT_OPEN).
3098+ */
30903099 conn = hci_conn_hash_lookup_ba (hdev , ev -> link_type , & ev -> bdaddr );
3091- if (!conn ) {
3100+ if (!conn ||
3101+ (conn -> role == HCI_ROLE_MASTER && conn -> state != BT_CONNECT )) {
30923102 /* In case of error status and there is no connection pending
30933103 * just unlock as there is nothing to cleanup.
30943104 */
@@ -5638,8 +5648,18 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
56385648 */
56395649 hci_dev_clear_flag (hdev , HCI_LE_ADV );
56405650
5641- conn = hci_conn_hash_lookup_ba (hdev , LE_LINK , bdaddr );
5642- if (!conn ) {
5651+ /* Check for existing connection:
5652+ *
5653+ * 1. If it doesn't exist then use the role to create a new object.
5654+ * 2. If it does exist confirm that it is connecting/BT_CONNECT in case
5655+ * of initiator/master role since there could be a collision where
5656+ * either side is attempting to connect or something like a fuzzing
5657+ * testing is trying to play tricks to destroy the hcon object before
5658+ * it even attempts to connect (e.g. hcon->state == BT_OPEN).
5659+ */
5660+ conn = hci_conn_hash_lookup_role (hdev , LE_LINK , role , bdaddr );
5661+ if (!conn ||
5662+ (conn -> role == HCI_ROLE_MASTER && conn -> state != BT_CONNECT )) {
56435663 /* In case of error status and there is no connection pending
56445664 * just unlock as there is nothing to cleanup.
56455665 */
0 commit comments