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: 197005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5122C433DF 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 7A92220657 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: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: 197004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C70DC433DF 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 26A5C20657 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);