From nobody Tue Apr 28 09:08:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B17CCA478 for ; Thu, 2 Jun 2022 15:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236434AbiFBPaK (ORCPT ); Thu, 2 Jun 2022 11:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234580AbiFBPaI (ORCPT ); Thu, 2 Jun 2022 11:30:08 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A23113C1FA for ; Thu, 2 Jun 2022 08:30:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id j11-20020a05690212cb00b006454988d225so4385376ybu.10 for ; Thu, 02 Jun 2022 08:30:07 -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=2nAGCZ2HRmIXfv8rT8uSoEGsDABE/p5lJinXX/zQGnA=; b=IfIrft4dh0L+HPBnonus5+t8id1FCITlCEYwqDadPZIb9negqKU7CN3IGx3i8hTnhR kB6ouvKEZZZP0zF0B8cw1UOa/f8y3XVDhpPK7cRzGLWUcglbKxAbMtNc0hniyy5/hL7F Osuhj77CqUU9jyA7mlllRNA736rv4LPVJjfzC0DsNurQR5dVgRYPdP8tdusDwF0hE3ZR qyCRo4MI1G6T2kSnla0yA76He3F+Fquw4jlhF3DudC+aK0Md+LME2aC1Bi/fTYB2sq+0 HQb17wBXpRy+YvXh3tfiB/Nk1Ba3q4rmQZEtl92xvisIC2C60EziP4l54dD3Um39VU9G pPSA== 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=2nAGCZ2HRmIXfv8rT8uSoEGsDABE/p5lJinXX/zQGnA=; b=YU1r2K3RWTJGInIwPJh5QOw6GrHhAST8hc/dlnSDv9ZwAWNJDCYYx2DRxkF8y20b5x ZzlgDJ8hN/lofYOsX915PZXGNaVVlILh6HE7ZPC2mxNfSa57DWjLNdMsZ1hwIyZ9eJI7 dH9VYuZiUB2UjllfU0eInwxCC0lQHnMCN/FvtZs0yvegixd8HWiDpIX1rpJBuyuV9a2D qCpLG5QW3rllBJ0IoOhGqkKnWx6yd2NDiyoJp6Y/8ehJ3bm/g4S8G8mGar5fJZ4prkXi AHzLB9/kKBILS5RmoKYFZWI0J4NBwswZGGruOo+sdmoLn3neoRygoTUEgr/AHXd+Py7m KL5A== X-Gm-Message-State: AOAM53081swkElOndKb4ojfA2HY11j1Q2cN81XW7SM+AxJMZUE7es3Iw ct7WTLbJZd5qPw/bPtNnVbLa4ax3uoKFRswriEM= X-Google-Smtp-Source: ABdhPJx9WENoVblAMpg4ET+k1EH0awq1ra4yhT0qlJy920LyMKD8OOajT85XeuhNvx8xInBSN3eh9VZql+trNKSgB1w= X-Received: from alainmic.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2890]) (user=alainmichaud job=sendgmr) by 2002:a25:2c4c:0:b0:65d:3767:2ef2 with SMTP id s73-20020a252c4c000000b0065d37672ef2mr5957046ybs.570.1654183806234; Thu, 02 Jun 2022 08:30:06 -0700 (PDT) Date: Thu, 2 Jun 2022 15:30:03 +0000 Message-Id: <20220602152952.v3.1.I9f2f4ef058af96a5ad610a90c6938ed17a7d103f@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v3] Bluetooth: clear the temporary linkkey in hci_conn_cleanup From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, Alain Michaud , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Luiz Augusto von Dentz , Marcel Holtmann , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alain Michaud If a hardware error occurs and the connections are flushed without a disconnection_complete event being signaled, the temporary linkkeys are not flushed. This change ensures that any outstanding flushable linkkeys are flushed when the connection are flushed from the hash table. Additionally, this also makes use of test_and_clear_bit to avoid multiple attempts to delete the link key that's already been flushed. Signed-off-by: Alain Michaud --- Changes in v3: -Adding test_and_clear_bit to the commit description based on Marcel's feedback Changes in v2: -Address Feedback from Luiz net/bluetooth/hci_conn.c | 3 +++ net/bluetooth/hci_event.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 352d7d612128..5911ca0c5239 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -118,6 +118,9 @@ static void hci_conn_cleanup(struct hci_conn *conn) if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags)) hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type); =20 + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + hci_remove_link_key(hdev, &conn->dst); + hci_chan_list_flush(conn); =20 hci_conn_hash_del(hdev, conn); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 6b83f9b0082c..b67fdd1ad8da 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2729,7 +2729,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u= 8 status) mgmt_conn =3D test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); =20 if (conn->type =3D=3D ACL_LINK) { - if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) hci_remove_link_key(hdev, &conn->dst); } =20 @@ -3372,7 +3372,7 @@ static void hci_disconn_complete_evt(struct hci_dev *= hdev, void *data, reason, mgmt_connected); =20 if (conn->type =3D=3D ACL_LINK) { - if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) hci_remove_link_key(hdev, &conn->dst); =20 hci_req_update_scan(hdev); --=20 2.36.1.255.ge46751e96f-goog