From patchwork Wed Mar 20 18:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1914222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V0HrS3D8Dz23r9 for ; Thu, 21 Mar 2024 05:56:56 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rn175-0003Ng-NM; Wed, 20 Mar 2024 18:56:35 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rn16z-0003Mn-6V for kernel-team@lists.ubuntu.com; Wed, 20 Mar 2024 18:56:29 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id AA71C3F118 for ; Wed, 20 Mar 2024 18:56:27 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-6e70785d542so782863b3a.0 for ; Wed, 20 Mar 2024 11:56:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710960985; x=1711565785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tyhFucUtBgsvSz0NhW3HrYbjn9LTMf3d6nY7BZQwKvA=; b=qSdTtNWnDH0yCPhcm0GOZb3qHKKo7tSFrp4TTgC00fo5npuQW9VD97l1gRj17c2BeV 4Hm34EykY4vGhp4OSCipWLK+9wkA7TCFepT3Buom/HviQPq0MKxzubZzhHauM2U/VSM5 M8LIi697C0cqvCoxcf+0bbp8k/VNzrk7dFHinfoKTwt3SDXDKQj06Fy9D1BM9B4NT2xP NE69rhLFMT1uRHqbHaSZFPkQlnzIc58ILPwDRAf1fd1+4XOkHgy+0lU7ODnvJ4AIDdIG YBgKxPfMfiakSLjXOpGBJOnMoT70YAOemGZ2sA1Wn4EviM9p4297Sn34YBktNuyD5O23 tl9Q== X-Gm-Message-State: AOJu0YxI/2RpIOxQXj9wZEFB282xLgI+1Ea+pO0FEQisszEtvzkI7pVi lzk0aqTRsSHZTqg6EdYOQJ6f6XxH5XSgtWnhq13zbO8R7JAmsWNFdJO8fsIlud7zS2HYJ+QcZ8i UhGoG2xFJKU3vxt7MSUzI/d8Onun7XhhrwSb/RLkyHYbCTCT4v7XEZ2CrR4w3ZJT/wgyJckjQcG L768eJpEAjtykj X-Received: by 2002:a05:6a00:2296:b0:6e6:c38e:e8cf with SMTP id f22-20020a056a00229600b006e6c38ee8cfmr622679pfe.2.1710960984929; Wed, 20 Mar 2024 11:56:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/YdQ4MVnRF0aw2IKig7qq894cbXR1p+6GwSTjJAPQew3rp00okcYzekplBlHO3CS+S6ukzw== X-Received: by 2002:a05:6a00:2296:b0:6e6:c38e:e8cf with SMTP id f22-20020a056a00229600b006e6c38ee8cfmr622661pfe.2.1710960984501; Wed, 20 Mar 2024 11:56:24 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2001:67c:1562:8007::aac:4795]) by smtp.gmail.com with ESMTPSA id jw2-20020a056a00928200b006e703e0e2f7sm8617526pfb.194.2024.03.20.11.56.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 11:56:24 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 1/1] Bluetooth: Add more enc key size check Date: Wed, 20 Mar 2024 14:56:10 -0400 Message-Id: <20240320185611.385130-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240320185611.385130-1-yuxuan.luo@canonical.com> References: <20240320185611.385130-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" 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. A simple and clear way to achieve this is to place the enc key size check in hci_cc_read_enc_key_size() 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) Cc: stable@vger.kernel.org Signed-off-by: Alex Lu Signed-off-by: Max Chou Signed-off-by: Luiz Augusto von Dentz (backported from commit 04a342cc49a8522e99c9b3346371c329d841dcd2) [yuxuan.luo: manually backported. Renamed status to rp_status to avoid name conflict with the function argument "status". ] CVE-2023-24023 Signed-off-by: Yuxuan Luo --- net/bluetooth/hci_event.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index f5b46ea9d4c4d..4ed4b83c5fd68 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2902,6 +2902,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, const struct hci_rp_read_enc_key_size *rp; struct hci_conn *conn; u16 handle; + u8 rp_status; BT_DBG("%s status 0x%02x", hdev->name, status); @@ -2911,6 +2912,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, } rp = (void *)skb->data; + rp_status = rp->status; handle = le16_to_cpu(rp->handle); hci_dev_lock(hdev); @@ -2923,15 +2925,30 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, * (which is the same we do also when this HCI command isn't * supported. */ - if (rp->status) { + if (rp_status) { bt_dev_err(hdev, "failed to read key size for handle %u", handle); conn->enc_key_size = HCI_LINK_KEY_SIZE; } else { conn->enc_key_size = rp->key_size; + rp_status = 0; + + if (conn->enc_key_size < hdev->min_enc_key_size) { + /* As slave role, the conn->state has been set to + * BT_CONNECTED and l2cap conn req might not be received + * yet, at this moment the l2cap layer almost does + * nothing with the non-zero status. + * So we also clear encrypt related bits, and then the + * handler of l2cap conn req will get the right secure + * state at a later time. + */ + rp_status = HCI_ERROR_AUTH_FAILURE; + clear_bit(HCI_CONN_ENCRYPT, &conn->flags); + clear_bit(HCI_CONN_AES_CCM, &conn->flags); + } } - hci_encrypt_cfm(conn, 0); + hci_encrypt_cfm(conn, rp_status); unlock: hci_dev_unlock(hdev);