Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp6655649ioo; Thu, 2 Jun 2022 10:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuNb6JeCsYw//dsWuM8YazpHU3ebw9rpd11NiOhzb7IeWtkSo9QQ4QZA/iXcaNr32ptrvy X-Received: by 2002:a17:90a:488c:b0:1c7:b62e:8e8c with SMTP id b12-20020a17090a488c00b001c7b62e8e8cmr41287526pjh.157.1654192485560; Thu, 02 Jun 2022 10:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654192485; cv=none; d=google.com; s=arc-20160816; b=hekmHiCE98WgezQ+i7wGc5WSzrNeXaN8RqbYNqkxAoRaZD2MMOfQA5Q4Jqdfw5JUFJ OBpXGaFUkSRsZCWbc/k5MSwK5tnmWSMN8xfH3LKlkICY4hdRvKkxraSoZZjCpt+9TMll lppsuOIH+GihIlhFlBZxaPSpEJBBaFznyPrQl822nMCok8+10Fhj2sz9flR0UyJKNuQX R+uBb52DKkmP+ualdXsjqGmA3ZcXPGAir+s5fq4qInw89mvaXi7VXtfSs2wUX3rzItTD oKfAp23rjHRko6uVpqu4sWBT7dR2edqkYzhCaW1OhJZxxcC0Esw8YkazPuO2ksojLzYz T5lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=TgjRCVHJNyPNYzKikXPzFw2J/LU8nswSlEqjqarztV8=; b=yhTMNm7lxmMeNVJDYVsL3pvNBD9tyCl98vtzMYxiNA1NnFcBUhushfflneBGotOnVd vMpFTOb/icPBoN9km8UQBixAW7wcLZlOwLkSwivOJbhm+UqeN/5Y1U3bPNwfksDuSfab 8P8yg15jwmriK2dO2CV6Z/QGsSKo6KuxHAR/o8Whyw5wasA8UTPsaNB9aU5/eBL3x9ZY DQdhy7zg1dhWtIVbIkelP2R7JO83O7mthuY1Nwu2MHxRXBW4WCu43cDLfoJRBBed7Xg1 2M3jPHsvTZ9WID99bi/674BAc9Gi+ynTmjww3lt7uUtKKVSC8ypdtEebZafLRigVB2Sg 2hqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PE7MPc6c; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k59-20020a17090a3ec100b001dc28f260d4si6849180pjc.43.2022.06.02.10.54.31; Thu, 02 Jun 2022 10:54:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PE7MPc6c; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235679AbiFBQrB (ORCPT + 99 others); Thu, 2 Jun 2022 12:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237136AbiFBQrA (ORCPT ); Thu, 2 Jun 2022 12:47:00 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF75E013 for ; Thu, 2 Jun 2022 09:46:57 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id c191-20020a621cc8000000b0051bd765ffc5so401722pfc.21 for ; Thu, 02 Jun 2022 09:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=TgjRCVHJNyPNYzKikXPzFw2J/LU8nswSlEqjqarztV8=; b=PE7MPc6cmH5MazFKJTU+COMQ9TpQO8bw53oBPGsv3J0JGY0JiPeVug3nPNJ8fxDUKc balqCApa63MPAan6oUedg99QMOIc+HXYQhUj4Z6rE4a+1yj97Sat3ODWaq57C38NGKts fh0RYdelZCoubs8Fv+tqDmQZYr1wHmUnZXD8FxWCX1nojhI/BqjFyuWbYeLgZ1c/AR7a 2Pg2gPfuIUH4fT2HOVFTNRRpB4nxKpsaCwyVtSqxWjmc2reoRap34iug3g1/1WEVChLz +OkMJIpoyPHEJ9wwD/nCExZBk+Rn233e6atK8AC5OBfC3aBSXLSTa618BcD7g8hD2R7/ FN5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=TgjRCVHJNyPNYzKikXPzFw2J/LU8nswSlEqjqarztV8=; b=Y9heyk/1w6VmQwME0WVQ0MmWnfLOcLwvIbU3Msrd031YNnFuy3sA2+WJeAFr/k6OGk BHecfjzjKNqBaRvnCzKnJSMugpe2wJc1SA9jW2VNP9wHz3c4V1bPRsMOAty3wLKbzHvp y7Ybv7Hexk58Hrkq8Kmv8ThCxaz+uq1R5MDaopolyW34MIL5eScUCvRendB4oZPlSLll gKZa/cQa5uZTAUrAzeUnzSz+w4UC/HlNThL0cMQQfvi6ZrSsWkb0yhLm3aApJZxolwhd oi8fPAgga0LSazCy14z9W7aYVsi9/WwS2zsu/QzUhzpg4lqX1xmuRmmEO7hojXqxKxiK wS/A== X-Gm-Message-State: AOAM531HsabNmQo+IPvPdrTl/c3/Sq0S+/Tw3g1Sa1q+R4CuSecFJATa D9MBgsCCuaY+8GxbhHdulJCASOKaEJqZ8f4IkLDBLNlVWMpLa9B9Mm2buoWWrwla3r42/1LFB2s 5jPgtpHD9gPws/gWYsac0JtiVSOU8Q2OBvZWG/tWbMJREBxriHgHWzaUScPjr8lGTP6l+Ha+ML7 p0R7L1jFfmn6X6BK7L9CM= X-Received: from abps.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:9b4]) (user=abhishekpandit job=sendgmr) by 2002:a62:d40c:0:b0:51b:bc02:703b with SMTP id a12-20020a62d40c000000b0051bbc02703bmr5866640pfh.65.1654188416434; Thu, 02 Jun 2022 09:46:56 -0700 (PDT) Date: Thu, 2 Jun 2022 09:46:49 -0700 Message-Id: <20220602094645.1.I7d191480c15b45a237b927e26aa26ba806409efb@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 1/2] Bluetooth: Fix index added after unregister From: Abhishek Pandit-Subedi To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: Abhishek Pandit-Subedi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Abhishek Pandit-Subedi When a userchannel socket is released, we should check whether the hdev is already unregistered before sending out an IndexAdded. Signed-off-by: Abhishek Pandit-Subedi --- This happened when the firmware crashed or the controller was lost for some other reason. For testing, I emualated this using: echo 0 > $(readlink -f /sys/class/bluetooth/hci0)/../../authorized = Close Index: F8:E4:E3:D9:9E:45 [hci0] 682.178794 @ MGMT Event: Index Removed (0x0005) plen 0 {0x0002} [hci0] 682.178809 @ MGMT Event: Index Removed (0x0005) plen 0 {0x0001} [hci0] 682.178809 = Delete Index: F8:E4:E3:D9:9E:45 [hci0] 682.178821 @ USER Close: bt_stack_manage {0x0003} [hci0] 682.397653 @ MGMT Event: Index Added (0x0004) plen 0 {0x0002} [hci0] 682.397667 @ MGMT Event: Index Added (0x0004) plen 0 {0x0001} [hci0] 682.397667 @ MGMT Close: bt_stack_manage {0x0002} 682.397793 @ MGMT Open: bt_stack_manage (privileged) version 1.14 {0x0003} 682.437223 @ MGMT Command: Read Controller Index List (0x0003) plen 0 {0x0003} 682.437230 @ MGMT Event: Command Complete (0x0001) plen 5 {0x0003} 682.437232 Read Controller Index List (0x0003) plen 2 Status: Success (0x00) Controllers: 0 Tested on ChromeOS kernel and compiled with allmodconfig on bluetooth-next. net/bluetooth/hci_sock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 189e3115c8c6..bd8358b44aa4 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -869,7 +869,8 @@ static int hci_sock_release(struct socket *sock) hdev = hci_pi(sk)->hdev; if (hdev) { - if (hci_pi(sk)->channel == HCI_CHANNEL_USER) { + if (hci_pi(sk)->channel == HCI_CHANNEL_USER && + !hci_dev_test_flag(hdev, HCI_UNREGISTER)) { /* When releasing a user channel exclusive access, * call hci_dev_do_close directly instead of calling * hci_dev_close to ensure the exclusive access will @@ -878,6 +879,11 @@ static int hci_sock_release(struct socket *sock) * The checking of HCI_AUTO_OFF is not needed in this * case since it will have been cleared already when * opening the user channel. + * + * Make sure to also check that we haven't already + * unregistered since all the cleanup will have already + * been complete and hdev will get released when we put + * below. */ hci_dev_do_close(hdev); hci_dev_clear_flag(hdev, HCI_USER_CHANNEL); -- 2.36.1.255.ge46751e96f-goog