From patchwork Fri Dec 3 03:58:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 520179 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp340035imb; Thu, 2 Dec 2021 19:54:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPLGkFrkxrg4NNyFRX3XnKmKOjUoKuupZXt2nr6JGP50OcQE2kfceIEDBLTGBk4a7AE+ku X-Received: by 2002:a17:907:6d20:: with SMTP id sa32mr20455342ejc.108.1638503692158; Thu, 02 Dec 2021 19:54:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638503692; cv=none; d=google.com; s=arc-20160816; b=yqpkLtfnsdWxgERyq5W93yJMfDnyzjrftVDHC2ktiYhQTACsAQIT6OVRbXRAt5taUL 8UMVFhgPEAgHW7xGfvMg2iQHwsdbYNQfZ+50ojkOJD/07jmgQt05ibu5G8YIrLWFw1DD lDDJYtcT8q1ZQP0m6EbT8/Ov6D/SWnPp4AFSL7iURxem9KhcROhRHbJX0HRqVHgB+jqp wUw02EriC/Tdi7suW7SY8dAiKUFOJMP6yp12LVlZ29SFc0YYh0o3SKtde0xogA7vVKDH FYNbaR1OPM4l6hGVD59ufP3zzw77mCglsXIiEJ9QRAq6eZpM/BEhQMH++iT/8wQZSgSV fnAA== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=u3BT8VQKhwEOjbCmcX8DaN25j5+OtfGNFh7D5LB93Ps=; b=pDzpSeNsJq83LHTgn0orv9md4J4PrxmO5J/QmGd21zJ9uzfcLn3n17+AtR9LMJFifB o0bm5W5/uXjWCNqrRaaLEA9+nhnqeL4Pju/999J8XperZHWN0b02ok25AG2KovewClZI 4RmEQBkXbxFvtFSOApvX4y9YHPCsTkLcJqRt0mIR50deQeIbgRBM+w0DXz1ujUABrVWE sYid7iHpBbMfDpFYHPScH/wqGd8kO/U29HqPf0c5QRjE7MI3Do9WMS1l37Fv0QUh93VC jMMl6cQ8I8T/JGMYPOscX/zxL5gNUOy5/i6GJcEOHHZPOYSo4/T+Z8W4NfGfsxI3+m5n YBfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pwul6V5A; 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 nc26si2846031ejc.455.2021.12.02.19.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:54:52 -0800 (PST) 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=pwul6V5A; 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 1200980F56; Fri, 3 Dec 2021 04:54:49 +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="pwul6V5A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E468F80F56; Fri, 3 Dec 2021 04:54:46 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 07E108022E for ; Fri, 3 Dec 2021 04:54:43 +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=masahisa.kojima@linaro.org Received: by mail-pl1-x634.google.com with SMTP id y7so1238130plp.0 for ; Thu, 02 Dec 2021 19:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u3BT8VQKhwEOjbCmcX8DaN25j5+OtfGNFh7D5LB93Ps=; b=pwul6V5AAXBtuSRfsu9e0cVofbQ1Qm7HclL3WqLvjSSE0zDNSEGRsU5OfKl8aKvPld Jb0nf40zUODzRFrTyfrIxXpVkx/HUI+MTAk7SHKtlcjUryf25aZeo4U3fFky31DmWguj nb/59iXxbjn2jyRtIEXbaZBpjALQ5hbjx/yPCSAUzFLIALbL3v99hP4hiobJKZWV1S2q RBrde8gZch/qjOLPzbiLvJb+JZEOMqbLpYVX0LXsUa8Le2MV07SswtUcXzehPn3Nh/+j gGrvwqemdznRmrXNOYlnKyGb2qlSOwDrwP1yEyHG7kDCpz+D4h0TwAglXLCpbOt7Qpil bSCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u3BT8VQKhwEOjbCmcX8DaN25j5+OtfGNFh7D5LB93Ps=; b=PhUP+3yVL9Dfujv8ordmlbnvyuLbB9BRYx/pxlHTbXIDFtFkC0nBN1bbTTL5FodHdS 48mZ9+p4MY858gzjEuwFVMsCZ5IwZhv0mVTmYTB0VEuFieW+QR981GyXjavN4pRVCR4U hNqZNkCvAf8/Bz34FYrYshTv6FBOz368+byKOwv6k/3P8aXoKYww/rzKmnNW6ZKvF6E/ 6RLWXNnSFMZN+Iimt1jbpnymx5IHSsBvPisp6S7u+g7YhlDHIg5vpkLp2ikAmlMhZmo4 pXmvJhgMt2thTB7IsXgd5k264nMgwKDSR/KFOl4Sga9n+kt5CrmcKvLfcbB4M2vOWsYD Pekw== X-Gm-Message-State: AOAM532VOqbK9Q7JeoMdjtkygkT9FKXD90r1gSvyxRXQRS08CT3D9fxq LKbWK2J76xYtTskDHZXZjbb45Uf0Qvc7Ww== X-Received: by 2002:a17:902:7b8d:b0:143:95e3:7dc0 with SMTP id w13-20020a1709027b8d00b0014395e37dc0mr20183826pll.21.1638503681364; Thu, 02 Dec 2021 19:54:41 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id y32sm1301334pfa.145.2021.12.02.19.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:54:40 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH 1/3] efi_loader: efi_tcg2_register returns appropriate error Date: Fri, 3 Dec 2021 12:58:13 +0900 Message-Id: <20211203035815.27433-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203035815.27433-1-masahisa.kojima@linaro.org> References: <20211203035815.27433-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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 commit modify efi_tcg2_register() to return the appropriate error. With this fix, sandbox will not boot because efi_tcg2_register() fails due to some missing feature in GetCapabilities. So disable sandbox if EFI_TCG2_PROTOCOL is enabled. UEFI secure boot variable measurement is not directly related to TCG2 protocol installation, tcg2_measure_secure_boot_variable() is moved to the separate function. Signed-off-by: Masahisa Kojima --- include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 2 ++ lib/efi_loader/efi_setup.c | 2 ++ lib/efi_loader/efi_tcg2.c | 65 +++++++++++++++++++++++++++----------- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 67c40ca57a..f4860e87fc 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -525,6 +525,8 @@ efi_status_t efi_disk_register(void); efi_status_t efi_rng_register(void); /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */ efi_status_t efi_tcg2_register(void); +/* Called by efi_init_obj_list() to do initial measurement */ +efi_status_t efi_tcg2_do_initial_measurement(void); /* measure the pe-coff image, extend PCR and add Event Log */ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, struct efi_loaded_image_obj *handle, diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 700dc838dd..24f9a2bb75 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -308,6 +308,8 @@ config EFI_TCG2_PROTOCOL bool "EFI_TCG2_PROTOCOL support" default y depends on TPM_V2 + # Sandbox TPM currently fails on GetCapabilities needed for TCG2 + depends on !SANDBOX select SHA1 select SHA256 select SHA384 diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 1aba71cd96..f58a4afa7f 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -241,6 +241,8 @@ efi_status_t efi_init_obj_list(void) ret = efi_tcg2_register(); if (ret != EFI_SUCCESS) goto out; + + efi_tcg2_do_initial_measurement(); } /* Secure boot */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 5f71b188a0..6dbdd35f29 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -153,6 +153,15 @@ static u16 alg_to_len(u16 hash_alg) return 0; } +static bool is_tcg2_protocol_installed(void) +{ + struct efi_handler *handler; + efi_status_t ret; + + ret = efi_search_protocol(efi_root, &efi_guid_tcg2_protocol, &handler); + return ret == EFI_SUCCESS; +} + static u32 tcg_event_final_size(struct tpml_digest_values *digest_list) { u32 len; @@ -1664,6 +1673,14 @@ void tcg2_uninit(void) event_log.buffer = NULL; efi_free_pool(event_log.final_buffer); event_log.final_buffer = NULL; + + if (!is_tcg2_protocol_installed()) + return; + + ret = efi_remove_protocol(efi_root, &efi_guid_tcg2_protocol, + (void *)&efi_tcg2_protocol); + if (ret != EFI_SUCCESS) + log_err("Failed to remove EFI TCG2 protocol\n"); } /** @@ -2345,12 +2362,37 @@ error: return ret; } +/** + * efi_tcg2_do_initial_measurement() - do initial measurement + * + * Return: status code + */ +efi_status_t efi_tcg2_do_initial_measurement(void) +{ + efi_status_t ret; + struct udevice *dev; + + if (!is_tcg2_protocol_installed()) + return EFI_SUCCESS; + + ret = platform_get_tpm2_device(&dev); + if (ret != EFI_SUCCESS) + goto out; + + ret = tcg2_measure_secure_boot_variable(dev); + if (ret != EFI_SUCCESS) + goto out; + +out: + return ret; +} + /** * efi_tcg2_register() - register EFI_TCG2_PROTOCOL * * If a TPM2 device is available, the TPM TCG2 Protocol is registered * - * Return: An error status is only returned if adding the protocol fails. + * Return: status code */ efi_status_t efi_tcg2_register(void) { @@ -2373,8 +2415,10 @@ efi_status_t efi_tcg2_register(void) } ret = efi_init_event_log(); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + tcg2_uninit(); goto fail; + } ret = efi_add_protocol(efi_root, &efi_guid_tcg2_protocol, (void *)&efi_tcg2_protocol); @@ -2391,24 +2435,9 @@ efi_status_t efi_tcg2_register(void) goto fail; } - ret = tcg2_measure_secure_boot_variable(dev); - if (ret != EFI_SUCCESS) { - tcg2_uninit(); - goto fail; - } - return ret; fail: log_err("Cannot install EFI_TCG2_PROTOCOL\n"); - /* - * Return EFI_SUCCESS and don't stop the EFI subsystem. - * That's done for 2 reasons - * - If the protocol is not installed the PCRs won't be extended. So - * someone later in the boot flow will notice that and take the - * necessary actions. - * - The TPM sandbox is limited and we won't be able to run any efi - * related tests with TCG2 enabled - */ - return EFI_SUCCESS; + return ret; }