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; }