From patchwork Tue May 19 20:25:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11558731 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7576C618 for ; Tue, 19 May 2020 20:25:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DCA3206BE for ; Tue, 19 May 2020 20:25:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lPjmSbDS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbgESUZW (ORCPT ); Tue, 19 May 2020 16:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgESUZW (ORCPT ); Tue, 19 May 2020 16:25:22 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58767C08C5C0 for ; Tue, 19 May 2020 13:25:22 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id f15so359992plr.3 for ; Tue, 19 May 2020 13:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=PlpimUzdploR0syL9l8/YlsWxzaH6bbKnKDninRyKo8=; b=lPjmSbDS2xboM3Po4TkB2itCUlVdWT2DePlXwbqdllU5XAuiiUzjL4P5oe3JX6ttLf xxYBLiP72GTG6MwRaj9sqerhgk28rVMvUfyuK3Dkiinzt0s/hnDBNlXHghNp2SFprTNv 2CXtVrv6ItxAYYl0c0RrCxzVSYTef0Hz9Nqex2LVgscyF52M9S7jenKBHcg119ayEFzW 3tdlCsERhHOHcvHqNnB7/FhiGl4FTtkrVKlEfxqxuw3JEspfI/XALkqRMrXw77FhO0pL 89alWlxJ69DOx0L111iGldKzKuSBQxm+ob0uYmKRg5bnw2nPAO6Jm+rUwXOLFlur0tSW BMjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=PlpimUzdploR0syL9l8/YlsWxzaH6bbKnKDninRyKo8=; b=SRYxjZHow5AlIPgHwXE5e+SvLYdpVt3iDebmrQhn+bHBnfqALMT84eoSyMJ3BvviAc l71aa0xZeshprE+y2F7MtZLXtPv5CqtcJf332QN4tuyiAxF0LodCjnvIBmTb6Se2WNzD I60HUMCGiMYcsY8qzb0Nuyqm8rkwlWC6CLfVyb1YRp72iWt4qVJ8ijg7YgJfFXzeW62R sTNyxQ8gSQwswUI78o03mBNyIbbCnstVsgY6Xx17auZzlMlYM2DQUw35G96G+7pHK+Jh JIJrflGB7Wsu4ZQbpVqV7vWjH//PzXSyNLEi4yxgMefwdedIAM167f53iP5ubM3zZ48P Rjxg== X-Gm-Message-State: AOAM532io5tjDDw6JKl/xI/9GWrjuwi6jUW4Ol8OVv/SgVJ32rvIonx5 w6dSPb+3ZBsLJ5ryhgL/dUAEme+6 X-Google-Smtp-Source: ABdhPJwpxeFYSso5iXkEPAuN4UdFdHfEulLYdjGRvTqGASiSFF6Yy5QD5G1/OeyN2NWtZZKIlpW9MA== X-Received: by 2002:a17:902:bb96:: with SMTP id m22mr1232413pls.222.1589919921259; Tue, 19 May 2020 13:25:21 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id c184sm298808pfc.57.2020.05.19.13.25.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 13:25:20 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/4] Bluetooth: Disconnect if E0 is used for Level 4 Date: Tue, 19 May 2020 13:25:16 -0700 Message-Id: <20200519202519.219335-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz E0 is not allowed with Level 4: BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C page 1319: '128-bit equivalent strength for link and encryption keys required using FIPS approved algorithms (E0 not allowed, SAFER+ not allowed, and P-192 not allowed; encryption key not shortened' SC enabled: > HCI Event: Read Remote Extended Features (0x23) plen 13 Status: Success (0x00) Handle: 256 Page: 1/2 Features: 0x0b 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Secure Simple Pairing (Host Support) LE Supported (Host) Secure Connections (Host Support) > HCI Event: Encryption Change (0x08) plen 4 Status: Success (0x00) Handle: 256 Encryption: Enabled with AES-CCM (0x02) SC disabled: > HCI Event: Read Remote Extended Features (0x23) plen 13 Status: Success (0x00) Handle: 256 Page: 1/2 Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Secure Simple Pairing (Host Support) LE Supported (Host) > HCI Event: Encryption Change (0x08) plen 4 Status: Success (0x00) Handle: 256 Encryption: Enabled with E0 (0x01) [May 8 20:23] Bluetooth: hci0: Invalid security: expect AES but E0 was used < HCI Command: Disconnect (0x01|0x0006) plen 3 Handle: 256 Reason: Authentication Failure (0x05) Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 17 +++++++++++++++++ net/bluetooth/hci_event.c | 6 ++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 07c34c55fc50..0c1cae83c8dc 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1325,6 +1325,23 @@ int hci_conn_check_link_mode(struct hci_conn *conn) return 0; } + /* AES encryption is required for Level 4: + * + * BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C + * page 1319: + * + * 128-bit equivalent strength for link and encryption keys + * required using FIPS approved algorithms (E0 not allowed, + * SAFER+ not allowed, and P-192 not allowed; encryption key + * not shortened) + */ + if (conn->sec_level == BT_SECURITY_FIPS && + !test_bit(HCI_CONN_AES_CCM, &conn->flags)) { + bt_dev_err(conn->hdev, "Invalid security: expect AES but E0 " + "was used"); + return 0; + } + if (hci_conn_ssp_enabled(conn) && !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) return 0; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 006c24e04b44..dc1cc3c4348c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3078,10 +3078,8 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) * that are not encrypted with AES-CCM using a P-256 authenticated * combination key. */ - if (hci_dev_test_flag(hdev, HCI_SC_ONLY) && - (!test_bit(HCI_CONN_AES_CCM, &conn->flags) || - conn->key_type != HCI_LK_AUTH_COMBINATION_P256)) { - hci_connect_cfm(conn, HCI_ERROR_AUTH_FAILURE); + if (!hci_conn_check_link_mode(conn)) { + hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_conn_drop(conn); goto unlock; } From patchwork Tue May 19 20:25:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11558733 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92C03618 for ; Tue, 19 May 2020 20:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AC63206BE for ; Tue, 19 May 2020 20:25:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XG8G5EFX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbgESUZY (ORCPT ); Tue, 19 May 2020 16:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgESUZX (ORCPT ); Tue, 19 May 2020 16:25:23 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9001CC08C5C0 for ; Tue, 19 May 2020 13:25:23 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id f6so365935pgm.1 for ; Tue, 19 May 2020 13:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+Bzf40guqOxD9K2dyA9WhKKtNzznnTmwoNHb0gJSwjw=; b=XG8G5EFXwmUpOyRlNjM0abVyAvy7djt3dKplcVxpaThr7R+1hRDSOtqdHG2BbXhLYQ fnV8xAUdfXrM4CXzzvXy1TffqP1yqpdHS/mVwqqzqsRm4yWXe/c5UDTr+WRfHgaWR/y9 1rjA1+Rj80S3oI01JEPJeLXtxTAGptI7h6foRMxssH2Twlc6bc0Cao4uibcEk+U5q9V0 s1FSJReNUJg/4hzAPSb3zp5Km40BO/s1tBBvrhZxIDh3cR7KwnxFvSepH6HyBwdtU60T RuZOe/mBWNhM+tvGMMBjvxZO3GdcMt6ErO0QWdmQ/qXghb1ullfPxqA9jlvi6RBYnAIT FRlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Bzf40guqOxD9K2dyA9WhKKtNzznnTmwoNHb0gJSwjw=; b=bIeMW4zkzIlCwgzerVIusrg1hK/4Oo/LNKYBTnBBCQbjdyXrK/Vp7OAUxfXjQtnqSr SSlkaRuNCWYClahu8x7cZMDMH5dfS8fYzuVQtAmLl16EOaHJ8EfNjABr/KyjPiFy7Ybw o4Bq0tGlcDOxfzgFHFABCith0EjdgPNpIXV//TLd7rjjI+Oz/bo3frLlOJabHm4EsAnR ANXlfrF73ed+4Aj40qIzrIQ0nk1e/oQ3siPvcPSS8QuWUEuQ4UpIqRE1PphubMsFA1GG iqnnl4yO0y1H0tOkCMXpDyQlAX2t7aGy44tBgyLoZFCQULRMNtUWjrB+LylieyQTqz+T wepw== X-Gm-Message-State: AOAM532moN6iJyBtQ1gRM+CBJuSGvSFiyQHpMgtpqkJGFx2DpHJcn3x1 BPWKHQouhpTl2IOm6co7CrosFmzB X-Google-Smtp-Source: ABdhPJxV6elJ1PUgh/RpBRdpMmJd5vXfaGW9iFBPSAmx3DZoL8P3XFqPV5EwSxDysWURDXoc+CDlNw== X-Received: by 2002:a63:5465:: with SMTP id e37mr784931pgm.300.1589919922773; Tue, 19 May 2020 13:25:22 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id c184sm298808pfc.57.2020.05.19.13.25.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 13:25:21 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/4] Bluetooth: Fix assuming EIR flags can result in SSP authentication Date: Tue, 19 May 2020 13:25:17 -0700 Message-Id: <20200519202519.219335-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200519202519.219335-1-luiz.dentz@gmail.com> References: <20200519202519.219335-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz EIR flags should just hint if SSP may be supported but we shall verify this with use of the actual features as the SSP bits may be disabled in the lower layers which would result in legacy authentication to be used. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 0c1cae83c8dc..6b2288d97ab7 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -225,8 +225,6 @@ static void hci_acl_create_connection(struct hci_conn *conn) } memcpy(conn->dev_class, ie->data.dev_class, 3); - if (ie->data.ssp_mode > 0) - set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); } cp.pkt_type = cpu_to_le16(conn->pkt_type); From patchwork Tue May 19 20:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11558735 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AF09618 for ; Tue, 19 May 2020 20:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E86E8206C3 for ; Tue, 19 May 2020 20:25:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tPeU1nmb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbgESUZZ (ORCPT ); Tue, 19 May 2020 16:25:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgESUZY (ORCPT ); Tue, 19 May 2020 16:25:24 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CF5C08C5C0 for ; Tue, 19 May 2020 13:25:24 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id b12so340232plz.13 for ; Tue, 19 May 2020 13:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ni50vKkK680nKaSMsTHtpa2+eV2jnN40meRoXQpQfZI=; b=tPeU1nmb//31SZraI8KY+XD9i5EKwHdpO+h46+AScvcVJt48Ywp/fXwZHDnuF7I80k XUOrS8kI7qnyeNGchOxwpN5SFtyV5+f6wYzkdsmX7NZfBODdj7CizaIKog2Ux33Bbkvv QzLbfRqGLw6xWHLSK8m5+4nEWoifbT+f+ND3jTfidwwv1yx8Lqh053vYN2exfLspr9iY Ryb6ds6CsvoYkwtuMrkdsl78AOAWpaIN5WpMtm1DNlaJAeMB0kzbzq4FPT/Bl0dF22Od u0GEdUP/p5zzEsFelBoOwDk+NVGIIX1rC97WMrcuAqlON35pLWEE9XhwO4uUB8lelNj+ QzKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ni50vKkK680nKaSMsTHtpa2+eV2jnN40meRoXQpQfZI=; b=NLBQJnUPWmPSKme+eQinyDU10lrp2O8JWlbGmO8nscfnLlz3k517IhReDVScmKYRuS +l4K4CLW2cn/IX4cPBgpXrd0sumpRV61IAyOYaOfhmu5HhdjRrtnv8XLuWf1BwlhsTVL cCmcwi2TMrLMoCH3w6uf1UCu00mN3x2e6nDJbxWfdxcilXi9TYzeoq3QEgitH6Odlvdu +6zQflUlWo1Lv/YrqZZ4FY5Pm9+xjngGaOoASBUitWKdG9swelTBadQho5HpLZqL7kq3 qKYBTxlQcXXr0EpqTPy3i8ig3YA3VXjsEg1vqgNag5d2wsSJA9WCNOC2zvAyJfwUluzg doug== X-Gm-Message-State: AOAM532/RLWsROIZVcoVynLxsOhhp26DC+oDBJ2saQsJg5k4VCwsMve2 x3Rr9LeevRyDgZTIM3UpQeIBLfPW X-Google-Smtp-Source: ABdhPJwlecuGBF/XqhjnyPpn+3dcDYOJniTefIS3+OHuBgj2dHK3FOhhTP1rfjhPlKrjAMmfaRdAFA== X-Received: by 2002:a17:902:ab8d:: with SMTP id f13mr1264949plr.58.1589919923905; Tue, 19 May 2020 13:25:23 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id c184sm298808pfc.57.2020.05.19.13.25.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 13:25:23 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 3/4] Bluetooth: Fix bogus check for re-auth no supported with non-ssp Date: Tue, 19 May 2020 13:25:18 -0700 Message-Id: <20200519202519.219335-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200519202519.219335-1-luiz.dentz@gmail.com> References: <20200519202519.219335-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This reverts 19f8def031bfa50c579149b200bfeeb919727b27 "Bluetooth: Fix auth_complete_evt for legacy units" which seems to be working around a bug on a broken controller rather then any limitation imposed by the Bluetooth spec, in fact if there ws not possible to re-auth the command shall fail not succeed. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index dc1cc3c4348c..8c9051ffa665 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2869,14 +2869,8 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) if (!ev->status) { clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); - - if (!hci_conn_ssp_enabled(conn) && - test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { - bt_dev_info(hdev, "re-auth of legacy device is not possible."); - } else { - set_bit(HCI_CONN_AUTH, &conn->flags); - conn->sec_level = conn->pending_sec_level; - } + set_bit(HCI_CONN_AUTH, &conn->flags); + conn->sec_level = conn->pending_sec_level; } else { if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); From patchwork Tue May 19 20:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11558737 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F86D912 for ; Tue, 19 May 2020 20:25:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28175206C3 for ; Tue, 19 May 2020 20:25:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YZS9BKLm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727885AbgESUZ0 (ORCPT ); Tue, 19 May 2020 16:25:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgESUZ0 (ORCPT ); Tue, 19 May 2020 16:25:26 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F7EFC08C5C0 for ; Tue, 19 May 2020 13:25:26 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id t16so351820plo.7 for ; Tue, 19 May 2020 13:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8RsJAFse4tQUTtMZRIGokBhmh9gqfamTDFFuTSZHRkM=; b=YZS9BKLm3ePuo/Z5vhCEJG4BDQLcB8N2LleDwdAOCKlSCr3XnHUs2kAPBrkuPANJIh i/kO3YCSHVMZf1tVi/9Y2G7NFs7BkEQmQSScRgj1I56kY8+ngcDAr/IQbdooGy3fIb0+ l8XqFB/xEjf+rwtSJUEeR61FMht8KZUXQZz0kVe/ZIjG6E2YRQsToyiDEk+n3VJ8goUU 34sinM1pTPjhjyOdf3wNmeQlgQEf+luqPZUjaI6zXg1XO1NGCsYgUUILd8DcWIf/VIH/ QOsvjRA03e72h4jA3vGVdwi9mXGb7FeqI7S3Bsl4e74SONvoVJ8RDqaHM5gctzN7PVti qjew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8RsJAFse4tQUTtMZRIGokBhmh9gqfamTDFFuTSZHRkM=; b=QUBhpmFUKp9BBoADxnGe5K18ynlI4kEqnPdODfRjbvQ8zTpo2/fO+T5V4m6zDfFgjS XPOSJCUvxoLiysdVHummINUpZeMIagwN+3zS3/xc67osDlHLKNNBMm5QXp+bo346jnBj 75FJi81s+cbmt9ORN+GpMt0ZkStHUt0pBjakPvlYPgV40KA7wdThXSTo/2IB6Q4wmDkf w6ArnkB+rL/PahHY86hVLOUp/TtKFqT5cX6C15Uw15pp1TCwiPICDAIvZwSRrFrH4uKG ZFPNQVMFBXTv2zMDmIXoSTl0clzdCp4mEv7+ilSH/JiXuiEXD4Z5t+3VQ8XLseo0mOF7 TAcQ== X-Gm-Message-State: AOAM532CgsccTGNEIZbSCh+mwh9tnnUWNny1gpGBoSyC4yyVfXDlSffj HUyl6DmrhLfSkFoCXag8hobKlxkW X-Google-Smtp-Source: ABdhPJxMf36CkI2QIqVP9cFYitl6xnWln3A1CdhDsuzvY4a3XOgwbkAtBaxg8f+Zf6vRJkwgiuaHHg== X-Received: by 2002:a17:902:684f:: with SMTP id f15mr1182373pln.237.1589919925169; Tue, 19 May 2020 13:25:25 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id c184sm298808pfc.57.2020.05.19.13.25.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 13:25:24 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 4/4] Bluetooth: Consolidate encryption handling in hci_encrypt_cfm Date: Tue, 19 May 2020 13:25:19 -0700 Message-Id: <20200519202519.219335-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200519202519.219335-1-luiz.dentz@gmail.com> References: <20200519202519.219335-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes hci_encrypt_cfm calls hci_connect_cfm in case the connection state is BT_CONFIG so callers don't have to check the state. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 20 ++++++++++++++++++-- net/bluetooth/hci_event.c | 28 +++------------------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 239ab72f16c6..2fe8a5ca9a81 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1380,10 +1380,26 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) conn->security_cfm_cb(conn, status); } -static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, - __u8 encrypt) +static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) { struct hci_cb *cb; + __u8 encrypt; + + if (conn->state == BT_CONFIG) { + if (status) + conn->state = BT_CONNECTED; + + hci_connect_cfm(conn, status); + hci_conn_drop(conn); + return; + } + + if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + encrypt = 0x00; + else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) + encrypt = 0x02; + else + encrypt = 0x01; if (conn->sec_level == BT_SECURITY_SDP) conn->sec_level = BT_SECURITY_LOW; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 8c9051ffa665..34d09a084871 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2910,7 +2910,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) &cp); } else { clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); - hci_encrypt_cfm(conn, ev->status, 0x00); + hci_encrypt_cfm(conn, ev->status); } } @@ -2995,22 +2995,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, conn->enc_key_size = rp->key_size; } - if (conn->state == BT_CONFIG) { - conn->state = BT_CONNECTED; - hci_connect_cfm(conn, 0); - hci_conn_drop(conn); - } else { - u8 encrypt; - - if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) - encrypt = 0x00; - else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) - encrypt = 0x02; - else - encrypt = 0x01; - - hci_encrypt_cfm(conn, 0, encrypt); - } + hci_encrypt_cfm(conn, 0); unlock: hci_dev_unlock(hdev); @@ -3126,14 +3111,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) } notify: - if (conn->state == BT_CONFIG) { - if (!ev->status) - conn->state = BT_CONNECTED; - - hci_connect_cfm(conn, ev->status); - hci_conn_drop(conn); - } else - hci_encrypt_cfm(conn, ev->status, ev->encrypt); + hci_encrypt_cfm(conn, ev->status); unlock: hci_dev_unlock(hdev);