Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp873356ybk; Wed, 20 May 2020 14:21:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypqo9qUQTxUb0XvrMs3wdNd9YpSQhRnyzKRf8wUiLPvy4oaiZFBsQGyeX6aI8vo0Z9pkH2 X-Received: by 2002:a17:906:aeca:: with SMTP id me10mr958647ejb.367.1590009680307; Wed, 20 May 2020 14:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590009680; cv=none; d=google.com; s=arc-20160816; b=pEH14h+4nGeIGd0c/9InWuL/qSnIepE3ldiGhvSMrgImdYLgp3eifUZt5VaTG6NeTI bgt4bA5mix2lZuRl7dfxWmN/mzsdGq0uLgPENX+fhG3Rz0Ggq2hYX7IL7z+Y+x6D/KpN D6dAJMSdd12GiCBiffBaYaS7fnlYIyxSL/62dbjMQPNPWVcwQJODKDHiMZ8/Yy7XLMf/ qHPLJTDHtwVJYTnU8nIm1tAvMgqWxIZD1kt4LL86agjeRT5Anj/kKtNCL/A58kt3bJXy byLizYNgA3t851wK/IxqU8Z8BuHcX8gmOwMNVs6WRfef4lRaePCotacxZMRHDMxEevPO 9JWg== 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:to:from:dkim-signature; bh=SePuO/HN8ITyCg8r9ePWi40xnk0eIjVtXgcuev5d1Yw=; b=NVTFTBTPFBv9FW9qyKByI4knXkpNxIn7FCv9e2AFFk2LbTuJKzdE7MHhoDud5gA9JT NMh+7svsEFIeRjEpZcZXBJifRQCt+CI6fI9kCRKVcN4WPuf6yKPSAzGDa0NHta6ftCeJ MGqFN6ldtx52jyV2avhymtQACD1eJbRqXGpBqiEc8oe/UFk/ORBAjnCyZYSXLeMldyXS dTgD0p1P8E98OeuT/jJ/6od7RPZdqsfOreQVW1WAcvPdJYao1MnGxloyEocdckBmSXL/ B2QJL1JceUoAGGinZomfKhbNLshD3GUYD04h02897f2Y63tnSvRw3IQsQ+r3pCvU/1uo 4xBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="EZtBNZT/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca1si2212361ejb.42.2020.05.20.14.20.40; Wed, 20 May 2020 14:21:20 -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=@gmail.com header.s=20161025 header.b="EZtBNZT/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726650AbgETVUV (ORCPT + 99 others); Wed, 20 May 2020 17:20:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgETVUU (ORCPT ); Wed, 20 May 2020 17:20:20 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD537C061A0E for ; Wed, 20 May 2020 14:20:20 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id l73so374942pjb.1 for ; Wed, 20 May 2020 14:20:20 -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=SePuO/HN8ITyCg8r9ePWi40xnk0eIjVtXgcuev5d1Yw=; b=EZtBNZT/tTRzi7NK7K8vn6bnVa3nDzLgHDDnSJOoxTWcr8iI/bs2YdF6miM2gbzfa5 Hw9Oe/REOUt5AEwK8oPyVSv6NuOcmAzvr3rCuNNW6puJym9fBKfc1/L3T3+/510mAVk6 dT61k+5cnaIV6eTlyyxI8hOLPp7ozc3/Zo24Qv61xuj1AWiN9WN0FXjNVpUys5G5KhkL 7x+/qVyJCJXM9KPQ+g7rMacXYIoM4vmMyfmWxf4bPLKPCux5i5Cbzm8bOdXxgoYfPnEV NoLKgX52jVGXQK+SvxwoS1jkHuLs6kC5/SJucLlbTyHFgvIuRzISk3jUOAC0UwRyc/lU UNKg== 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=SePuO/HN8ITyCg8r9ePWi40xnk0eIjVtXgcuev5d1Yw=; b=Jed4FqhnZ9Li2KKSN0Ii6ctuxbsew+D2UU82Aj/87GBSCCBza2Bl/FwA+oSVDLKjoA QYZi4Tob7uRjZISk6XjpVCGPj8TktNjF2zHuqvWtBEbkAdTLT0nVeapduaqlsGz6jz7Z 61YGyuNF5+EDqC7bTHMzjHlRGilwVaee0ygJ2GGSBLWJutznwOxysYUpU1DxpLFjvpzD H/+Za3WwI/yKr6Z/QW67rBEWH5wdOViC7Kh1k/WE3VyccADIzmAmcdGscEfPlo52Y6fi eyS4THl8KoUQkgLHebk99JqyWpe7v6GJvQlwrRJVLZSH+lXvpkYSrSbZgxyerlBEG6W+ 0z+Q== X-Gm-Message-State: AOAM531VQBRKSpFyOduRnUxcyq0yMjONKAeE1YSKpka1f8TlYTfGWyii BJGN6fBIFGaSWTETd5LBMy1V8OBl X-Received: by 2002:a17:90a:f098:: with SMTP id cn24mr7462804pjb.201.1590009619280; Wed, 20 May 2020 14:20:19 -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 o27sm2424524pgd.18.2020.05.20.14.20.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:20:17 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/2] Bluetooth: Disconnect if E0 is used for Level 4 Date: Wed, 20 May 2020 14:20:14 -0700 Message-Id: <20200520212015.626026-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.25.3 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 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 --- include/net/bluetooth/hci_core.h | 10 ++++++---- net/bluetooth/hci_conn.c | 17 +++++++++++++++++ net/bluetooth/hci_event.c | 20 ++++++++------------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index cdd4f1db8670..c69309ffd40a 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1402,11 +1402,13 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) else encrypt = 0x01; - if (conn->sec_level == BT_SECURITY_SDP) - conn->sec_level = BT_SECURITY_LOW; + if (!status) { + if (conn->sec_level == BT_SECURITY_SDP) + conn->sec_level = BT_SECURITY_LOW; - if (conn->pending_sec_level > conn->sec_level) - conn->sec_level = conn->pending_sec_level; + if (conn->pending_sec_level > conn->sec_level) + conn->sec_level = conn->pending_sec_level; + } mutex_lock(&hci_cb_list_lock); list_for_each_entry(cb, &hci_cb_list, list) { diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 307800fd18e6..b99b5c6de55a 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1323,6 +1323,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: Missing AES-CCM usage"); + 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 cfeaee347db3..d6a1e2450696 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3065,27 +3065,23 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); + /* Check link security requirements are met */ + if (!hci_conn_check_link_mode(conn)) + ev->status = HCI_ERROR_AUTH_FAILURE; + if (ev->status && conn->state == BT_CONNECTED) { if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); + /* Notify upper layers so they can cleanup before + * disconnecting. + */ + hci_encrypt_cfm(conn, ev->status); hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_conn_drop(conn); goto unlock; } - /* In Secure Connections Only mode, do not allow any connections - * 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); - hci_conn_drop(conn); - goto unlock; - } - /* Try reading the encryption key size for encrypted ACL links */ if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { struct hci_cp_read_enc_key_size cp; -- 2.25.3