From patchwork Tue Dec 7 05:15:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 521616 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5711313imb; Mon, 6 Dec 2021 21:11:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFZV5hSEXyDjlBYaPw4hvZHNP5u9dm4lW8eijziq3xt3B5sjyoPasB1UOMr7huCyD1e6JL X-Received: by 2002:a50:ce51:: with SMTP id k17mr5614080edj.356.1638853886405; Mon, 06 Dec 2021 21:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638853886; cv=none; d=google.com; s=arc-20160816; b=PQd8aAEP+0f5j7UAJYNtLgWj5T5cBQMn+mg1wNmzNYdk+eam4tiyO5JRT7KxIruEFK KihNb55vwo1iqNTbeCxOIC1nMKZNGog8Rnz8E7Pc+RW2JMqPOspw8wBEj3Eker9f88hD Ic65OGJnqdnn6DnnfuOipTcVGnqkMrVv2Z39G/aEe70rCpi3InBQmj9s4oLTkjnw7BY+ LED3alpcHVtoqx3WVUBLAe2cwvZFsemVc1IKXydqNJJxZ5OkxxyCBapawFAwQRlfk7kw 7eo8TnpyeniY0L4PyjjvFMxSzNR5bhJNsEpNeia/KAQfyYcE48+7RYecz52GYWo0i4dI uRtA== 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=+sBca1fs/JDQgJP4ZaFL3NNddsDJc0M3jKtMy5Oz9QE=; b=mPOGUuceWl1LEj0ogEHSZP2K+iQKS0+ttnnSiLtKoBNrVrrm4UAm4jMpBWLWwzRm3O KZzcC5B1L9LmQKPCB2gZswvdmtVfnLcfywUXGjAtHPbIzR0JbFzShkq8z4UD8WDgq9GQ 0yngeZZOlMCFVcpKNyltQs33oRPeMxVSpGBWBVNtxWx4bLXuLaI7oj9PcS04wlEnwSFY VOX6uo/Wfc9BKyrF/pdv+Sk2rcjbW/ZZ0lHmDtsEuuoIuGnVsa56RMC2ASA0EGROJJEU 7AcSiLmGz9yo6FScGjEjmTDv/0oF3jgxgpEgC2AGftLSv0W1USwyGkF7CEWnRdrdI0MB U86A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OPmnQGcC; 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 w26si22348973edl.90.2021.12.06.21.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:26 -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=OPmnQGcC; 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 9A3B683383; Tue, 7 Dec 2021 06:11:20 +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="OPmnQGcC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 20E02830F2; Tue, 7 Dec 2021 06:11:18 +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 6A9D0830F2 for ; Tue, 7 Dec 2021 06:11:13 +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 n8so8615305plf.4 for ; Mon, 06 Dec 2021 21:11:13 -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=+sBca1fs/JDQgJP4ZaFL3NNddsDJc0M3jKtMy5Oz9QE=; b=OPmnQGcCxUqYfJ7Veo8LYhN15VtoUMg2p3Bhq1LWj8rlmYxGretU0KDKHcJVpvsp4p sFHRW0C4r/Tbowr4MRncOaKaoTnoCEl3g16zorwR+HAIAv1f76xX5RHCDuvKGxQMQt/J Pr9J2ihto2KunmqduSsgkrnvwEV8LRcKsWTxl7xSyF7bkwkK9VOg/XOPFWVkcUtW9SKw wflyDe9O6isEzvVb4cZkulCgAs1oryE12jY6No/42ef7CBV6r0jSx2w7t80/h/D/Z8uX Yd/mo+8AVpAw5Ea64SJlG42en+F4wfx3gOD2JzZULu5VgklF8+rnJdamK/aTB04A4Fq8 6VTg== 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=+sBca1fs/JDQgJP4ZaFL3NNddsDJc0M3jKtMy5Oz9QE=; b=fJEvPQV7Fl3JdB8TU9H3nFyWG1+3Dei2Xns6T+zhGGCiXwMr1yyy1C/fdRwRn/1cpb hWkA275mR5svD4PeZfz4LJRtPKT8fYTye1a0gawfS0VsOZjCUlHGtwA6iIQihXBnwr5W o8bAR98KLABNy20M07yVt0sBoIrFdg5ZBjY2wXGNz5CqZHiAjCbZfn4/zolmG0SN3u4I 5QTY5hexjzoV+Khl+Bj7RRwlQ1jU0zxA7o9LtndWS2pZvq/FTfY7zwZ0qVcgC6FfpzCg 9GWajY6HfDduUs8ZG9hDjul2NauJlxHhIXQ+VcGE/U3zbdhpBuD8bVvMSor+HVKEhcSU w9lQ== X-Gm-Message-State: AOAM5303aIrOlz2yivROKqaTV7cJRYnfs+vq7NcajehY3YEyltnUM8J4 ovoEGM22rJxtoD0NHMG+wjyK3bRQJ/E1Jw== X-Received: by 2002:a17:90b:2252:: with SMTP id hk18mr3916334pjb.218.1638853871815; Mon, 06 Dec 2021 21:11:11 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q10sm11975516pfk.180.2021.12.06.21.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:11 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v2 1/3] efi_loader: efi_tcg2_register returns appropriate error Date: Tue, 7 Dec 2021 14:15:31 +0900 Message-Id: <20211207051533.5597-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211207051533.5597-1-masahisa.kojima@linaro.org> References: <20211207051533.5597-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 Reviewed-by: Ilias Apalodimas --- Changes in v2: - return EFI_SECURITY_VIOLATION if there is no tpm device found in efi_tcg2_do_initial_measurement() include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 2 ++ lib/efi_loader/efi_setup.c | 4 +++ lib/efi_loader/efi_tcg2.c | 65 +++++++++++++++++++++++++++----------- 4 files changed, 55 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..49172e3579 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -241,6 +241,10 @@ efi_status_t efi_init_obj_list(void) ret = efi_tcg2_register(); if (ret != EFI_SUCCESS) goto out; + + ret = efi_tcg2_do_initial_measurement(); + if (ret == EFI_SECURITY_VIOLATION) + goto out; } /* Secure boot */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 5f71b188a0..bdfd9a37b5 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) + return EFI_SECURITY_VIOLATION; + + 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 Tue Dec 7 05:15:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 521617 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5711421imb; Mon, 6 Dec 2021 21:11:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbwlgzKo8zrl6vykX4p0EfSd2JgO0bZbUhyV5iP/87w1jkRzmqoezkFdln/nb8JTwjs4AE X-Received: by 2002:a50:e0c4:: with SMTP id j4mr5599724edl.239.1638853894013; Mon, 06 Dec 2021 21:11:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638853894; cv=none; d=google.com; s=arc-20160816; b=GEzLO/EgB/AROf4UOalq3Aq7ieQ1uD0jNG/ov+LsYPfkb2VAA1uIRiSC/ViF/b02tF BgnYmLqQttisDPSvYvLC4Cy24sE/lAu9j+aSxWnDvwTx4wCrytDeuC7++GkyPegURsTI Q2wFuhFeXCdnc1Wjg8JzMxcxMq+hu1Dje6N+d04L4eyOvLJO2XCJoWohduikT5/dVXF4 Gw1dRLxQhSpC/ZVcLER3V8KgVXFUpKnTb8iDKsyD/uQ/2+rnVD/DETuC8NOy2Qd5kpYS Xi3OFiSOyvPkzx2PUtRhH6leVvYMXrAEz6GmB8cPVCkKTfPL1Zr5YmCwHfepTo1sBYVS o+Nw== 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=2zBP+B0gjXmBLFHI97p4G8as/h1mPry1Kf6nmtw8DjE=; b=FvWWo4kcoA8zylLJR4jOL0SQpvU6/YOOM1soXGUCoRBg7dolmq0wlRqwjmW0kkHCgg peNxvtynvVpWhLodWSUF53Jn7OTTlNIYFi1Fp6QNV6HEG33KSzELJUuPjZk66jjLT/gs Ptv+TtWHoBSrVmR5kTuf4UEBiTBDaxyx0cKp1R7VQdxWtwC10ovXz9pg41BADeDYw+r5 xyo5PaWiVrf38X2adOnHstkuyhEmbt/N62mdjcIMWT+ErGZ2iO9JybGKh0mm7/TMu0qR rdB7U7i0EzVTEbggQaykgBcfuQwWzShyZ1gbgGbqdecNEp6ZTKCsz4nOoEDIhd/Sgtor X94g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M0hnMl/6"; 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 nc41si26299203ejc.520.2021.12.06.21.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:34 -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="M0hnMl/6"; 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 B62D5833E3; Tue, 7 Dec 2021 06:11:25 +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="M0hnMl/6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9E881833C3; Tue, 7 Dec 2021 06:11:20 +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-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 A3FBA83084 for ; Tue, 7 Dec 2021 06:11:15 +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-x636.google.com with SMTP id b11so8582752pld.12 for ; Mon, 06 Dec 2021 21:11:15 -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=2zBP+B0gjXmBLFHI97p4G8as/h1mPry1Kf6nmtw8DjE=; b=M0hnMl/6HBn0jGOsOiJD64PKjSh790zmxtyOH2Q77YK0QHmKWkxTq39M7g1gX05yZR VkXemtJBWmtu5LMPU3326IMG2FBxx6JWy5mHiVMHRdLu16LlfJnWMrvnVBU4LbUkL/Ar 64T4OwcQzRAOs5kUsNX3N/MHM2SR6M6jCC8o0yKsNi/G3PupgJA2WUPD6oDK0Mwd8fNb /QQvIN5xPaob4kSyrZYGuv6IoRvWl1FkuQohxxzJYxQuPpU5JoPBnSwQupbYN8FhrN/9 qLnWVjdeT3gGyLkGqERtdrjivqMV0jYwEf4Wh/G2eQYGFcivAGXDvJxrtjabp2IAPVvf mCEw== 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=2zBP+B0gjXmBLFHI97p4G8as/h1mPry1Kf6nmtw8DjE=; b=bpbBW+XmxwwRZaCHDYxA1X+OAXlLJyyEc19p6hBhfC/TNWcVy+FI/jt8ewmRD00Zbv rUlPBMTxfdjnH66dhrWxRLsRlJuevzKG2wtf53ZwWiFlXLl95gMVPleBp8Q5OIPMDHMp KFwyW7a6JTmoA2AGJCZpYNIc6OGgoMA6evmjvr/tMSzfeR4lC/1ReO+mu9RbQxiyCP1w Zui7eryqyXZvT+D7A7ybcJADogIkLu3BhIiwX3lHQrC5I/rMOBcIZ/4wFqcp0ULwXVPc 3qSCLGX6OcLPX8MO7K1LEY95gaqMEhwVnULroH4sTb73LFFwdl1jHb9lfdyx5sRkRGyt WqHg== X-Gm-Message-State: AOAM533/uXeVxNahINziDvd+fzBPjhY6Pjfzmmed9zkwHa/cC4IIWMuj WjtOVGF69AnDK2P76uY3Hj66IPFel3deBQ== X-Received: by 2002:a17:90b:97:: with SMTP id bb23mr3883718pjb.201.1638853874152; Mon, 06 Dec 2021 21:11:14 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q10sm11975516pfk.180.2021.12.06.21.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:13 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v2 2/3] efi_loader: check tcg2 protocol installation outside the TCG protocol Date: Tue, 7 Dec 2021 14:15:32 +0900 Message-Id: <20211207051533.5597-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211207051533.5597-1-masahisa.kojima@linaro.org> References: <20211207051533.5597-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 --- No update since v1 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 bdfd9a37b5..59bce85028 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 Tue Dec 7 05:15:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 521618 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5711536imb; Mon, 6 Dec 2021 21:11:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeHOjyKo5cI1NAwjjBpq3nqIy4hWr6uFsEBWEkmpppld6dPU+uS5+iABckEFPtWnQGAtuH X-Received: by 2002:a05:6402:41a:: with SMTP id q26mr5590966edv.387.1638853903063; Mon, 06 Dec 2021 21:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638853903; cv=none; d=google.com; s=arc-20160816; b=oMJkXwgF6Q96Ouki4XWz5WYHqZEpDUGbXXuzYoUUxvKZoG0ez4++i/tjtoXFgyJwmC qZgNbp9PuIFV9EXJ+tkZW8157FZKKz+fP5xgpLlZ3iDGiZ2J+c3lfeC2BMmuMBuFa8Hu /73xZUIurzA6emNcSsv517UZ9CEsQpCb8ixHwa1jAto4txunbm3bkwvvr5UTVJ5ypyc1 3JlhfuQBdS5dPQHeg4RJARgFUJ7rFFFVKie+lEYr9Ziy7WT6W1q3Dp1KD1pJfDc0V1Ir 2CR0PptVwWMiZeslSESyCq64BDhdR2oyIBiVzonPXHRmqlwKJL0NhhwN0y+cUTfa/32Q v+jg== 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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=gFg85gaTmlwhkpPMR0Ebo/gg2tIwIf3nCXZxmorNi+USWW7RZs6Z9YAxDCtJgoXkOP BIM6rxtnJVc74nAllrBTQGUveds+/LNAi3Ic36heT6a570Wlt/HwmREq+JgmeMyirQTR MqeDtXYuOL4XGp9bMYRCcTThkLIeHND8tNC7plq1tPAUw3DplG6zLMTGvjUNPeHArQfO 6nHzhsZ/kcGS2joQuOGi4FJaSHYsq4Zdubpbk1saIYOet2J38zI5htEFnqnWET9BMr6O MMBT49fVtDdSMPAyYWe50XJSTP952kVJy9Rzo3L+y3v4W6Q4bYsGZdvwZj1hL6i3KgXc e3AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W1OXQmqj; 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 q2si20290160ejx.746.2021.12.06.21.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:43 -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=W1OXQmqj; 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 13D138348F; Tue, 7 Dec 2021 06:11:30 +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="W1OXQmqj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8057D8345C; Tue, 7 Dec 2021 06:11:23 +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-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 6FC86830F5 for ; Tue, 7 Dec 2021 06:11:18 +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-pj1-x1029.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so1040304pjb.2 for ; Mon, 06 Dec 2021 21:11:18 -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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=W1OXQmqjnMY54k0nlWkTmHRSl5zpc/+D5faSYoj76GQS1v5DHvuovpsJ3JI8DyxQN3 6hXGeWVhgMXlSFoZtD622LL4aj5/KJ3vENw0AbKM4LR0QNuO0D+J5nBdhs3s/1gsRDsx BCsTBpa2GkDappFChgOJ/7DvDB6dw05Z3rj7b37J7+FRi+98v7+WOan7xTKyJoqAT9De yD/nEhPZJV4xMGXM/kF5ca9VDgRki4FIKHU2ArN6reWRnvRjQctIbMc4bvgYo4DvOgqP 9vFHf+xCa21EvphSW7osTJO7GF1FI3iNmJxEFvZeZDJ+ZHixx6LbIFl6ISmAY648z1vX dSTw== 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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=gzrF14g4DXOy8BFZZolXlRez5PDaVIDCu/Lco1pC+5uljtTwiZHIWTDDoSn8HCNEBD V09EYCuihFwCk937T8IvyWxyVdJZgjWmjexJCeC0KSGWJramys1cBPPHDuv2+hILLRT6 kyFSIPQn+qY7UdHrKFut+vG+7Mi3LIwc04UJvl80FuKvsnzCVR5Ap/xdgtcdKE5Q4/bi ADFBmyUb4GFIqjE3Uimi+42iAKXcPzxZgPMNqutfw41kr+2AHKLhThbBW1homj6AvBgH haOzyr8RzgtBpUi5h8a1JOKoIrB5sKuzqTp/3E/MPcXEjP9DhgjOnF6cf+cK9FmdWzdn DhHw== X-Gm-Message-State: AOAM533jqaHsIgzGgH8wbnN+Ri5RA61by1Mm77dZEwpm9TulYCYDPC8k paKJf0uBkkLtb3kB13hs+QMMncivoFpSig== X-Received: by 2002:a17:90a:db81:: with SMTP id h1mr3980620pjv.46.1638853876549; Mon, 06 Dec 2021 21:11:16 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q10sm11975516pfk.180.2021.12.06.21.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:16 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v2 3/3] efi_loader: correctly handle no tpm device error Date: Tue, 7 Dec 2021 14:15:33 +0900 Message-Id: <20211207051533.5597-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211207051533.5597-1-masahisa.kojima@linaro.org> References: <20211207051533.5597-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 and efi_load_image() ends with failure. The same error handling is applied to efi_tcg2_measure_efi_app_invocation(). Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Changes in v2: - EFI_SECURITY_VIOLATION is returned in efi_tcg2_measure_efi_app_invocation() lib/efi_loader/efi_boottime.c | 9 ++++++--- lib/efi_loader/efi_image_loader.c | 13 ++++++++++--- lib/efi_loader/efi_tcg2.c | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 8492b732f3..20b69699fe 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3016,9 +3016,12 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) { ret = efi_tcg2_measure_efi_app_invocation(image_obj); - if (ret != EFI_SUCCESS) { - log_warning("tcg2 measurement fails(0x%lx)\n", - ret); + if (ret == EFI_SECURITY_VIOLATION) { + /* + * TCG2 Protocol is installed but no TPM device found, + * this is not expected. + */ + return EFI_EXIT(EFI_SECURITY_VIOLATION); } } } diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eb95580538..773bd0677c 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)) - log_err("PE image measurement failed\n"); + 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, no tpm device found\n"); + goto err; + } + #endif /* Copy PE headers */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 59bce85028..0ae07ef083 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: @@ -2200,7 +2200,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) - return ret; + return EFI_SECURITY_VIOLATION; ret = tcg2_measure_boot_variable(dev); if (ret != EFI_SUCCESS)