Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D156AECAAA1 for ; Wed, 31 Aug 2022 03:06:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2824E849B5; Wed, 31 Aug 2022 05:06:02 +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="XyqTN2+Y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 633FF849C0; Wed, 31 Aug 2022 05:05:59 +0200 (CEST) Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) (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 ECA2E819FC for ; Wed, 31 Aug 2022 05:05:55 +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-oa1-x2e.google.com with SMTP id 586e51a60fabf-11f11d932a8so12948492fac.3 for ; Tue, 30 Aug 2022 20:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=NEEOoJ6nBPEl6RHdZc4CI5y1OBP/b/o7V9ZznO6vyDo=; b=XyqTN2+YMuzcf5PikkCnPFK2fYQdqP7UfpIn+q3vwQkPRwb4OmPln7qRzfI8Ow54cF 8/ulHxB4jFTU2IPtiOM7YXqf71CwcajqT9G1StZBJU7rZKlu8oxIwDmHtEcHB6JuKvHa POCT9eGoxnZ+FxRl3jKqRthBwwXYza1k5AQQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=NEEOoJ6nBPEl6RHdZc4CI5y1OBP/b/o7V9ZznO6vyDo=; b=8JrCKPifdrvwelNDq0CvfIVYU80rFMZDaOMuqG4Qm7Sz6Ax6XzOchD1x8mAwhruTri XXM49Lq2F8eh4ryvA89RWyW+bwfEhK1Eo65IXg8xwnVP8lZl5m61ASHkj4sY5thqBJ3X mkhEiQibF0HjYPao9/B6uVjBgh2VU3LR4/E6MHQlN0Zn01nqnq92ohoLAWYZNYbwKY4p H4E2JL8tT8WrZO3//06uB1CbwHjlUdplh6zA8DErOIOaR7GMvMrpakLLtFZQ8hetNyYl 1sNfPW3ILcbL3vg+BQiQc+ZpDUQx0lXzRe7R0WwIaqRspkLPZ9RSFuhJKzQriLI1mHUj HX+w== X-Gm-Message-State: ACgBeo3rq0/PjuAbPSGYQDTcGf8EDmzcgTQDhmx3VtRg7fG1JE2DZweA e+zAewp5n9K34nsbRd5IaPc2C2OePfwFJg== X-Google-Smtp-Source: AA6agR4+Z39YE6/KRv1UOQ7BBXQwQ8VHFwZkQGk4pbq+yAogZX2k8kJQXiaUabObNGTiubuDS7n1Ng== X-Received: by 2002:a05:6870:ac2c:b0:11c:743b:8c9f with SMTP id kw44-20020a056870ac2c00b0011c743b8c9fmr512254oab.209.1661915154480; Tue, 30 Aug 2022 20:05:54 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id cp6-20020a056830660600b0063b34c35575sm2888129otb.42.2022.08.30.20.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:05:54 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Ilias Apalodimas Subject: [PATCH v5 1/7] tpm: Require a digest source when extending the PCR Date: Tue, 30 Aug 2022 21:05:32 -0600 Message-Id: <20220831030538.26742-2-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220831030538.26742-1-sjg@chromium.org> References: <20220831030538.26742-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean This feature is used for measured boot, so we can add a log entry to the TCPA with some information about where the digest comes from. It is not currently supported in the TPM drivers, but add it to the API so that code which expects it can signal its request. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes in v5: - Reword mention of measured boot Changes in v3: - Drop limits on the TPM hash size - Update commit message Changes in v2: - Use "cmd" for the digest type in the tpm command - Update comment for tpm_pcr_extend() 'name' parameter cmd/tpm-v1.c | 3 ++- cmd/tpm_test.c | 5 +++-- include/tpm_api.h | 8 +++++--- lib/tpm-v2.c | 2 ++ lib/tpm_api.c | 10 ++++++---- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c index bf238a9f2e3..0efb079b0a9 100644 --- a/cmd/tpm-v1.c +++ b/cmd/tpm-v1.c @@ -131,7 +131,8 @@ static int do_tpm_extend(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - rc = tpm_pcr_extend(dev, index, in_digest, out_digest); + rc = tpm_pcr_extend(dev, index, in_digest, sizeof(in_digest), + out_digest, "cmd"); if (!rc) { puts("PCR value after execution of the command:\n"); print_byte_string(out_digest, sizeof(out_digest)); diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c index a3ccb12f53a..b35eae81dc3 100644 --- a/cmd/tpm_test.c +++ b/cmd/tpm_test.c @@ -91,7 +91,8 @@ static int test_early_extend(struct udevice *dev) tpm_init(dev); TPM_CHECK(tpm_startup(dev, TPM_ST_CLEAR)); TPM_CHECK(tpm_continue_self_test(dev)); - TPM_CHECK(tpm_pcr_extend(dev, 1, value_in, value_out)); + TPM_CHECK(tpm_pcr_extend(dev, 1, value_in, sizeof(value_in), value_out, + "test")); printf("done\n"); return 0; } @@ -438,7 +439,7 @@ static int test_timing(struct udevice *dev) 100); TTPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)), 100); - TTPM_CHECK(tpm_pcr_extend(dev, 0, in, out), 200); + TTPM_CHECK(tpm_pcr_extend(dev, 0, in, sizeof(in), out, "test"), 200); TTPM_CHECK(tpm_set_global_lock(dev), 50); TTPM_CHECK(tpm_tsc_physical_presence(dev, PHYS_PRESENCE), 100); printf("done\n"); diff --git a/include/tpm_api.h b/include/tpm_api.h index 11aa14eb793..8979d9d6df7 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -81,14 +81,16 @@ u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data, * * @param dev TPM device * @param index index of the PCR - * @param in_digest 160-bit value representing the event to be + * @param in_digest 160/256-bit value representing the event to be * recorded - * @param out_digest 160-bit PCR value after execution of the + * @param size size of digest in bytes + * @param out_digest 160/256-bit PCR value after execution of the * command + * @param name digest source, used for log output * Return: return code of the operation */ u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, - void *out_digest); + uint size, void *out_digest, const char *name); /** * Issue a TPM_PCRRead command. diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 1bf627853af..6058f2e1e4f 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -157,6 +157,8 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, }; int ret; + if (!digest) + return -EINVAL; /* * Fill the command structure starting from the first buffer: * - the digest diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 032f383ca04..7e8df8795ef 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -140,15 +140,17 @@ u32 tpm_write_lock(struct udevice *dev, u32 index) } u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, - void *out_digest) + uint size, void *out_digest, const char *name) { - if (tpm_is_v1(dev)) + if (tpm_is_v1(dev)) { return tpm1_extend(dev, index, in_digest, out_digest); - else if (tpm_is_v2(dev)) + } else if (tpm_is_v2(dev)) { return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest, TPM2_DIGEST_LEN); - else + /* @name is ignored as we do not support the TPM log here */ + } else { return -ENOSYS; + } } u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) -- 2.37.2.672.g94769d06f0-goog