Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp620858pxa; Fri, 14 Aug 2020 13:07:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIkOI0gAVYZj3jg3ci+5A8883rq04eg6rDHS1s0ICYXCxUwVWT9orukF7DAw6mFvZjnQvm X-Received: by 2002:a17:906:a219:: with SMTP id r25mr4104214ejy.201.1597435659187; Fri, 14 Aug 2020 13:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597435659; cv=none; d=google.com; s=arc-20160816; b=ejPUiQ8CFHYLlmAjTDMjIG820khFwUlVOGbe4SbHVIt97BVCkSu5sLSGW1AXncr4PT knZQu9zXW31pjKGZMV4FPuKK39p5nm5VHZz0I4oLPFNnwIKPk4ogRl4TaDsYzSmV7FCv ZX3f2ouwIas5Fd17BYj+d/utUtxOPG/Du5Ru06tvmiSnOq5cqIbrSnEWsw1oBFHJYcT3 aHiVBNbslE0S8jhVA8DRgPx5WVJmXhWlvdPv5wYxUDzoTHxE5V4qpgcS7XZxt/Ue8JQw yA88Is+qGKPKyKtxSgtaYOyw24CMPjcj6jVU6wc7Y2gopMjhJQrEbaV4MAZJ3H7CBznB OnAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Sym/AmXhI2hFDD6PNhYTvYIW04BDHmyuqhnUhFDB198=; b=Q0gw0npBV9De1I5kdJJ/pnHZVbyQ9gt1oCoWaF+ggTv1oWkgsJOM9u1iuCJQlqbLt8 Owf4y4Oui0hFAsm1VCHT0U82YRL3Vckn2/XHEjjn8EH/NywxRSZmBbl34bB1IOd2ThN4 apJEf9OoLYVX9SEHiqAB0p/MNZ7K8uNX1HjCOpYQ0Wcq+pgM9tkIiZKpVZIOVBehdhgX sZfvsVEI7WTCoWJVWA6JPQ80o+IurOBgrlYwYIP/tIWz029ySWoDk9nfmg67Ef02iQgy C83pGKDSGZbQLfXMUouWztSH6IvdslAKnI7HhDfEd/ZqtLOpihPaQACraC120k5MBa+K O6lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=In8sZKHd; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si6195096ejx.56.2020.08.14.13.07.15; Fri, 14 Aug 2020 13:07:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=In8sZKHd; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbgHNTEP (ORCPT + 99 others); Fri, 14 Aug 2020 15:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbgHNTEO (ORCPT ); Fri, 14 Aug 2020 15:04:14 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23718C061385 for ; Fri, 14 Aug 2020 12:04:14 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id i92so5967847pje.0 for ; Fri, 14 Aug 2020 12:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Sym/AmXhI2hFDD6PNhYTvYIW04BDHmyuqhnUhFDB198=; b=In8sZKHdSEbhLPcwRUfe7iXD7g6GuOB752EKkJMSV9iP16ltG3sgfA9O+Yaof7JYU0 yIsj305aKFhCEDRAxvT62nvMk3XlW7dr13kW4pGUOmCWjUs1JoeEDpbefG5xA4XNpmlF 97ez5sKMlF9hA/7UR2rKBmR+zGpcmRmkXBiz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Sym/AmXhI2hFDD6PNhYTvYIW04BDHmyuqhnUhFDB198=; b=Bzj9Yp6s7EzhKR2tahTb9MOv7++18UlcQQxj8TaT4PO+opwhmGvyfhqxTND6at3g7y t5TvNYVgQ5xhojqZXy/kzRXTytBE0oLceXDUk0slEwYsTAOnTPP/lv2L5TRFuSut+WEL vfrLYi7ZrhQXB6aCdwNWnGXtMmwzNeOgJYbftIcQb9xRCzE+AFnD63XZv9XlDtI23o4c XZ1fWvvYoo69cevjWNJHWse8eXHt0T1QWuS43pIdoWzZ+Hh4zsT0TZDn7UIY+tGkk/yj ay/d8Gqprm4BjJXPE7ZjyRJwSkiafnoxg7reS2XjZpVgNHelPUdFjFwktufRHDtBkxxU mioQ== X-Gm-Message-State: AOAM531LRqF2EQojYkBC/i3lHFwOqWBmpc7uqQYpJDTnKu6RXUdPYlO8 /gXgtbes47GOSvHoOuPjQ4tG9FJa4RKggw== X-Received: by 2002:a17:90a:216a:: with SMTP id a97mr3353255pje.144.1597431853192; Fri, 14 Aug 2020 12:04:13 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id z2sm10125840pfq.46.2020.08.14.12.04.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Aug 2020 12:04:12 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH] Bluetooth: Fix auto-creation of hci_conn at Conn Complete event Date: Fri, 14 Aug 2020 12:04:06 -0700 Message-Id: <20200814190406.361415-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 --- 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