diff mbox series

[v2] Bluetooth: Fix auto-creation of hci_conn at Conn Complete event

Message ID 20200814190909.361764-1-sonnysasaka@chromium.org
State New
Headers show
Series [v2] Bluetooth: Fix auto-creation of hci_conn at Conn Complete event | expand

Commit Message

Sonny Sasaka Aug. 14, 2020, 7:09 p.m. UTC
Currently the code auto-creates hci_conn only if the remote address has
been discovered before. This may not be the case. For example, the
remote device may trigger connection after reboot at already-paired
state so there is no inquiry result found, but it is still correct to
create the hci_conn when Connection Complete event is received.

A better guard is to check against bredr allowlist. Devices in the
allowlist have been given permission to auto-connect.

Fixes: 4f40afc6c764 ("Bluetooth: Handle BR/EDR devices during suspend")
Signed-off-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>

---
 net/bluetooth/hci_event.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Sonny Sasaka Sept. 16, 2020, 10:39 p.m. UTC | #1
Dear maintainers,

Friendly ping to review this patch. Thanks!

On Fri, Aug 14, 2020 at 12:09 PM Sonny Sasaka <sonnysasaka@chromium.org> wrote:
>

> Currently the code auto-creates hci_conn only if the remote address has

> been discovered before. This may not be the case. For example, the

> remote device may trigger connection after reboot at already-paired

> state so there is no inquiry result found, but it is still correct to

> create the hci_conn when Connection Complete event is received.

>

> A better guard is to check against bredr allowlist. Devices in the

> allowlist have been given permission to auto-connect.

>

> Fixes: 4f40afc6c764 ("Bluetooth: Handle BR/EDR devices during suspend")

> Signed-off-by: Sonny Sasaka <sonnysasaka@chromium.org>

> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>

>

> ---

>  net/bluetooth/hci_event.c | 17 +++++++++++------

>  1 file changed, 11 insertions(+), 6 deletions(-)

>

> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c

> index 33d8458fdd4a..6b83da1790ee 100644

> --- a/net/bluetooth/hci_event.c

> +++ b/net/bluetooth/hci_event.c

> @@ -2566,7 +2566,6 @@ static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)

>  static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)

>  {

>         struct hci_ev_conn_complete *ev = (void *) skb->data;

> -       struct inquiry_entry *ie;

>         struct hci_conn *conn;

>

>         BT_DBG("%s", hdev->name);

> @@ -2575,13 +2574,19 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)

>

>         conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);

>         if (!conn) {

> -               /* Connection may not exist if auto-connected. Check the inquiry

> -                * cache to see if we've already discovered this bdaddr before.

> -                * If found and link is an ACL type, create a connection class

> +               /* Connection may not exist if auto-connected. Check the bredr

> +                * allowlist to see if this device is allowed to auto connect.

> +                * If link is an ACL type, create a connection class

>                  * automatically.

> +                *

> +                * Auto-connect will only occur if the event filter is

> +                * programmed with a given address. Right now, event filter is

> +                * only used during suspend.

>                  */

> -               ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);

> -               if (ie && ev->link_type == ACL_LINK) {

> +               if (ev->link_type == ACL_LINK &&

> +                   hci_bdaddr_list_lookup_with_flags(&hdev->whitelist,

> +                                                     &ev->bdaddr,

> +                                                     BDADDR_BREDR)) {

>                         conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr,

>                                             HCI_ROLE_SLAVE);

>                         if (!conn) {

> --

> 2.26.2

>
Marcel Holtmann Sept. 20, 2020, 6:22 a.m. UTC | #2
Hi Sonny,

> Currently the code auto-creates hci_conn only if the remote address has

> been discovered before. This may not be the case. For example, the

> remote device may trigger connection after reboot at already-paired

> state so there is no inquiry result found, but it is still correct to

> create the hci_conn when Connection Complete event is received.

> 

> A better guard is to check against bredr allowlist. Devices in the

> allowlist have been given permission to auto-connect.

> 

> Fixes: 4f40afc6c764 ("Bluetooth: Handle BR/EDR devices during suspend")

> Signed-off-by: Sonny Sasaka <sonnysasaka@chromium.org>

> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>

> 

> ---

> net/bluetooth/hci_event.c | 17 +++++++++++------

> 1 file changed, 11 insertions(+), 6 deletions(-)


patch has been applied to bluetooth-next tree.

Regards

Marcel
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 33d8458fdd4a..6b83da1790ee 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2566,7 +2566,6 @@  static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
 static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_conn_complete *ev = (void *) skb->data;
-	struct inquiry_entry *ie;
 	struct hci_conn *conn;
 
 	BT_DBG("%s", hdev->name);
@@ -2575,13 +2574,19 @@  static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 
 	conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
 	if (!conn) {
-		/* Connection may not exist if auto-connected. Check the inquiry
-		 * cache to see if we've already discovered this bdaddr before.
-		 * If found and link is an ACL type, create a connection class
+		/* Connection may not exist if auto-connected. Check the bredr
+		 * allowlist to see if this device is allowed to auto connect.
+		 * If link is an ACL type, create a connection class
 		 * automatically.
+		 *
+		 * Auto-connect will only occur if the event filter is
+		 * programmed with a given address. Right now, event filter is
+		 * only used during suspend.
 		 */
-		ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
-		if (ie && ev->link_type == ACL_LINK) {
+		if (ev->link_type == ACL_LINK &&
+		    hci_bdaddr_list_lookup_with_flags(&hdev->whitelist,
+						      &ev->bdaddr,
+						      BDADDR_BREDR)) {
 			conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr,
 					    HCI_ROLE_SLAVE);
 			if (!conn) {