Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23304C636CA for ; Sun, 18 Jul 2021 20:19:49 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 95FD4610CB for ; Sun, 18 Jul 2021 20:19:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95FD4610CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 51D1B82C47; Sun, 18 Jul 2021 22:18:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="evHdXUdE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0AFE282BF7; Sun, 18 Jul 2021 22:18:22 +0200 (CEST) Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E5DC4828EB for ; Sun, 18 Jul 2021 22:18:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc2a.google.com with SMTP id t46-20020a4a96f10000b02902618ad2ea55so3931074ooi.4 for ; Sun, 18 Jul 2021 13:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jiKcn1o430eh/BOVWKtQRjvqrv/VGjGvlMbzq2DAZoM=; b=evHdXUdEYe2T2uvPMilov9ikiZuVyN67Kf3dtrPuWxdY8vvRYKhJPZA+8iRPoNUEtb BtPAHY7/8vKQC6NoP1GsvP2u/nfr2YIc5JyltAWjUp+Ax4FMtHnKpBaQbEnVrR7ZhTp4 HPcW3Hyl3tGYAzDSWPm8zEDRX2Qk21VRJzgT4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jiKcn1o430eh/BOVWKtQRjvqrv/VGjGvlMbzq2DAZoM=; b=LxrXD5VPXFWryFRSsPCnQG2a9ezzb6K2Uq7sE955DV1bevkrvDSdgjhjGoq9QP+lVx wTT7KRQTG5+iLFabJ11mBzuKw0kvAiRE2p2RJtvo8W7xcLXk2NvvBCiBG8lCLueggpwj NlyXqcNLWk4kxkRTeXBC5m4FZXk+3vKU6rmg0W6rdybxyJAtzHLcmHz2D2qdZZLY+96L ylsvgZpFRVp/dfshewQqPmGyieKPm7lDH1/ITw5z5W7KaqMXxev+OoqfAjIy6OolqWjJ OwrL0GY6CpW5qRC/7jel6VkwTxh64kOteKpO7ntu1nuRek6tR6y4cklnUP41/1U4CCkk LMyA== X-Gm-Message-State: AOAM533roJzO4FVBENox6LuSW3UZhqKZEyYGA79mDSF4BmmDNzXd8xJa sWy/uj++3lppIu3X2Wr9i/srJbO1ZnwG2Idl X-Google-Smtp-Source: ABdhPJwQ0v8aT8X0WHTqZsSU9gQRYWox1jdB+3+IcZd1aIs2VSoUSCigNTFyJ9X7OOpUNhrAHL/sBg== X-Received: by 2002:a4a:ae8c:: with SMTP id u12mr15422882oon.3.1626639497202; Sun, 18 Jul 2021 13:18:17 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id g1sm3031606ooi.34.2021.07.18.13.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 13:18:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Thirupathaiah Annapureddy , Simon Glass , Heinrich Schuchardt Subject: [PATCH v2 09/10] sandbox: tpm: Correct handling of SANDBOX_TPM_PCR_NB Date: Sun, 18 Jul 2021 14:18:05 -0600 Message-Id: <20210718201806.761202-10-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog In-Reply-To: <20210718201806.761202-1-sjg@chromium.org> References: <20210718201806.761202-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This is the number of PCRs, so the current check is off by one. Also the map itself should not be checked, just the resulting pcr_index, to avoid confusing people who read the code. Fix these problems. Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to correct handling of SANDBOX_TPM_PCR_NB drivers/tpm/tpm2_tis_sandbox.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c index ed9c9a0bc9f..3c4bbcdf2ee 100644 --- a/drivers/tpm/tpm2_tis_sandbox.c +++ b/drivers/tpm/tpm2_tis_sandbox.c @@ -642,15 +642,8 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, for (i = 0; i < pcr_array_sz; i++) pcr_map += (u64)sent[i] << (i * 8); - if (pcr_map >> SANDBOX_TPM_PCR_NB) { - printf("Sandbox TPM handles up to %d PCR(s)\n", - SANDBOX_TPM_PCR_NB); - rc = TPM2_RC_VALUE; - return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); - } - if (!pcr_map) { - printf("Empty PCR map.\n"); + printf("Empty PCR map\n"); rc = TPM2_RC_VALUE; return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); } @@ -659,6 +652,13 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, if (pcr_map & BIT(i)) pcr_index = i; + if (pcr_index >= SANDBOX_TPM_PCR_NB) { + printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n", + pcr_index, SANDBOX_TPM_PCR_NB); + rc = TPM2_RC_VALUE; + return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); + } + /* Write tag */ put_unaligned_be16(tag, recv); recv += sizeof(tag); @@ -692,9 +692,9 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, pcr_index = get_unaligned_be32(sendbuf + sizeof(tag) + sizeof(length) + sizeof(command)); - if (pcr_index > SANDBOX_TPM_PCR_NB) { - printf("Sandbox TPM handles up to %d PCR(s)\n", - SANDBOX_TPM_PCR_NB); + if (pcr_index >= SANDBOX_TPM_PCR_NB) { + printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n", + pcr_index, SANDBOX_TPM_PCR_NB); rc = TPM2_RC_VALUE; } -- 2.32.0.402.g57bb445576-goog