Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3825512rdb; Mon, 11 Dec 2023 00:29:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEur3KxZJpdI0dcEk2yRPBpm/fooZEYi8BSvH15NdDrF7nO6fRaxIz7mfUQ8+OfEujXDxK X-Received: by 2002:a17:902:e842:b0:1d1:cb7a:a8eb with SMTP id t2-20020a170902e84200b001d1cb7aa8ebmr1482852plg.53.1702283395473; Mon, 11 Dec 2023 00:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702283395; cv=none; d=google.com; s=arc-20160816; b=xFLtB1l0XWIpln/Zq9qdjZ88oQdWDcgPFJVPBjowhbDlALR8Re3gnId+pNDxBL9rHB fOBJEU5VKLL+cWUPErhKBI5T8lZ7MQjjicOVbyu38ok96ig3fQVPFRTCKEdXdGNIAEfd xyCVU2WWfdMM/i28grf5DGtfBayLKU7MeDw5TnF9mOKmLfAvR2kB+Zd0ggNO0HNzgFhf u7GN15jQpFdfxPENKrnSvpN7QZHvZmeq6xYfwoFQWpeJ+TO7ZeczLZx0iIv4DTMZD7Xi t/oiGM9f1bnASBMGKqGFD3RzOyzzBA2HF2QHlPh9fTRK6ucTzoEMHkIUP9mpojhtnE8Q jhIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=kj+51azGLhEAGWV6j2wJ7OUNB2c5ZbQvjGHQkqxpKS8=; fh=5tsMlV+CZFncqCxW0JiQnKLipd7NERFBPxjlqP4n6Bo=; b=qvUvTy3dhwhqXCNBzzWEhR0ZC9hH8SLibvumzZMtN8KcK3frT8MzMUDa3O8Bzh+C5a vXBwCeOfuMs3GMwQ+rsQ4+NgZN6e+XTzShDPYPZIypHQBY/5tP+Du8yWsB4ZBrErzdXY SJaYovVQQBo5lGe7c/neKKmfSB7m02fAMkA1Ki808Tt6qibPQT1Y81eT3XM6UldSXxFH UeYuga/phTJZh63horTCSjGmY+W8uhulaysxq0cxurabX/EoytrWWCwUcZLmigtfxdl9 7Ci6jWkRezjXb2atxlSCoIBAk2nDaxIh9XAxh5tcKvf1aJx3Yah2Al550P5+7OCVDtlE VsKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b001d1ccbe983asi5856232plg.383.2023.12.11.00.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 00:29:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id AEB4F8069A02; Mon, 11 Dec 2023 00:29:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229654AbjLKI3f (ORCPT + 99 others); Mon, 11 Dec 2023 03:29:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjLKI3f (ORCPT ); Mon, 11 Dec 2023 03:29:35 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F221FE5; Mon, 11 Dec 2023 00:29:39 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3BB8TPNC02597530, This message is accepted by code: ctloc85258 Received: from RSEXMBS01.realsil.com.cn ([172.29.17.195]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3BB8TPNC02597530 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Mon, 11 Dec 2023 16:29:31 +0800 Received: from alexlu (172.29.36.158) by RSEXMBS01.realsil.com.cn (172.29.17.195) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 11 Dec 2023 16:29:25 +0800 Date: Mon, 11 Dec 2023 16:29:12 +0800 From: Alex Lu To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , , CC: Max Chou , Karen Hsu Subject: [PATCH] Bluetooth: Add more enc key size check Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline X-Originating-IP: [172.29.36.158] X-ClientProxiedBy: RSEXH36502.realsil.com.cn (172.29.17.3) To RSEXMBS01.realsil.com.cn (172.29.17.195) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 00:29:52 -0800 (PST) From: Alex Lu When we are slave role and receives l2cap conn req when encryption has started, we should check the enc key size to avoid KNOB attack or BLUFFS attack. From SIG recommendation, implementations are advised to reject service-level connections on an encrypted baseband link with key strengths below 7 octets. The btmon log below shows the case that lacks enc key size check. > HCI Event: Connect Request (0x04) plen 10 Address: BB:22:33:44:55:99 (OUI BB-22-33) Class: 0x480104 Major class: Computer (desktop, notebook, PDA, organizers) Minor class: Desktop workstation Capturing (Scanner, Microphone) Telephony (Cordless telephony, Modem, Headset) Link type: ACL (0x01) < HCI Command: Accept Connection Request (0x01|0x0009) plen 7 Address: BB:22:33:44:55:99 (OUI BB-22-33) Role: Peripheral (0x01) > HCI Event: Command Status (0x0f) plen 4 Accept Connection Request (0x01|0x0009) ncmd 2 Status: Success (0x00) > HCI Event: Connect Complete (0x03) plen 11 Status: Success (0x00) Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33) Link type: ACL (0x01) Encryption: Disabled (0x00) ... > HCI Event: Encryption Change (0x08) plen 4 Status: Success (0x00) Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33) Encryption: Enabled with E0 (0x01) < HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2 Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33) > HCI Event: Command Complete (0x0e) plen 7 Read Encryption Key Size (0x05|0x0008) ncmd 2 Status: Success (0x00) Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33) Key size: 6 ... // We should check the enc key size > ACL Data RX: Handle 1 flags 0x02 dlen 12 L2CAP: Connection Request (0x02) ident 3 len 4 PSM: 25 (0x0019) Source CID: 64 < ACL Data TX: Handle 1 flags 0x00 dlen 16 L2CAP: Connection Response (0x03) ident 3 len 8 Destination CID: 64 Source CID: 64 Result: Connection pending (0x0001) Status: Authorization pending (0x0002) > HCI Event: Number of Completed Packets (0x13) plen 5 Num handles: 1 Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33) Count: 1 #35: len 16 (25 Kb/s) Latency: 5 msec (2-7 msec ~4 msec) < ACL Data TX: Handle 1 flags 0x00 dlen 16 L2CAP: Connection Response (0x03) ident 3 len 8 Destination CID: 64 Source CID: 64 Result: Connection successful (0x0000) Status: No further information available (0x0000) Signed-off-by: Alex Lu Signed-off-by: Max Chou --- net/bluetooth/l2cap_core.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 17ca13e8c044..b0f31d798132 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1669,7 +1669,13 @@ static void l2cap_conn_start(struct l2cap_conn *conn) rsp.dcid = cpu_to_le16(chan->scid); if (l2cap_chan_check_security(chan, false)) { - if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { + if (!l2cap_check_enc_key_size(conn->hcon)) { + l2cap_state_change(chan, BT_DISCONN); + __set_chan_timer(chan, + L2CAP_DISC_TIMEOUT); + rsp.result = L2CAP_CR_SEC_BLOCK; + rsp.status = L2CAP_CS_NO_INFO; + } else if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { rsp.result = cpu_to_le16(L2CAP_CR_PEND); rsp.status = cpu_to_le16(L2CAP_CS_AUTHOR_PEND); chan->ops->defer(chan); @@ -4202,7 +4208,15 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn, if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { if (l2cap_chan_check_security(chan, false)) { - if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { + /* As slave role, we should check the enc key size when + * l2cap conn req is received. + */ + if (!l2cap_check_enc_key_size(conn->hcon)) { + l2cap_state_change(chan, BT_DISCONN); + __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); + result = L2CAP_CR_SEC_BLOCK; + status = L2CAP_CS_NO_INFO; + } else if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { l2cap_state_change(chan, BT_CONNECT2); result = L2CAP_CR_PEND; status = L2CAP_CS_AUTHOR_PEND; -- 2.39.2