From patchwork Thu Mar 14 10:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1912060 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 4TwNhL6W8Qz1ydl for ; Thu, 14 Mar 2024 21:21:22 +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 1rkiD0-0005GM-Lc; Thu, 14 Mar 2024 10:21:10 +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 1rkiCn-0005F2-QD for kernel-team@lists.ubuntu.com; Thu, 14 Mar 2024 10:20:58 +0000 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (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 82C963F1D9 for ; Thu, 14 Mar 2024 10:20:57 +0000 (UTC) Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-6dde168a7aeso757481a34.1 for ; Thu, 14 Mar 2024 03:20:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710411655; x=1711016455; 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=TUAQR60q10Ckle+1EGDWjylGfwm0Joo2VZQJ2z72mw8=; b=K4ZHaNbXbAv/uMfxLRwD/ptPUYI6uBXLByMxS4WPU8SblVVP0m6IxfIII1yraAA42R QijS3VWEQblUjUM7kiegTIcLwTmjU2zUQ2auwjO/QkOkaNBi3+He+CgY1p7UHEVt2JD2 TocHb0vOt++m8pAb4KZ53zx1rYgXgN5DW2tvbBvFNQ1bJNknONHZVlGemlmQ7etUVIPT EXs3W2Jvuv/U+g1nfbi3RPi+jUoxOKnE0uWX2l9Mv3qQK7iA+arJh6IkdiOxqBXfyQao fIIf6wDE+HNkMfbk/yfsHfW4dTc6HdPZC8W9B0R5aDheJvQN6fSXt4kd/Jz7SQQyw+6d bc2g== X-Gm-Message-State: AOJu0YxONU+N4XszvcAC+a+0NKDOtx21l7estT2uMuLwfwx1U7yB+kxe WuXOEquFbZXJJqlrVk06KFsTzGydjYH4XwYyuPaQthv9fjmjO3NfmuS4cusg38SHd5pP/wQE6SM S31B4lfDZidCjT0b/YpiRg/WSlBbr9ffMV0NVMI8EWLfkvk/39UH/U/qHUczM2mOwUdKxEX3jWZ 2nLHsxuPy0vkCY/W0= X-Received: by 2002:a05:6358:d596:b0:17e:a3c0:f000 with SMTP id ms22-20020a056358d59600b0017ea3c0f000mr1553029rwb.5.1710411655320; Thu, 14 Mar 2024 03:20:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIBG+N1HLuxKJPTfPbru5y9ge3z9fuFWuiTlDBlRsFWLCQ7eRcCJzS6X1NlZMY930evD9FxA== X-Received: by 2002:a05:6358:d596:b0:17e:a3c0:f000 with SMTP id ms22-20020a056358d59600b0017ea3c0f000mr1553015rwb.5.1710411654891; Thu, 14 Mar 2024 03:20:54 -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.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 03:20:54 -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: Thu, 14 Mar 2024 06:20:01 -0400 Message-Id: <20240314102002.22662-2-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) 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 f5b46ea9d4c4d..3f3b14ce31eea 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 = rp->status; BT_DBG("%s status 0x%02x", hdev->name, status); @@ -2923,15 +2924,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);