Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1232776pxu; Fri, 16 Oct 2020 07:12:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLBCtBzLke+L0OYvW1b5xy3wSjfxTAH66doK/qVUzENy1mqOCu1vJO6pEhxFynWn5nLqqZ X-Received: by 2002:a17:907:417e:: with SMTP id oe22mr3913674ejb.10.1602857571180; Fri, 16 Oct 2020 07:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602857571; cv=none; d=google.com; s=arc-20160816; b=PAEjyCP1g2j6z8BvEYF02sTcwDqYe62Sax3WRtJdTgAqvd4F2EypNaJmKZdel5l2Qp MeHrCvyGUYkoTmsVTKgS54oIVYCetbZqNJS7Xsd9MFJYL596anfH1u7hZfdXopXxu3/A PL1JihcvrSZS3oZxL7vFA4WUzNegYPeuxjUY1X6F+hh03+KlY82F1R0JXbQdPMn2Ylwo 6cWlPUaGOd+RgxqyttlFVXLL/hT4xYLdlcbaptuenT8dSf4ZhsgPb4OV9XokgT/qeyhb N8OqBKktxUgymHugC2PZEkjG3olqn5E6iBKEiTt+enDPslFy7QzUHkEWqTAGwJDpYV61 ffEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+RUDiRPlzDniD7AWXAFbNo/e9smkOBArSAot7YkOuGU=; b=vFO9+8UdU/XQuxjcNgiWCy2asXbHi6scdV4zv+hy890qmF9D4FR6yTU0oOwnKCPuBR Qejergy4IBDOxjaMT1MCx/cAphlZtXwjiNIyblMM7vUjtGFd/87PYwf3+VVCK58g6qIy q1xGFJrqmonkQyUU/ZGOYJbA0WZ1kbZKEm1YUO5Af+mHBi2FRqD5NepghB/ewPp5W0Mt LbHa6gL66pXCeWxn332OSBpPzHvsFr4L2X29f9Hqm13+VNdT4xscXZuzd7kbecMJmDvq fLdkF1rTcPaxG6JYMnx5cUkEGdLtoakhnV32M5bFN2U/a8qnExpDft55FOxRYVG1ZXsN 9Z3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sg78O65A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ng3si1702161ejb.345.2020.10.16.07.12.28; Fri, 16 Oct 2020 07:12:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=default header.b=Sg78O65A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406328AbgJPJQK (ORCPT + 99 others); Fri, 16 Oct 2020 05:16:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:37410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394574AbgJPJIu (ORCPT ); Fri, 16 Oct 2020 05:08:50 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 859CF214DB; Fri, 16 Oct 2020 09:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839316; bh=O30KFM0sT94yUxPrvn+5GjyKvlRBQI2V7sZbwg9qHME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sg78O65A5LflmwoPgkvGXSWKc9ybBIo3KScDAuvADmaEqFuZnO2nsnmDAJMOWVH6z WjI27M/4Lyvopjxpvt2n9iRQxOksbb6/Q9gK79avPLS2MLMg9dmsoVvmajFE1ZqsZT nl/vEMhrIpMdzNKsQyBrHBrwNIPSxFlwkp1nWuwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Hans-Christian Noren Egtvedt Subject: [PATCH 4.14 07/18] Bluetooth: Disconnect if E0 is used for Level 4 Date: Fri, 16 Oct 2020 11:07:17 +0200 Message-Id: <20201016090437.644988101@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.265805669@linuxfoundation.org> References: <20201016090437.265805669@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luiz Augusto von Dentz commit 8746f135bb01872ff412d408ea1aa9ebd328c1f5 upstream. 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 Signed-off-by: Marcel Holtmann Cc: Hans-Christian Noren Egtvedt Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1273,11 +1273,13 @@ static inline void hci_encrypt_cfm(struc 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) { --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1163,6 +1163,23 @@ int hci_conn_check_link_mode(struct hci_ 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; --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2626,26 +2626,22 @@ static void hci_encrypt_change_evt(struc 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) {