@@ -3048,8 +3048,18 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
30483048
30493049	hci_dev_lock (hdev );
30503050
3051+ 	/* Check for existing connection: 
3052+ 	 * 
3053+ 	 * 1. If it doesn't exist then it must be receiver/slave role. 
3054+ 	 * 2. If it does exist confirm that it is connecting/BT_CONNECT in case 
3055+ 	 *    of initiator/master role since there could be a collision where 
3056+ 	 *    either side is attempting to connect or something like a fuzzing 
3057+ 	 *    testing is trying to play tricks to destroy the hcon object before 
3058+ 	 *    it even attempts to connect (e.g. hcon->state == BT_OPEN). 
3059+ 	 */ 
30513060	conn  =  hci_conn_hash_lookup_ba (hdev , ev -> link_type , & ev -> bdaddr );
3052- 	if  (!conn ) {
3061+ 	if  (!conn  || 
3062+ 	    (conn -> role  ==  HCI_ROLE_MASTER  &&  conn -> state  !=  BT_CONNECT )) {
30533063		/* In case of error status and there is no connection pending 
30543064		 * just unlock as there is nothing to cleanup. 
30553065		 */ 
@@ -5615,8 +5625,18 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
56155625	 */ 
56165626	hci_dev_clear_flag (hdev , HCI_LE_ADV );
56175627
5618- 	conn  =  hci_conn_hash_lookup_ba (hdev , LE_LINK , bdaddr );
5619- 	if  (!conn ) {
5628+ 	/* Check for existing connection: 
5629+ 	 * 
5630+ 	 * 1. If it doesn't exist then use the role to create a new object. 
5631+ 	 * 2. If it does exist confirm that it is connecting/BT_CONNECT in case 
5632+ 	 *    of initiator/master role since there could be a collision where 
5633+ 	 *    either side is attempting to connect or something like a fuzzing 
5634+ 	 *    testing is trying to play tricks to destroy the hcon object before 
5635+ 	 *    it even attempts to connect (e.g. hcon->state == BT_OPEN). 
5636+ 	 */ 
5637+ 	conn  =  hci_conn_hash_lookup_role (hdev , LE_LINK , role , bdaddr );
5638+ 	if  (!conn  || 
5639+ 	    (conn -> role  ==  HCI_ROLE_MASTER  &&  conn -> state  !=  BT_CONNECT )) {
56205640		/* In case of error status and there is no connection pending 
56215641		 * just unlock as there is nothing to cleanup. 
56225642		 */ 
0 commit comments