Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp518rdb; Thu, 5 Oct 2023 14:23:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/bvhkQeG/IRlGZdd8ey8eIdhO/z4G7RwFf78U+BB83at9TwXmyuZNfBYzExmgGj+igE3j X-Received: by 2002:a17:902:ea82:b0:1c7:48ea:86ed with SMTP id x2-20020a170902ea8200b001c748ea86edmr6326646plb.62.1696541022222; Thu, 05 Oct 2023 14:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696541022; cv=none; d=google.com; s=arc-20160816; b=wugyW7yDhrbvm7bAV5CSdqtLu8kRuIFCq5CRseGd4RMsgVjCmyBJLnlsIVS8ztkJQk hFbNsF9rB8QIRbjdaZGeAvWAuFAsuXx2yjUB9gLTHWRPqVuu/ruIxWd5I/6DGUPlaiqw OsbtKD3bPwIcmqAfJI3EqY6+eQ/pLI+bFclm83pvIFGN57nPWtnYOrfRKUawOvYDGSKk lREKyVx9WhW7MCntkw9bv+oJitKg2n5oMD6FHBHnqAZZhsLAjg8sn/bum4Tz/mG8bCRC z5s3zkTBeQxsQQOazrq1vu/To86nZoQucRCmgtl6Z17eowwaYRmRGIAWyUqyblR28Cje Uhxw== 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 :message-id:date:subject:to:from:dkim-signature; bh=DDhpUIqvl1ORkTIiMf5KpxmE5DtBrjSETYkFCLhSs/U=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=RYTho8T5cMo3Uu8yUjvcTZjqHI06hd5nulB0SwdT5R64h6kaC7+rmopqNPIm286h4I t2RKNzLWAPqidt7Dw8ULEsBaA8X21YxX+pVPXLecx2mQV7bTLEucVkLxeiIJ5F/OWuPU 9rOtwldK27q6WJ/psRTOuRSWd2Bmg9YjzCA2qif7lQCo7vl7XDHJisr3LJNQGWU8xICS 3Wf11EmauzeXd9uZGlFNE8/ZdG7zaf3GGS6ACcTPqQcY8/Xh7Y1LkLFrHi+NuEdnVB4v Ew8j/NN7LpQYYWfy4XViw+v0Yb2BgvhXcHfR7F61ydk3baMwhn/BDtMU0sfSN6FVAg7N Xp2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ooqcjk2M; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id lg3-20020a170902fb8300b001c33d339754si2164734plb.136.2023.10.05.14.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ooqcjk2M; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A52A784A383F; Thu, 5 Oct 2023 14:23:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjJEVX2 (ORCPT + 99 others); Thu, 5 Oct 2023 17:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjJEVX1 (ORCPT ); Thu, 5 Oct 2023 17:23:27 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B13A495 for ; Thu, 5 Oct 2023 14:23:26 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6969b391791so1170805b3a.3 for ; Thu, 05 Oct 2023 14:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696541005; x=1697145805; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DDhpUIqvl1ORkTIiMf5KpxmE5DtBrjSETYkFCLhSs/U=; b=Ooqcjk2MWgi84wJQPiAcjhCANO7BZ3icVSOHezBR8ZBdXQ1nOYr+97GnlYM5rl6XgZ z8cZnG5gK9+Hgz46QB0JJ0evFqpA1TSNPpPJM3SINAgE5uOUcwclVs6OLpUjeNfnVVKZ KhhxWD166Rom08yUY5rpN4ADsYDgaYCBTU2OivXkfEflZURvfciyYSOOY7paOEIYZ5ZU EsTNVMeBUQul+MPicCPglteqSkZJYkZM+oK2bahYuoGilVXwqN8k7lnIy+FMgzjU4FWV pSIMD4+xwXiK3jNP2dxQqRPX6qz0XIpC+oPHps+ZxleJlTiOXCSQKKxTj1iimjvf1YOG RGTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696541005; x=1697145805; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DDhpUIqvl1ORkTIiMf5KpxmE5DtBrjSETYkFCLhSs/U=; b=PKwL1hjtOruOPfYIkRhOp3QHOvpPCq4bcD9+C4zR1bxircYx02I2sZd+33JvGPdTeE IM3fIt1qbeqT5Amv7CJFTkSaQ0GsEvPa0DOeRkWAajj5PahCadlwkjDCgarUTJPw9tbP T93gcKXtEtlcRBnY6N6TwZyaD0WRK0Jr4HRnfPEY32fRYhoTDp7DUqM0WeXTcwgR87Dk E8ZbmX5s0GDEaqi0v4KY7pEbeQVJB1RDZXHJezyUWOKeqAEAsaaHzo6MsQ4j9mi6V0rG B4zHxngWA9JxzxgPr7ZCFsIzN2+MHxEy/OC+NhYgTnEJuoJUpWKcLnQE76wtVBEKW192 JQOg== X-Gm-Message-State: AOJu0YwykeDDdBS3tlhZQkT/MnCh0QDTmns7G73pzJXa9J5dVaH9/Snc axic6LLsz/LPlJH4E8pHtuQ1K662m0K+i+lS X-Received: by 2002:a05:6a21:3293:b0:16b:89c2:8c0e with SMTP id yt19-20020a056a21329300b0016b89c28c0emr174759pzb.61.1696541005237; Thu, 05 Oct 2023 14:23:25 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id u10-20020a170902b28a00b001c60a2b5c61sm2208410plr.134.2023.10.05.14.23.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:23:24 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/2] Bluetooth: hci_event: Fix using memcmp when comparing keys Date: Thu, 5 Oct 2023 14:23:21 -0700 Message-ID: <20231005212322.3886919-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 05 Oct 2023 14:23:39 -0700 (PDT) From: Luiz Augusto von Dentz memcmp is not consider safe to use with cryptographic secrets: 'Do not use memcmp() to compare security critical data, such as cryptographic secrets, because the required CPU time depends on the number of equal bytes.' While usage of memcmp for ZERO_KEY may not be considered a security critical data, it can lead to more usage of memcmp with pairing keys which could introduce more security problems. Fixes: fe7a9da4fa54 ("Bluetooth: hci_event: Ignore NULL link key") Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 43ed691d0d90..d9c1bfb3082f 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -26,6 +26,8 @@ /* Bluetooth HCI event handling. */ #include +#include +#include #include #include @@ -4754,7 +4756,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data, goto unlock; /* Ignore NULL link key against CVE-2020-26555 */ - if (!memcmp(ev->link_key, ZERO_KEY, HCI_LINK_KEY_SIZE)) { + if (!crypto_memneq(ev->link_key, ZERO_KEY, HCI_LINK_KEY_SIZE)) { bt_dev_dbg(hdev, "Ignore NULL link key (ZERO KEY) for %pMR", &ev->bdaddr); hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); @@ -5294,8 +5296,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn) * available, then do not declare that OOB data is * present. */ - if (!memcmp(data->rand256, ZERO_KEY, 16) || - !memcmp(data->hash256, ZERO_KEY, 16)) + if (!crypto_memneq(data->rand256, ZERO_KEY, 16) || + !crypto_memneq(data->hash256, ZERO_KEY, 16)) return 0x00; return 0x02; @@ -5305,8 +5307,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn) * not supported by the hardware, then check that if * P-192 data values are present. */ - if (!memcmp(data->rand192, ZERO_KEY, 16) || - !memcmp(data->hash192, ZERO_KEY, 16)) + if (!crypto_memneq(data->rand192, ZERO_KEY, 16) || + !crypto_memneq(data->hash192, ZERO_KEY, 16)) return 0x00; return 0x01; -- 2.41.0