From patchwork Wed Mar 24 07:43:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 407798 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp186907jai; Wed, 24 Mar 2021 00:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcCqKhqDy7+8mW0pKtnhFTyo+9FFf+PRE+ThMHZcHhk54UBMHLRfIlofj755PcqsKHqanF X-Received: by 2002:a17:906:4150:: with SMTP id l16mr2297875ejk.90.1616571799745; Wed, 24 Mar 2021 00:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616571799; cv=none; d=google.com; s=arc-20160816; b=VTafNnQI6aVAe2Q3qtSL6mgbAj7n3yuVS+9a47Pp/QrwZpfifv0c+HO8fscMITnEYl IKNflxUg4lUK7+ru//k3KUI/uNkIkUr7W/++TAHIbQW+1HjQ4ihcSlL+j4isziq/UgYN WEa8O2oKB5vhcT5qFDE2UCTIidpNVtccUWL+QO9WGcsLgs9+WszdZGnsnohs/WUaNLBb kK2qrwCgkcXievEPbP3gVXPXchVcatXD+XFb9H9bw+UkPOqKmt1R+4x7mWn9lxNDmci0 HhwKjp1XgE9PquwZWM4ruWnkjgk0qM9EzoEMmzAaFAk3ZvHdfPxdY48hlKY+JhrGR/He C31g== 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=JMvqIKj8941b3Voj/MLSLjNHGkrcUVHtawmze7SLWp4=; b=mvVtxm+0VxXfZgpg7sukt6VvvbAjg/54ShFynIBCoV6SCfOcUPknc+S8FSZNIgY05A JKoSSPKRnytI9dZFV0QyaTxDabw3Gmo7mB02lh02kD+Tg7ve9K37b+YsWDUJM2vHF8xV rvJqQSFY4+LXQwpdSQnmRk9lddea4XW6Vi3TreT3EU5duLnTgugGS3O8zzzCGbzBmOUW 0JrHIq66eS0jSeW6oOmWPGLDHLjdtkuB+vPnyosGhjydW3uZyYrqG3c7VPCnxaHP+gy+ 802fpnNPFpSoZWPyXhvmybt0cGqV3xxJiXBSXCW9L4W6gYE25owLazj0p3YzJmDth5GP lY5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gqm9UJvJ; 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 w18si1104244ejy.196.2021.03.24.00.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 00:43:19 -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=gqm9UJvJ; 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 27FAB801FC; Wed, 24 Mar 2021 08:43:17 +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="gqm9UJvJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 91ECD80462; Wed, 24 Mar 2021 08:43:15 +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,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 722118006D for ; Wed, 24 Mar 2021 08:43:12 +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-ed1-x52c.google.com with SMTP id b16so26506249eds.7 for ; Wed, 24 Mar 2021 00:43:12 -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=JMvqIKj8941b3Voj/MLSLjNHGkrcUVHtawmze7SLWp4=; b=gqm9UJvJUUAtAvl4RsMYvCa+fKv/Vd2rAAnoWrAeaIVgSsOcAVsuIzTKLYQfdQSKpe vBxsyzwun6JkFScpNaZkJH6bFWuVynPN1c32UQc4xRyy+pgckQaZQfMbNBITE5kx7ceX 1ZA0cbNF9AXbhYdxms4nVKO8tu45I/ZMNc64U7QflW1H5UFhbUAWWyC5U5vUmaFvopX9 cg43alw//44LyKECftlHMj5cpTlXZzAua/Wo9lC3xbNNuHNgyOWd8FavvPKDZAvBljO7 gV5jbU5sB7bddN6bZHWX+YvHCPU481uXpP3gWFgL6ZPiFxVPbHi2g/P+dxgDfzjrSvHP Hd9A== 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=JMvqIKj8941b3Voj/MLSLjNHGkrcUVHtawmze7SLWp4=; b=Qw197j/915Z1PK+tE8loMs3UBtdXig5nyKO6Kd6zCuBiGJJHgtddqCY6/CEsbmbYMA YhdIUn4UxH2mka27VW0+fwOkzlfYaogoBInoNNXzSYMnamAE/bs0glDzZ02P5aJMOy/5 jxMjW0Qoet1UijxG7OpJxjuae2V1H1PVOl2+n0bOWIyas08rif3GX8SC8NTDmn0nJkYM QmLnNFlgirff2HqxIhw7Cw27f5bzOBTcz2ttZYYU/jOhxvPZ7WvXHaCKEJBEg71vCk9s xYAoq70AR6pkI6tZoAHfjgGCNYJnj8LsN8EKmn2RLwbjWgIAlzV5NYnrjn6bkgBk0z4X rACQ== X-Gm-Message-State: AOAM531bxHezeBZ9EHyeX729LGT+seyuTjnV3q0A5CAm7Qq0jYt2rQNF g6uw21U5kPWWuS6fq2mkM8j3Gw== X-Received: by 2002:aa7:db01:: with SMTP id t1mr1983361eds.77.1616571792082; Wed, 24 Mar 2021 00:43:12 -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 jv19sm510016ejc.74.2021.03.24.00.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 00:43:11 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH v2] efi_loader: Add a locality event on the eventlog Date: Wed, 24 Mar 2021 09:43:08 +0200 Message-Id: <20210324074309.1192430-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 --- changes since v1: - v1 was missing the required headers changes - exit on tcg2_create_digest() failure include/efi_tcg2.h | 13 ++++++++++ lib/efi_loader/efi_tcg2.c | 52 +++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 13 deletions(-) -- 2.31.0 diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h index 40e241ce315c..eac76774d7ff 100644 --- a/include/efi_tcg2.h +++ b/include/efi_tcg2.h @@ -72,6 +72,7 @@ struct efi_tcg2_boot_service_capability { offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03" +#define TCG_EFI_STARTUP_LOCALITY_SIGNATURE "StartupLocality" #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2 #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0 #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2 @@ -120,6 +121,18 @@ struct tcg_efi_spec_id_event { u8 vendor_info[]; } __packed; +/** + * struct tdTCG_EfiStartupLocalityEvent + * + * @signature: The NUL-terminated ASCII string "StartupLocality" + * @startup_locality: The Locality Indicator which sent the TPM2_Startup + * command + */ +struct tcg_efi_startup_locality_event { + u8 signature[16]; + u8 startup_locality; +} __packed; + /** * struct tdEFI_TCG2_FINAL_EVENTS_TABLE * @version: version number for this structure diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 797d6eb134f6..31c80b21d8b5 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,22 @@ 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); + if (ret != EFI_SUCCESS) + goto out; + 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: