@@ -3050,8 +3050,18 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
30503050
30513051	hci_dev_lock (hdev );
30523052
3053+ 	/* Check for existing connection: 
3054+ 	 * 
3055+ 	 * 1. If it doesn't exist then it must be receiver/slave role. 
3056+ 	 * 2. If it does exist confirm that it is connecting/BT_CONNECT in case 
3057+ 	 *    of initiator/master role since there could be a collision where 
3058+ 	 *    either side is attempting to connect or something like a fuzzing 
3059+ 	 *    testing is trying to play tricks to destroy the hcon object before 
3060+ 	 *    it even attempts to connect (e.g. hcon->state == BT_OPEN). 
3061+ 	 */ 
30533062	conn  =  hci_conn_hash_lookup_ba (hdev , ev -> link_type , & ev -> bdaddr );
3054- 	if  (!conn ) {
3063+ 	if  (!conn  || 
3064+ 	    (conn -> role  ==  HCI_ROLE_MASTER  &&  conn -> state  !=  BT_CONNECT )) {
30553065		/* In case of error status and there is no connection pending 
30563066		 * just unlock as there is nothing to cleanup. 
30573067		 */ 
@@ -5618,8 +5628,18 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
56185628	 */ 
56195629	hci_dev_clear_flag (hdev , HCI_LE_ADV );
56205630
5621- 	conn  =  hci_conn_hash_lookup_ba (hdev , LE_LINK , bdaddr );
5622- 	if  (!conn ) {
5631+ 	/* Check for existing connection: 
5632+ 	 * 
5633+ 	 * 1. If it doesn't exist then use the role to create a new object. 
5634+ 	 * 2. If it does exist confirm that it is connecting/BT_CONNECT in case 
5635+ 	 *    of initiator/master role since there could be a collision where 
5636+ 	 *    either side is attempting to connect or something like a fuzzing 
5637+ 	 *    testing is trying to play tricks to destroy the hcon object before 
5638+ 	 *    it even attempts to connect (e.g. hcon->state == BT_OPEN). 
5639+ 	 */ 
5640+ 	conn  =  hci_conn_hash_lookup_role (hdev , LE_LINK , role , bdaddr );
5641+ 	if  (!conn  || 
5642+ 	    (conn -> role  ==  HCI_ROLE_MASTER  &&  conn -> state  !=  BT_CONNECT )) {
56235643		/* In case of error status and there is no connection pending 
56245644		 * just unlock as there is nothing to cleanup. 
56255645		 */ 
0 commit comments