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; } From patchwork Fri Dec 3 03:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 520181 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp340275imb; Thu, 2 Dec 2021 19:55:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMmnpiHYp1lJwIBKcc8FTtniPGKx46Sc4SPULhzyekDffip+S1OSG1hhTeeyk5DHYEZUdM X-Received: by 2002:aa7:df9a:: with SMTP id b26mr22603415edy.107.1638503712527; Thu, 02 Dec 2021 19:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638503712; cv=none; d=google.com; s=arc-20160816; b=kCy3+OiYxCx4XnA/SHe0nN4ayV/yyEIpl6kyuwcOSsfupx5JGfSkrvmpMPtmatmpN+ +4VdVu1t+5Nt7HjeV/dERbGQTfQgVCFM5UP1PMdXmEBA6Ga8/zlcYjMLxlHAnv9suD71 L09YqWv1BZHX5khHs3BVlqLGgeQDLaqo5XTh7gLpJ/FkYL5rKAMvCZCROvHquGtYdO1f tPPTIZd7Kp7oINDX+63G0kqdxc5Cg9GCxJduk/jen0vcAvz0PGu6wXjCNTwrqz5hmARM 9+4g0zxum9P/q4vHurtUUnejCc42tD+5VdhryQeHb1oz3lmjeXMLoAB0Hj1KRyQ77cym KGxA== 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=PjeEgqGuWSuhB/+vrig2LM1FErcEwda+t2mT9RS4me8=; b=vTYUVZRTkC1Rua1ynwN7VWi7gQ/vpAgTgPzR2Vv7BhTPVF0StXTsxdNntBLbVsc3Vg NeDBev6mLR3YwfaqDGeH2jXNyJmF0G9ogs+D7XzBzyQs1QwGGRyoKICiGjVfTEv/sdHf jDscIOnZv5ksgYB+aMSZUigtg6/nLZllDx4vzWtcqLDl0Yof/95vxBjr6v5ssgEjnW7x 8M25fEpGXyBjduZT8Zhx2oFG/tWLjZW++si/Pm3A2O3yn7nzSf0Yg58gmS9poH+x/DTU 8m+acCoEiJ+NOGL3hKza5lQVVnO/DAnupvWxxJkk5rRV+snE3lifSKYblsOzDaR1q9SN Y6xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OVq/lr4r"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id a8si2794234edy.288.2021.12.02.19.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OVq/lr4r"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 3BDC581435; Fri, 3 Dec 2021 04:54:58 +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="OVq/lr4r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E6A2E80605; Fri, 3 Dec 2021 04:54:51 +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-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 3291F80605 for ; Fri, 3 Dec 2021 04:54:45 +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-pg1-x530.google.com with SMTP id f125so1830273pgc.0 for ; Thu, 02 Dec 2021 19:54:45 -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=PjeEgqGuWSuhB/+vrig2LM1FErcEwda+t2mT9RS4me8=; b=OVq/lr4ruEC3KG0sDPtr6g6pKFMPkl97eQMtPuKUi3nmgS1RNGCDMuB9n6Jg8Y16S8 syJ34RUYPQTmCENvT/D4TcGhus0/Dj5nnOXNxKWix9rsyI68PdeGKH5q7deNercjRim6 msldKCZtHzLudGl8fr6rx26NwFHvgX/wNYhLaLVY8m8qtGMTECz5TMpj4ManOKOCH9Se ItYUrdnFv1fKHMTrH/EIM2X8YF50/qQwB3vYEm3N81qb5lfaRtFVZ5DMC5GjtPjsx7T+ Kqw6V2nNLqgV5OpP64ULB1/Jk3gJnNC3OVPyAETvdAAxOsNT2okofLJDi3mRRYutUvfc rOxg== 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=PjeEgqGuWSuhB/+vrig2LM1FErcEwda+t2mT9RS4me8=; b=wIVKDAqSVIxYbzgmkfsW3qnWaUb6fgjQ6HruaFZ1F9UFmtTZ3B7qDTZv1t2rPmfcFg Y+g4aeoMMVHfjSzyMsWlZIlQ5xl574avaF7k8yPbNtb4csPShiEM23CwSsVcrnYnOItd jm7+TiYNVQvQKibbzJt0NRnKu6hlW9LcREObFLtbj1tSSfB9RTcc4YF518PsiCcRsc7l VTAM6j9AwWv+3FhDZ/428ejEZtILCnG0C48wq85M0KK2qd/8yVl0hd46BNz/D3WDfn4b yYg7a0RXc+c7nLCchzwc2r40GFaND76uhkHe4jrxgU+kT5NFpI6wModWI9gKuvIupDlJ pLYA== X-Gm-Message-State: AOAM533qziGiTUB09D1ie4c9sXGEEU4siF1N0EtYc8jQxNW/aWHrGpAP fDgtSwtFjDAZkcoZ6NVzEG7pmWfAqOQiHw== X-Received: by 2002:a63:903:: with SMTP id 3mr2691929pgj.356.1638503683704; Thu, 02 Dec 2021 19:54:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:54:43 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH 2/3] efi_loader: check tcg2 protocol installation outside the TCG protocol Date: Fri, 3 Dec 2021 12:58:14 +0900 Message-Id: <20211203035815.27433-3-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 There are functions that calls tcg2_agile_log_append() outside of the TCG protocol invocation (e.g tcg2_measure_pe_image). These functions must to check that TCG2 protocol is installed. If not, measurement shall be skipped. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_tcg2.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 6dbdd35f29..2b7b7cbbae 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -972,6 +972,9 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, IMAGE_NT_HEADERS32 *nt; struct efi_handler *handler; + if (!is_tcg2_protocol_installed()) + return EFI_SUCCESS; + ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) return ret; @@ -2189,6 +2192,9 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha u32 event = 0; struct smbios_entry *entry; + if (!is_tcg2_protocol_installed()) + return EFI_SUCCESS; + if (tcg2_efi_app_invoked) return EFI_SUCCESS; @@ -2239,6 +2245,9 @@ efi_status_t efi_tcg2_measure_efi_app_exit(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) return ret; @@ -2264,6 +2273,12 @@ efi_tcg2_notify_exit_boot_services(struct efi_event *event, void *context) EFI_ENTRY("%p, %p", event, context); event_log.ebs_called = true; + + if (!is_tcg2_protocol_installed()) { + ret = EFI_SUCCESS; + goto out; + } + ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) goto out; @@ -2293,6 +2308,9 @@ efi_status_t efi_tcg2_notify_exit_boot_services_failed(void) struct udevice *dev; efi_status_t ret; + if (!is_tcg2_protocol_installed()) + return EFI_SUCCESS; + ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) goto out; From patchwork Fri Dec 3 03:58:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 520182 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp340370imb; Thu, 2 Dec 2021 19:55:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOMOE5brjUGnhv4b8teF5XqTujaIkpnHfwTmYi5scFWgXvJM/Rb2z+2sitA2RkmZTlco4R X-Received: by 2002:a05:6402:3589:: with SMTP id y9mr23940687edc.44.1638503721473; Thu, 02 Dec 2021 19:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638503721; cv=none; d=google.com; s=arc-20160816; b=dlfDC+Kf0/EYm11N3swNjg+nL8FuOFw6lsriY8xOh+E5zbc6SMgBoLkq7TiclDOVqV hnLnIe3GkyS5locDYEvEes3k4vik/7Frgt/rUfZjVS76zocuLYnIbv3DLIJTJoFNx7Vf sSB0dwUg+iLdTvt3mLy4MZFxwN05nTQnG3gy+KG1D/DuAqhIFR0A1J+X10Vt79+9S+B8 lC+aJKRFsgaGLUj4DwrWv97gnFbyOy5skBmma3EJp27n/g2ZWNBIR7SwCpACeRRnccKv XQD1FJBHWMQ1kQLeiNE0AMNMAHy5H2rI7kzU7WgLAccLpD7TlhNhZL0tTB7m7AsXh7D5 uqTg== 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=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=EN9AycpJPq0718b3MglODT0YkzWL6MRuV3glxitH1belp1MAxEXaEkpB8z/VR/ZOSS BbhloFU3Gp/81JBoZ9jckGBZmeJztZLoA/jU5nJWC1XpnFFUa90n4m73sntPqSOMub6p P6Z/t39Jxzw9cvmC9YTq6SslseolcD0G1/C7UrXVYAG2WSRkGy7MsWGVXCyQRbFdp8JX gwTf5YD/FYvdoGRKHKPCsndHQUNZjWMgOWkqBsEbn92X3ZdCAjhdKy6X4tmKVY7qmQgz ILvk0kzjCq9lNRgCq9HjeDdP5Hoqy4zyO+ldeE7QAtZ0T0WqCQg05zLUwP/qauc3hOPm +u4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YuoRD2Zn; 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 qf15si2920158ejc.553.2021.12.02.19.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:55:21 -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=YuoRD2Zn; 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 B87BB811B9; Fri, 3 Dec 2021 04:55:06 +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="YuoRD2Zn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E353810EB; Fri, 3 Dec 2021 04:54:53 +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-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 A366A80379 for ; Fri, 3 Dec 2021 04:54:47 +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-x635.google.com with SMTP id q17so1175054plr.11 for ; Thu, 02 Dec 2021 19:54:47 -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=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=YuoRD2ZnG0qf1J6Ch1aFcTPvF3w/dVCqCIitCi1fqXjXyeRMqejnjAbrrYpN4TnBpb 6NYq9AcVPdtiqZLDS/DaSqmK4sQCfAaEpn5mwlcqvkvO5PiCi5Bv8ObKIqT/7dDQ2UPZ qaVRqN0XVUHfGLnKs+59QtImoI8jqZbgRiFa2hn4WbfgxjKGerdiYEJCiF+Xv2QKAook 6hIHbhNxvwaY/Rkn1kPjnROSs5izD4koueqTabSgCcmj1WIakn3v1XALKKMk/b8izeC8 oYZBDIoD9CqCBx7WhEISCT9l1wzXRhFQ5RPMoyd5IH0h4VUDymiG7G6DbDqopVMQgHm8 TazQ== 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=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=eWfayLhCWFzO+VRN92u6s8yMQlD5AFg4UNxnUKg9h6iCaYI2Jzx1qmd/X5C2WgwhRv +PZzJgFrIGsnD/eHuVA2hgmyEqknzjLRq085t3XXZbJ+qmi+MPsIwkeS+Nb0o8oEQOMC 8XzLxvVGBm+FrAws1/rPBGWLupNdl3FiicuzYYkoLI4avvTqVnKI743I2wi4wmzqyMRR 8ManVYTwJMOKs47g7bvE3MwYBxffQldyUECO5BYX45XaUd2m5hkkMF49HBjAI6AgtyNZ ofs+YvtWFo3hZss0duOD0Tm7lL4u9/KPnU/DWZ+c9bJxtDHclT1yp6qJ9lPxmHp36Jov SoEw== X-Gm-Message-State: AOAM531+rhDa5GeBnMyaI1O7YAm2p0Y7qMUnbImn+OVialL2RqWRKRZV h1uypKXAkGFuLZSqfXnuooCdRbEpiEmPOw== X-Received: by 2002:a17:903:1c7:b0:141:e630:130c with SMTP id e7-20020a17090301c700b00141e630130cmr19974523plh.80.1638503686082; Thu, 02 Dec 2021 19:54:46 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:54:45 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH 3/3] efi_loader: correctly handle tcg2_measure_pe_image() error Date: Fri, 3 Dec 2021 12:58:15 +0900 Message-Id: <20211203035815.27433-4-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 When the TCG2 protocol is installed in efi_tcg2_register(), TPM2 device must be present. tcg2_measure_pe_image() expects that TCP2 protocol is installed and TPM device is available. If TCG2 Protocol is installed but TPM device is not found, tcg2_measure_pe_image() returns EFI_SECURITY_VIOLATION efi_load_image() ends with failure. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_image_loader.c | 11 +++++++++-- lib/efi_loader/efi_tcg2.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eb95580538..426f096574 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -934,9 +934,16 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, #if CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL) /* Measure an PE/COFF image */ - if (tcg2_measure_pe_image(efi, efi_size, handle, - loaded_image_info)) + ret = tcg2_measure_pe_image(efi, efi_size, handle, loaded_image_info); + if (ret == EFI_SECURITY_VIOLATION) { + /* + * TCG2 Protocol is installed but no TPM device found, + * this is not expected. + */ log_err("PE image measurement failed\n"); + goto err; + } + #endif /* Copy PE headers */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 2b7b7cbbae..c19f73dc10 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -977,7 +977,7 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) - return ret; + return EFI_SECURITY_VIOLATION; switch (handle->image_type) { case IMAGE_SUBSYSTEM_EFI_APPLICATION: