From patchwork Tue Mar 23 18:13:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 406941 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4679332jai; Tue, 23 Mar 2021 11:13:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv0gJxQT/ahAdn3LHm4fhxM87/Pe1yR21HVJuHIZY3qpcJoanjVbTY8lg7uPoFYViHbhJf X-Received: by 2002:a17:906:f2d2:: with SMTP id gz18mr6121750ejb.454.1616523210143; Tue, 23 Mar 2021 11:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616523210; cv=none; d=google.com; s=arc-20160816; b=x++LK+UeX8iwLjST6N9w1bsiXC8q5cQBpgwWTpNK7iDYZ+RI7wJJwX/Gd6fexPZT2h 1mu/lBRqnnyWgNdswP2t5RJc0DhJYnZkOBrADnPieLlL3gt/ZxuUFGZ5o2+mFhdb3iUJ UDBuIWoz0K+4IX25gdygJNqZTxMpS9RGNyyCASwTMiGko/Mr798c3Wu4V/tGWUCLOEO+ cKiScZs0CXYeUVcz+07iiH5bSZ8/zv9yG4g4ifl3K0Ls2vpM2vfKmTUHpT0wUn/XyDqx INFPJvwEP29XlaYJQ5LZVuzojQqmRrrGHZMqDG18XFI6uKGxOQB+uJiTyJ26uTB5rtPI LIRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=MED0Cuar13cXszBVLPKdB1gDUfPdme2d2qRJIXEC6MU=; b=nGeFLU0xPe7OReus7IgmuB7pmrTY0ShD/iJ1GVpB89l7CM6qxaJJwM/YPB/sgkwYQA Bc0uU5HRbv91fnWZe57dLYYAD+gm6rpxOSSue5I2r00isXW8a2D8cmIkFCwegySZFiQV prZS8L5HMXzmQ5A107RC/M9G+xQVrox2SVJxEORY58GzNE2re52+wZQBIl0DCh6ChFYJ ZfHwEvpvFOBb+43F49BrQrCgXL15XcUvXJSiEIqrAc0TvBdHRemFL+5Acv96uFrFZpX4 lY5x2UNjKyEaYGC7eV0ljazdjhvXtSNbCmTAH1LD7xerVaDGn/tPZb0wCaKvk16bLO2L GUJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dZY0D9qs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j16si16638675edj.401.2021.03.23.11.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:13:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dZY0D9qs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7CFD7806F1; Tue, 23 Mar 2021 19:13:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dZY0D9qs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 69A4081FB4; Tue, 23 Mar 2021 19:13:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 5215280200 for ; Tue, 23 Mar 2021 19:13:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x331.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so11377453wmj.2 for ; Tue, 23 Mar 2021 11:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MED0Cuar13cXszBVLPKdB1gDUfPdme2d2qRJIXEC6MU=; b=dZY0D9qsU0Vxcuyqb9XlT9uTjhIxTud23DiAPueX4LEGXunjqKESg6h63WwrJzXeZy HFPjqaq2WqBxnwPk6KYxuCacP3ymJn+lL75R9lkd1Ztt6zUiK0xqhoyf+QXu2fcSRj7S hd35hi+1sn+QzTIM+E1m/b9jkSwVFVIgPYyE7Ym9ay4FR3T0unTazZXQ0CVXY62r7SKG K/zGxenq7VjQZ4bBCcL9pl505LX6TIoOICzeBNdoB6+2ZVHoo9aijaRrkW7CWTEIJUw5 xKVd7K29HH74L2qUUEed0Qt2u+usgzzu/72RbcyEFLPNu6NVbGf5/7ryPvtRZnvQQ9aW /mIQ== 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:mime-version :content-transfer-encoding; bh=MED0Cuar13cXszBVLPKdB1gDUfPdme2d2qRJIXEC6MU=; b=E/K2j3ALdXmJdZUR6LprvHFoJv6Qm846LLN2DkeyzpMwzc5EIYJ54oor1J2jmUrjQW zNILQFKwrdvlrR5BvqA6b0IBqLZ2Vg3E4ke2xOHJuNeJIKGtwjEyu+tLHTacNHtNrw5T jckxdUPTuQoojvAE2zO8j6CNOfkMQYo4apKAaekmwYjISVtKbpLbdSv1uSSVk4dIY6VP 3o8dgbDcaZBK+8fDcgROiNKSdAGbf8Qgfkuc4+CeuNOjWu4kyWDPCmVYgY/n8pZ/fW9m Ef7InLatl1zA22rJKPpAPNi0oCaDW1yssbB6x5m6f34Tcf/R0rR1WGMjsJ97y13Qou8n Eu8w== X-Gm-Message-State: AOAM530O8Ln3sOw4EXApVjqpvOfotlpx6Al9ageg6pjlGxgJDVqojMVi 8OvW6PE2Bp3wjEGVPKLjAjQ8FA== X-Received: by 2002:a1c:c20a:: with SMTP id s10mr4532773wmf.144.1616523203860; Tue, 23 Mar 2021 11:13:23 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id o15sm18778844wra.93.2021.03.23.11.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:13:23 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: Add a locality event on the eventlog Date: Tue, 23 Mar 2021 20:13:20 +0200 Message-Id: <20210323181320.1186699-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 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.102.4 at phobos.denx.de X-Virus-Status: Clean We are currently not adding any events on the eventlog apart from the SpecID event. The locality event is mandatory and must be logged before extending PCR[0]. The spec description is "The Startup Locality event should be placed in the log before any event which extends PCR[0]. This allows software which needs to parse the TCG Event Log to initialize its internal PCR[0] state correctly". So let's add a locality even during the EventLog creation, right after our SpecID event. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_tcg2.c | 50 +++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) -- 2.31.0 diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 797d6eb134f6..a89dadcb22e9 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -513,7 +513,7 @@ static efi_status_t tcg2_create_digest(const u8 *input, u32 length, sha1_context ctx; sha256_context ctx_256; sha512_context ctx_512; - u8 final[TPM2_ALG_SHA512]; + u8 final[TPM2_ALG_SHA512] = { 0 }; efi_status_t ret; u32 active; int i; @@ -530,27 +530,35 @@ static efi_status_t tcg2_create_digest(const u8 *input, u32 length, continue; switch (hash_alg) { case TPM2_ALG_SHA1: - sha1_starts(&ctx); - sha1_update(&ctx, input, length); - sha1_finish(&ctx, final); + if (input) { + sha1_starts(&ctx); + sha1_update(&ctx, input, length); + sha1_finish(&ctx, final); + } digest_list->count++; break; case TPM2_ALG_SHA256: - sha256_starts(&ctx_256); - sha256_update(&ctx_256, input, length); - sha256_finish(&ctx_256, final); + if (input) { + sha256_starts(&ctx_256); + sha256_update(&ctx_256, input, length); + sha256_finish(&ctx_256, final); + } digest_list->count++; break; case TPM2_ALG_SHA384: - sha384_starts(&ctx_512); - sha384_update(&ctx_512, input, length); - sha384_finish(&ctx_512, final); + if (input) { + sha384_starts(&ctx_512); + sha384_update(&ctx_512, input, length); + sha384_finish(&ctx_512, final); + } digest_list->count++; break; case TPM2_ALG_SHA512: - sha512_starts(&ctx_512); - sha512_update(&ctx_512, input, length); - sha512_finish(&ctx_512, final); + if (input) { + sha512_starts(&ctx_512); + sha512_update(&ctx_512, input, length); + sha512_finish(&ctx_512, final); + } digest_list->count++; break; default: @@ -1004,6 +1012,8 @@ static efi_status_t efi_init_event_log(void) struct udevice *dev; size_t spec_event_size; efi_status_t ret; + struct tcg_efi_startup_locality_event locality_event; + struct tpml_digest_values digest_list; ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) @@ -1040,6 +1050,20 @@ static efi_status_t efi_init_event_log(void) event_log.pos = spec_event_size + sizeof(*event_header); event_log.last_event_size = event_log.pos; + /* Add a locality event before PCR[0] changes */ + memcpy(locality_event.signature, TCG_EFI_STARTUP_LOCALITY_SIGNATURE, + sizeof(locality_event.signature)); + /* + * Locality 0 is designated as the default Locality. This is usually + * the platform’s boot firmware, OS and applications. + */ + locality_event.startup_locality = 0; + ret = tcg2_create_digest(NULL, 0, &digest_list); + ret = tcg2_agile_log_append(0, EV_NO_ACTION, &digest_list, + sizeof(locality_event), (u8 *)&locality_event); + if (ret != EFI_SUCCESS) + goto out; + ret = create_final_event(); out: