From patchwork Thu Mar 14 10:20:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1912061 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 4TwNhN6vKxz1yWn for ; Thu, 14 Mar 2024 21:21:24 +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 1rkiD5-0005HW-IO; Thu, 14 Mar 2024 10:21:15 +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 1rkiCr-0005FN-Oz for kernel-team@lists.ubuntu.com; Thu, 14 Mar 2024 10:21:02 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.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 57D243F62E for ; Thu, 14 Mar 2024 10:21:01 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-5dbddee3694so492196a12.1 for ; Thu, 14 Mar 2024 03:21:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710411659; x=1711016459; 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=yVUcU/mEAljxGf9hIO81kXMnQpFWcrw80gI1umsGCvk=; b=ICa9MEpSFme4IU4NKhxEk/hLPK4o7luiVh5WISPFY0XHx85Udx4OhtSVaVTNSVXarc c4FZvZCu53uck6IZ2B49XJQIUBrnOomw5aVVuIt40e7kERu13yRK2k6B2avQU0KrWXqg 4GtjDBBOQ5ED1mz1VZ1nxxV9CmQC9BfIaJisK6FJATAmP3YNgJk3XtK0U+OXf3VQ34FB VMSKLJ1l4tXFT0waai4AZWrQtub0u6WBrnYci6JEIMoDRQQosYFE7FdXCOxlJHW+6Bho owgA3dT+n8M1LW6aM7Us9wcPK4ZgRjObc3B5ddFA6Ba5QwJwVeLdpqLhNjIl5+ZFmm5/ GFDQ== X-Gm-Message-State: AOJu0YzTBXewEYYzXkqJ9yUsOKWvSdCdfiIii8j/Eud5PQzYczeS3GlY eZ7r1752YTAdHNa8FRtpGbBRR9pOJyjX4Jor7eoMpj73NMd1rEld3PMoRq7wjQIxqwFAfO0obaa XdASSNnooujtTy9+6LWzpJ2yWFAxDbFX6aFlJv38faxVKL4WwK7UKeHAcNvH9ofzVqOcv9c6GqV 8ITGI1LCWUER7NIDY= X-Received: by 2002:a05:6a20:12c1:b0:1a0:f7d0:e680 with SMTP id v1-20020a056a2012c100b001a0f7d0e680mr7978541pzg.5.1710411658970; Thu, 14 Mar 2024 03:20:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdTbdqwqaeD7RzedQDq0i7sUps8/Tn/XFcI0x8+ivvCNU7RG2HhsjRBEDeDz7q+w7bofTuJA== X-Received: by 2002:a05:6a20:12c1:b0:1a0:f7d0:e680 with SMTP id v1-20020a056a2012c100b001a0f7d0e680mr7978505pzg.5.1710411658311; Thu, 14 Mar 2024 03:20:58 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1562:8007::aac:4795]) by smtp.gmail.com with ESMTPSA id p6-20020a63ab06000000b005dc89957e06sm333939pgf.71.2024.03.14.03.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 03:20:57 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][Jammy][PATCH 1/1] Bluetooth: Add more enc key size check Date: Thu, 14 Mar 2024 06:20:02 -0400 Message-Id: <20240314102002.22662-3-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240314102002.22662-1-yuxuan.luo@canonical.com> References: <20240314102002.22662-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 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index b1eb614f2aad3..f9072872c35a5 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3113,6 +3113,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 = rp->status; BT_DBG("%s status 0x%02x", hdev->name, status); @@ -3134,15 +3135,30 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, * secure approach is to then assume the key size is 0 to force a * disconnection. */ - if (rp->status) { + if (rp_status) { bt_dev_err(hdev, "failed to read key size for handle %u", handle); conn->enc_key_size = 0; } 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);