From patchwork Wed May 12 06:59:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 435459 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4558188jao; Wed, 12 May 2021 00:00:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5/YREmbEqJL1HhzFTKNCY/UhDOjeL67knxdFt6LKpgCGA7hhnHk1r48+198qYnr8yeEwt X-Received: by 2002:a17:906:828b:: with SMTP id h11mr36111074ejx.305.1620802830820; Wed, 12 May 2021 00:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620802830; cv=none; d=google.com; s=arc-20160816; b=Gc1jHwc8njYiEddXidy2mKKfwPoAuYi5moB0LaSYZBb2oE/Bm1tjX3U9+ie3kWxy9A H8psmlrXwqZSU75/nn09p75GQiEiGmzzLS9SRs2k7ZnmXqfS+3j8yrds1RQbPSItmO3C 5XlW1nS9yGkD7k0BWWQbnhm3Z3vyS9WDfwxOAJSsui41Xs36iFa6oWDhfg3AZqZvaptE HTmy/mOCRFvW0Vr1M91ePup2NLBS0FSB8HiYAamZb4j06ho3W0Xut6JrwySIVxPRp9Bo ifp0Fa7mUZqlzhr6/Kc8/XdY3zGNssDEcPW6axw4HNNNMOwwAukLjBljUAofN3H7fLH1 zBtg== 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=NAQqdzK8c+14WZmMUdQOLvXd2DdcF6pI1pOl3eAy+io=; b=fHhgu70yAQequlGhJFuJCD0yDtcwJqNSqdj8Pb2UrBaYondRr+xNacdBmoaoY6C88I dUqv1QsAztkMGJeP/AU+zAyoiIOioisNZ9mjYGVD2rk+GJovfdhs0kVJSppDB0otBij+ eQ/PcuHHfjWw8vKs03K1JrkRP0ORefi07qjPiGkBnr5xns1GwnqsOpgciWzmZBd71pz9 WPNSDmfxyOZS7+QrSB6WuE2R9B4srIRwAgLTEYg9PSSNPE4GivCA3ikbkYxb0GOMNajQ NYgKAZpmfT0wXUGR5yI8GXhjbAO6ZPxsyuMTrCqQqVAQRCFp79vyFKd6IpPKBISoCoe3 35rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RZfEwAtc; 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 z17si19003627eju.287.2021.05.12.00.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:30 -0700 (PDT) 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=RZfEwAtc; 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 3646182D51; Wed, 12 May 2021 09:00:22 +0200 (CEST) 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="RZfEwAtc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95E5482D4F; Wed, 12 May 2021 09:00:18 +0200 (CEST) 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-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 DAEDB82D03 for ; Wed, 12 May 2021 09:00:10 +0200 (CEST) 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-x62a.google.com with SMTP id b21so12072886plz.0 for ; Wed, 12 May 2021 00:00:10 -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:in-reply-to:references; bh=NAQqdzK8c+14WZmMUdQOLvXd2DdcF6pI1pOl3eAy+io=; b=RZfEwAtcYhgIVnBvhbQ04fTm8pEsHh0C5bnQCBOxZbn9duKXdafGJxFCyAGTspu+RN TB0tHJ0Jz7s6hqHldqNkKnOI764/FLUZwI5FyII3pPqyz9DTbVAviAGSiu6SL+Hx6Xzg C0VoYqXe4P/kouOQZ8yOM5EdAoEuCllwBBETHuMaInYve91voaVX2d4LSIXJ4CUP8ZyA E66zSejUMTfo/A6ZVORlViP+18cUFe35sOgo4GC8PPKS4hXhM4cWYLjQSYIe8RqaqX6W q3yYyS9cKzBBQZ+PmdWHZGQOu2PvuK2kxF0qOsNM9cWnHjIrYP0RkuGaUfEPOhY1118Q iSUA== 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:in-reply-to :references; bh=NAQqdzK8c+14WZmMUdQOLvXd2DdcF6pI1pOl3eAy+io=; b=OfvDJspgUsFn7ULqDwqeE2VJ0CYOh/MY3MZgkIohAgs/+8P8To8ftdPkIXZjHSKolH 4bmrYlAFW3KA4IKLWYb427p8IAFxoeg8ooU5w2OX8m0kwa/caH8shGCBJl6jwgNbTRUA UImy9bb/I13z4FU4bPSu9fZ3DjHB92BlpcgeJepySSOcvhAmw0pUJMJeUMcGXBznI/Vn aCw0hyqEPfL42H8DDOk4DvzfH4gob69CuapSk9U1LV4/5Q52juBp7iZTk0WYUS3IkU/5 Wz4JaTbwOEdm0aMYcjtL8NKkeC7N+xfYHWPkNul5iFqePE125oYkF3CFRGG66U6kew12 GvyQ== X-Gm-Message-State: AOAM5323NFOHPMGkpPvlQZF4ls7PI+8xsnccYIl1tCtmcZ5HPGYtlWXO kYBZjL+fHzpWdV364pf1pqygrg== X-Received: by 2002:a17:90b:1d86:: with SMTP id pf6mr37884257pjb.59.1620802808092; Wed, 12 May 2021 00:00:08 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id in16sm15956081pjb.14.2021.05.12.00.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:07 -0700 (PDT) From: Masahisa Kojima To: Heinrich Schuchardt Cc: Alexander Graf , Simon Glass , Ilias Apalodimas , Masahisa Kojima , Dhananjay Phadke , Takahiro Akashi , u-boot@lists.denx.de Subject: [PATCH v4 1/3] efi_loader: expose efi_image_parse() even if UEFI Secure Boot is disabled Date: Wed, 12 May 2021 15:59:45 +0900 Message-Id: <20210512065947.23998-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512065947.23998-1-masahisa.kojima@linaro.org> References: <20210512065947.23998-1-masahisa.kojima@linaro.org> 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 This is preparation for PE/COFF measurement support. PE/COFF image hash calculation is same in both UEFI Secure Boot image verification and measurement in measured boot. PE/COFF image parsing functions are gathered into efi_image_loader.c, and exposed even if UEFI Secure Boot is not enabled. This commit also adds the EFI_SIGNATURE_SUPPORT option to decide if efi_signature.c shall be compiled. Signed-off-by: Masahisa Kojima --- Changes in v4: - revert #ifdef instead of using "if (!IS_ENABLED())" statement, not to rely on the compiler optimization. Changes in v3: - hide EFI_SIGNATURE_SUPPORT option Changes in v2: - Remove all #ifdef from efi_image_loader.c and efi_signature.c - Add EFI_SIGNATURE_SUPPORT option - Explicitly include - Gather PE/COFF parsing functions into efi_image_loader.c - Move efi_guid_t efi_guid_image_security_database in efi_var_common.c lib/efi_loader/Kconfig | 6 +++ lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_image_loader.c | 64 ++++++++++++++++++++++++++++- lib/efi_loader/efi_signature.c | 67 +------------------------------ lib/efi_loader/efi_var_common.c | 3 ++ 5 files changed, 74 insertions(+), 68 deletions(-) -- 2.17.1 diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 0b99d7c774..b76e77180e 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -174,6 +174,7 @@ config EFI_CAPSULE_AUTHENTICATE select PKCS7_MESSAGE_PARSER select PKCS7_VERIFY select IMAGE_SIGN_INFO + select EFI_SIGNATURE_SUPPORT default n help Select this option if you want to enable capsule @@ -336,6 +337,7 @@ config EFI_SECURE_BOOT select X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER select PKCS7_VERIFY + select EFI_SIGNATURE_SUPPORT default n help Select this option to enable EFI secure boot support. @@ -343,6 +345,10 @@ config EFI_SECURE_BOOT it is signed with a trusted key. To do that, you need to install, at least, PK, KEK and db. +config EFI_SIGNATURE_SUPPORT + bool + depends on EFI_SECURE_BOOT || EFI_CAPSULE_AUTHENTICATE + config EFI_ESRT bool "Enable the UEFI ESRT generation" depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 8bd343e258..fd344cea29 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -63,7 +63,7 @@ obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o -obj-y += efi_signature.o +obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE) diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index f53ef367ec..fe1ee198e2 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -213,7 +213,68 @@ static void efi_set_code_and_data_type( } } -#ifdef CONFIG_EFI_SECURE_BOOT +/** + * efi_image_region_add() - add an entry of region + * @regs: Pointer to array of regions + * @start: Start address of region (included) + * @end: End address of region (excluded) + * @nocheck: flag against overlapped regions + * + * Take one entry of region [@start, @end[ and insert it into the list. + * + * * If @nocheck is false, the list will be sorted ascending by address. + * Overlapping entries will not be allowed. + * + * * If @nocheck is true, the list will be sorted ascending by sequence + * of adding the entries. Overlapping is allowed. + * + * Return: status code + */ +efi_status_t efi_image_region_add(struct efi_image_regions *regs, + const void *start, const void *end, + int nocheck) +{ + struct image_region *reg; + int i, j; + + if (regs->num >= regs->max) { + EFI_PRINT("%s: no more room for regions\n", __func__); + return EFI_OUT_OF_RESOURCES; + } + + if (end < start) + return EFI_INVALID_PARAMETER; + + for (i = 0; i < regs->num; i++) { + reg = ®s->reg[i]; + if (nocheck) + continue; + + /* new data after registered region */ + if (start >= reg->data + reg->size) + continue; + + /* new data preceding registered region */ + if (end <= reg->data) { + for (j = regs->num - 1; j >= i; j--) + memcpy(®s->reg[j + 1], ®s->reg[j], + sizeof(*reg)); + break; + } + + /* new data overlapping registered region */ + EFI_PRINT("%s: new region already part of another\n", __func__); + return EFI_INVALID_PARAMETER; + } + + reg = ®s->reg[i]; + reg->data = start; + reg->size = end - start; + regs->num++; + + return EFI_SUCCESS; +} + /** * cmp_pe_section() - compare virtual addresses of two PE image sections * @arg1: pointer to pointer to first section header @@ -422,6 +483,7 @@ err: return false; } +#ifdef CONFIG_EFI_SECURE_BOOT /** * efi_image_unsigned_authenticate() - authenticate unsigned image with * SHA256 hash diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c index c7ec275414..bdd09881fc 100644 --- a/lib/efi_loader/efi_signature.c +++ b/lib/efi_loader/efi_signature.c @@ -15,18 +15,16 @@ #include #include #include +#include #include #include -const efi_guid_t efi_guid_image_security_database = - EFI_IMAGE_SECURITY_DATABASE_GUID; const efi_guid_t efi_guid_sha256 = EFI_CERT_SHA256_GUID; const efi_guid_t efi_guid_cert_rsa2048 = EFI_CERT_RSA2048_GUID; const efi_guid_t efi_guid_cert_x509 = EFI_CERT_X509_GUID; const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID; const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID; -#if defined(CONFIG_EFI_SECURE_BOOT) || defined(CONFIG_EFI_CAPSULE_AUTHENTICATE) static u8 pkcs7_hdr[] = { /* SEQUENCE */ 0x30, 0x82, 0x05, 0xc7, @@ -539,68 +537,6 @@ out: return !revoked; } -/** - * efi_image_region_add() - add an entry of region - * @regs: Pointer to array of regions - * @start: Start address of region (included) - * @end: End address of region (excluded) - * @nocheck: flag against overlapped regions - * - * Take one entry of region [@start, @end[ and insert it into the list. - * - * * If @nocheck is false, the list will be sorted ascending by address. - * Overlapping entries will not be allowed. - * - * * If @nocheck is true, the list will be sorted ascending by sequence - * of adding the entries. Overlapping is allowed. - * - * Return: status code - */ -efi_status_t efi_image_region_add(struct efi_image_regions *regs, - const void *start, const void *end, - int nocheck) -{ - struct image_region *reg; - int i, j; - - if (regs->num >= regs->max) { - EFI_PRINT("%s: no more room for regions\n", __func__); - return EFI_OUT_OF_RESOURCES; - } - - if (end < start) - return EFI_INVALID_PARAMETER; - - for (i = 0; i < regs->num; i++) { - reg = ®s->reg[i]; - if (nocheck) - continue; - - /* new data after registered region */ - if (start >= reg->data + reg->size) - continue; - - /* new data preceding registered region */ - if (end <= reg->data) { - for (j = regs->num - 1; j >= i; j--) - memcpy(®s->reg[j + 1], ®s->reg[j], - sizeof(*reg)); - break; - } - - /* new data overlapping registered region */ - EFI_PRINT("%s: new region already part of another\n", __func__); - return EFI_INVALID_PARAMETER; - } - - reg = ®s->reg[i]; - reg->data = start; - reg->size = end - start; - regs->num++; - - return EFI_SUCCESS; -} - /** * efi_sigstore_free - free signature store * @sigstore: Pointer to signature store structure @@ -846,4 +782,3 @@ struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name) return efi_build_signature_store(db, db_size); } -#endif /* CONFIG_EFI_SECURE_BOOT || CONFIG_EFI_CAPSULE_AUTHENTICATE */ diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index b11ed91a74..83479dd142 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -24,6 +24,9 @@ struct efi_auth_var_name_type { const enum efi_auth_var_type type; }; +const efi_guid_t efi_guid_image_security_database = + EFI_IMAGE_SECURITY_DATABASE_GUID; + static const struct efi_auth_var_name_type name_type[] = { {u"PK", &efi_global_variable_guid, EFI_AUTH_VAR_PK}, {u"KEK", &efi_global_variable_guid, EFI_AUTH_VAR_KEK}, From patchwork Wed May 12 06:59:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 435460 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4558360jao; Wed, 12 May 2021 00:00:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOXOACIhEUkf508YVgJObN5MnFJQEBmeIa82G1H+e6Th6S1BBbZdshyDj4ye7I8vYpxVzm X-Received: by 2002:a05:6402:11ca:: with SMTP id j10mr41645450edw.184.1620802841912; Wed, 12 May 2021 00:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620802841; cv=none; d=google.com; s=arc-20160816; b=u8MGX5lNVgdY8aUIqR+fk8GhdEAX/TG7kvqZ0UUJDGAXKCmq1uMThf3F0iUTucCwlB LmpfCVzfl8sw2sn10odVqOuNHEaem/Wv7joWqFIYDRivJGRM5pIAuyKilEPoZ/3LowX5 yUZLV6QrrfjPZaiLlxwi3n5Ku24wv3JrowTf+oJblpBcvcOw448AtYXCB1atap6xMJyl KSQnWOzqe4dc1e8FUS9KEqhryMmolo9KybwfdtsE+wpqFM4SDA9v5XcxZFGa6X+sD34D qiQhIBNTMcL0mZ2mEEkThysnpDkfxjiyX94FXKQH3kNGF5gfdjpDhUhPhLUim4mE6Pwf TRSQ== 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=WIkOYvCyCLku8aweKHUky96KQwyTuf7xt3PToLNMxXY=; b=X63xK5NWpc42s6xv0fiuwD4hfDzLjbzW7/MSw9Fim59CirNI6tgL+O2E5/c2/JfCHv 9f3CIMUa1bnLlNTsefIqXJgarSyp43NeVf2d+Er3gbjb2ljUn8JfG2djuPTpSl4BtcQZ ZGXQUZUrFTJTNgwWvRqMolJfgwdXdOhpK2plR1uK5670l7ko3dJQDLLwmJ2S9EeMw9KJ /DvTzA5FvNVoKU8KTGijHd1bSPY29RaU8dzbx0/ebnWZqdFoH0OZeOatG27u1QIur+9d v6hnKQ8ecuk98KAVP5VVUDWFtcENDOoFQfCcmWmEFL6idkUdQvcbcLYCwaYWKDdxTP9N fcQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pDDnopGf; 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 y23si19270814edu.555.2021.05.12.00.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:41 -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=pDDnopGf; 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 93E8D82D50; Wed, 12 May 2021 09:00:28 +0200 (CEST) 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="pDDnopGf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D846282D4B; Wed, 12 May 2021 09:00:25 +0200 (CEST) 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-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 858F482AE7 for ; Wed, 12 May 2021 09:00:12 +0200 (CEST) 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 n16so12033154plf.7 for ; Wed, 12 May 2021 00:00: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:in-reply-to:references; bh=WIkOYvCyCLku8aweKHUky96KQwyTuf7xt3PToLNMxXY=; b=pDDnopGfMRvISTTvcRlubTlnxOX2kmF/VB0wW4d/tlWSdXDtsvt/HQzP23HO2KKNTR O4Rptehg7ZtuaRzwubWB1UBKS+yjef5uLQ9GaOPLZStR7uzdCxosmtmXDi1qgU9rNwGm RqBr+NuFL2qMK49BbbMp8BbiJtwbFVEM3nHgqTI+7CceZqg4R9w2/LZfMVHJgUDO0bad 4uq+Bn3ZCbwEeWxRDnUVozEA/KogOyHAX8fhw6J9i+9J8BHRonY2f/3zMtHH1TQLgjfC 6FQbt9Xk2aWpgC0xs9ckeOLoZtW8vmdxxzyP4qo+Rl27Nuo7yOV+MUks92Tz/sU4R1JT 95Ow== 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:in-reply-to :references; bh=WIkOYvCyCLku8aweKHUky96KQwyTuf7xt3PToLNMxXY=; b=NvoQUTYbXyLOOSfVNHqCgh5Yzw6+s9cVfR3jlJFey0KiadjgH8aTazgtqVx7KDhaBM kMSxLuK0ksk2XynMSlUOdmTCQYw1pnaTBtIpRjw11exH/D30+hkiyAO3TJsD3Ak3pCrX NBcESmFglrFvZlJYyfCrLlE0slN2GNyWYYYHWzebp7oyNoMu3/XKezr02SsuHSxE+pl4 BiONoK1zHIghI0Z51XFQUSKB5n9H38nlxlJbNe7FZtiz1DvWPwNtzVtjiY4a4t0jP7WJ GHwd/Iu1g+nLGf82DNvReUfSvGS2LglYlj86mQIGXlDs24SIHghllb0gQUqI6xg3kxkp 894Q== X-Gm-Message-State: AOAM532VVn1tT9EU1Zn38REPRD7L8jtQvDFr/1keuJLrvyT73L8CVN8m PcUKMZh7WlK5fO/jOTWSmRuj+Q== X-Received: by 2002:a17:902:ea0f:b029:ef:28a:c031 with SMTP id s15-20020a170902ea0fb02900ef028ac031mr28929750plg.49.1620802810970; Wed, 12 May 2021 00:00:10 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id in16sm15956081pjb.14.2021.05.12.00.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:10 -0700 (PDT) From: Masahisa Kojima To: Heinrich Schuchardt Cc: Alexander Graf , Simon Glass , Ilias Apalodimas , Masahisa Kojima , Dhananjay Phadke , Takahiro Akashi , u-boot@lists.denx.de Subject: [PATCH v4 2/3] efi_loader: add PE/COFF image measurement Date: Wed, 12 May 2021 15:59:46 +0900 Message-Id: <20210512065947.23998-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512065947.23998-1-masahisa.kojima@linaro.org> References: <20210512065947.23998-1-masahisa.kojima@linaro.org> 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 "TCG PC Client Platform Firmware Profile Specification" requires to measure every attempt to load and execute a OS Loader(a UEFI application) into PCR[4]. This commit adds the PE/COFF image measurement, extends PCR, and appends measurement into Event Log. Signed-off-by: Masahisa Kojima --- (no changes since v2) Changes in v2: - Remove duplicate include - Remove unnecessary __packed attribute - Add all EV_EFI_* event definition - Create common function to prepare 8-byte aligned image - Add measurement for EV_EFI_BOOT_SERVICES_DRIVER and EV_EFI_RUNTIME_SERVICES_DRIVER - Use efi_search_protocol() to get device_path - Add function comment include/efi_loader.h | 6 + include/efi_tcg2.h | 9 ++ include/tpm-v2.h | 18 +++ lib/efi_loader/efi_image_loader.c | 59 +++++++-- lib/efi_loader/efi_tcg2.c | 207 ++++++++++++++++++++++++++++-- 5 files changed, 275 insertions(+), 24 deletions(-) -- 2.17.1 Acked-by: Ilias Apalodimas Tested-by: Ilias Apalodimas diff --git a/include/efi_loader.h b/include/efi_loader.h index de1a496a97..9f2854a255 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -426,6 +426,10 @@ 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); +/* 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, + struct efi_loaded_image *loaded_image_info); /* Create handles and protocols for the partitions of a block device */ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, const char *if_typename, int diskid, @@ -847,6 +851,8 @@ bool efi_secure_boot_enabled(void); bool efi_capsule_auth_enabled(void); +void *efi_prepare_aligned_image(void *efi, u64 *efi_size, void **new_efi); + bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp, WIN_CERTIFICATE **auth, size_t *auth_len); diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h index 40e241ce31..bcfb98168a 100644 --- a/include/efi_tcg2.h +++ b/include/efi_tcg2.h @@ -9,6 +9,7 @@ #if !defined _EFI_TCG2_PROTOCOL_H_ #define _EFI_TCG2_PROTOCOL_H_ +#include #include #define EFI_TCG2_PROTOCOL_GUID \ @@ -53,6 +54,14 @@ struct efi_tcg2_event { u8 event[]; } __packed; +struct uefi_image_load_event { + efi_physical_addr_t image_location_in_memory; + u64 image_length_in_memory; + u64 image_link_time_address; + u64 length_of_device_path; + struct efi_device_path device_path[]; +}; + struct efi_tcg2_boot_service_capability { u8 size; struct efi_tcg2_version structure_version; diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 7de7d6a57d..247b386967 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -70,6 +70,24 @@ struct udevice; #define EV_TABLE_OF_DEVICES ((u32)0x0000000B) #define EV_COMPACT_HASH ((u32)0x0000000C) +/* + * event types, cf. + * "TCG PC Client Platform Firmware Profile Specification", Family "2.0" + * rev 1.04, June 3, 2019 + */ +#define EV_EFI_EVENT_BASE ((u32)0x80000000) +#define EV_EFI_VARIABLE_DRIVER_CONFIG ((u32)0x80000001) +#define EV_EFI_VARIABLE_BOOT ((u32)0x80000002) +#define EV_EFI_BOOT_SERVICES_APPLICATION ((u32)0x80000003) +#define EV_EFI_BOOT_SERVICES_DRIVER ((u32)0x80000004) +#define EV_EFI_RUNTIME_SERVICES_DRIVER ((u32)0x80000005) +#define EV_EFI_GPT_EVENT ((u32)0x80000006) +#define EV_EFI_ACTION ((u32)0x80000007) +#define EV_EFI_PLATFORM_FIRMWARE_BLOB ((u32)0x80000008) +#define EV_EFI_HANDOFF_TABLES ((u32)0x80000009) +#define EV_EFI_HCRTM_EVENT ((u32)0x80000010) +#define EV_EFI_VARIABLE_AUTHORITY ((u32)0x800000E0) + /* TPMS_TAGGED_PROPERTY Structure */ struct tpms_tagged_property { u32 property; diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index fe1ee198e2..f37a85e56e 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -302,6 +302,40 @@ static int cmp_pe_section(const void *arg1, const void *arg2) return 1; } +/** + * efi_prepare_aligned_image() - prepare 8-byte aligned image + * @efi: pointer to the EFI binary + * @efi_size: size of @efi binary + * @new_efi: pointer to the newly allocated image + * + * If @efi is not 8-byte aligned, this function newly allocates + * the image buffer and updates @efi_size. + * + * Return: valid pointer to a image, return NULL if allocation fails. + */ +void *efi_prepare_aligned_image(void *efi, u64 *efi_size, void **new_efi) +{ + size_t new_efi_size; + void *p; + + /* + * Size must be 8-byte aligned and the trailing bytes must be + * zero'ed. Otherwise hash value may be incorrect. + */ + if (!IS_ALIGNED(*efi_size, 8)) { + new_efi_size = ALIGN(*efi_size, 8); + p = calloc(new_efi_size, 1); + if (!p) + return NULL; + memcpy(p, efi, *efi_size); + *efi_size = new_efi_size; + *new_efi = p; + return p; + } else { + return efi; + } +} + /** * efi_image_parse() - parse a PE image * @efi: Pointer to image @@ -561,7 +595,7 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) struct efi_signature_store *db = NULL, *dbx = NULL; void *new_efi = NULL; u8 *auth, *wincerts_end; - size_t new_efi_size, auth_size; + size_t auth_size; bool ret = false; EFI_PRINT("%s: Enter, %d\n", __func__, ret); @@ -569,19 +603,9 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) if (!efi_secure_boot_enabled()) return true; - /* - * Size must be 8-byte aligned and the trailing bytes must be - * zero'ed. Otherwise hash value may be incorrect. - */ - if (efi_size & 0x7) { - new_efi_size = (efi_size + 0x7) & ~0x7ULL; - new_efi = calloc(new_efi_size, 1); - if (!new_efi) - return false; - memcpy(new_efi, efi, efi_size); - efi = new_efi; - efi_size = new_efi_size; - } + efi = efi_prepare_aligned_image(efi, (u64 *)&efi_size, &new_efi); + if (!efi) + return false; if (!efi_image_parse(efi, efi_size, ®s, &wincerts, &wincerts_len)) { @@ -891,6 +915,13 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, goto err; } +#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"); +#endif + /* Copy PE headers */ memcpy(efi_reloc, efi, sizeof(*dos) diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 94e8f22bbb..7ad9cb2b89 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -706,6 +708,183 @@ out: return EFI_EXIT(ret); } +/** + * tcg2_hash_pe_image() - calculate PE/COFF image hash + * + * @efi: pointer to the EFI binary + * @efi_size: size of @efi binary + * @digest_list: list of digest algorithms to extend + * + * Return: status code + */ +static efi_status_t tcg2_hash_pe_image(void *efi, u64 efi_size, + struct tpml_digest_values *digest_list) +{ + WIN_CERTIFICATE *wincerts = NULL; + size_t wincerts_len; + struct efi_image_regions *regs = NULL; + void *new_efi = NULL; + u8 hash[TPM2_SHA512_DIGEST_SIZE]; + efi_status_t ret; + u32 active; + int i; + + efi = efi_prepare_aligned_image(efi, &efi_size, &new_efi); + if (!efi) + return EFI_OUT_OF_RESOURCES; + + if (!efi_image_parse(efi, efi_size, ®s, &wincerts, + &wincerts_len)) { + log_err("Parsing PE executable image failed\n"); + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = __get_active_pcr_banks(&active); + if (ret != EFI_SUCCESS) { + ret = EFI_DEVICE_ERROR; + goto out; + } + + digest_list->count = 0; + for (i = 0; i < MAX_HASH_COUNT; i++) { + u16 hash_alg = hash_algo_list[i].hash_alg; + + if (!(active & alg_to_mask(hash_alg))) + continue; + switch (hash_alg) { + case TPM2_ALG_SHA1: + hash_calculate("sha1", regs->reg, regs->num, hash); + break; + case TPM2_ALG_SHA256: + hash_calculate("sha256", regs->reg, regs->num, hash); + break; + case TPM2_ALG_SHA384: + hash_calculate("sha384", regs->reg, regs->num, hash); + break; + case TPM2_ALG_SHA512: + hash_calculate("sha512", regs->reg, regs->num, hash); + break; + default: + EFI_PRINT("Unsupported algorithm %x\n", hash_alg); + return EFI_INVALID_PARAMETER; + } + digest_list->digests[i].hash_alg = hash_alg; + memcpy(&digest_list->digests[i].digest, hash, (u32)alg_to_len(hash_alg)); + digest_list->count++; + } + +out: + free(new_efi); + free(regs); + + return ret; +} + +/** + * tcg2_measure_pe_image() - measure PE/COFF image + * + * @efi: pointer to the EFI binary + * @efi_size: size of @efi binary + * @handle: loaded image handle + * @loaded_image: loaded image protocol + * + * Return: status code + */ +efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, + struct efi_loaded_image_obj *handle, + struct efi_loaded_image *loaded_image) +{ + struct tpml_digest_values digest_list; + efi_status_t ret; + struct udevice *dev; + u32 pcr_index, event_type, event_size; + struct uefi_image_load_event *image_load_event; + struct efi_device_path *device_path; + u32 device_path_length; + IMAGE_DOS_HEADER *dos; + IMAGE_NT_HEADERS32 *nt; + struct efi_handler *handler; + + ret = platform_get_tpm2_device(&dev); + if (ret != EFI_SUCCESS) + return ret; + + switch (handle->image_type) { + case IMAGE_SUBSYSTEM_EFI_APPLICATION: + pcr_index = 4; + event_type = EV_EFI_BOOT_SERVICES_APPLICATION; + break; + case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER: + pcr_index = 2; + event_type = EV_EFI_BOOT_SERVICES_DRIVER; + break; + case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER: + pcr_index = 2; + event_type = EV_EFI_RUNTIME_SERVICES_DRIVER; + break; + default: + return EFI_UNSUPPORTED; + } + + ret = tcg2_hash_pe_image(efi, efi_size, &digest_list); + if (ret != EFI_SUCCESS) + return ret; + + ret = tcg2_pcr_extend(dev, pcr_index, &digest_list); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(efi_search_protocol(&handle->header, + &efi_guid_loaded_image_device_path, + &handler)); + if (ret != EFI_SUCCESS) + return ret; + + device_path = EFI_CALL(handler->protocol_interface); + device_path_length = efi_dp_size(device_path); + if (device_path_length > 0) { + /* add end node size */ + device_path_length += sizeof(struct efi_device_path); + } + event_size = sizeof(struct uefi_image_load_event) + device_path_length; + image_load_event = (struct uefi_image_load_event *)malloc(event_size); + if (!image_load_event) + return EFI_OUT_OF_RESOURCES; + + image_load_event->image_location_in_memory = (efi_physical_addr_t)efi; + image_load_event->image_length_in_memory = efi_size; + image_load_event->length_of_device_path = device_path_length; + + dos = (IMAGE_DOS_HEADER *)efi; + nt = (IMAGE_NT_HEADERS32 *)(efi + dos->e_lfanew); + if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + IMAGE_NT_HEADERS64 *nt64 = (IMAGE_NT_HEADERS64 *)nt; + + image_load_event->image_link_time_address = + nt64->OptionalHeader.ImageBase; + } else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + image_load_event->image_link_time_address = + nt->OptionalHeader.ImageBase; + } else { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + if (device_path_length > 0) { + memcpy(image_load_event->device_path, device_path, + device_path_length); + } + + ret = tcg2_agile_log_append(pcr_index, event_type, &digest_list, + event_size, (u8 *)image_load_event); + +out: + free(image_load_event); + + return ret; +} + /** * efi_tcg2_hash_log_extend_event() - extend and optionally log events * @@ -758,24 +937,32 @@ efi_tcg2_hash_log_extend_event(struct efi_tcg2_protocol *this, u64 flags, /* * if PE_COFF_IMAGE is set we need to make sure the image is not * corrupted, verify it and hash the PE/COFF image in accordance with - * the procedure specified in "Calculating the PE Image Hash" - * section of the "Windows Authenticode Portable Executable Signature + * the procedure specified in "Calculating the PE Image Hash" + * section of the "Windows Authenticode Portable Executable Signature * Format" - * Not supported for now */ if (flags & PE_COFF_IMAGE) { - ret = EFI_UNSUPPORTED; - goto out; - } + IMAGE_NT_HEADERS32 *nt; - pcr_index = efi_tcg_event->header.pcr_index; - event_type = efi_tcg_event->header.event_type; + ret = efi_check_pe((void *)data_to_hash, data_to_hash_len, + (void **)&nt); + if (ret != EFI_SUCCESS) { + log_err("Not a valid PE-COFF file\n"); + goto out; + } - ret = tcg2_create_digest((u8 *)data_to_hash, data_to_hash_len, - &digest_list); + ret = tcg2_hash_pe_image((void *)data_to_hash, data_to_hash_len, + &digest_list); + } else { + ret = tcg2_create_digest((u8 *)data_to_hash, data_to_hash_len, + &digest_list); + } if (ret != EFI_SUCCESS) goto out; + pcr_index = efi_tcg_event->header.pcr_index; + event_type = efi_tcg_event->header.event_type; + ret = tcg2_pcr_extend(dev, pcr_index, &digest_list); if (ret != EFI_SUCCESS) goto out; From patchwork Wed May 12 06:59:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 435461 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4558505jao; Wed, 12 May 2021 00:00:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5zQsGj2YMdzP8ZYKmaawvfaXzleLdiThX6zjYJa+qTR/Tmnb8Qv5Ih8CiA4YsfJl/Z9pE X-Received: by 2002:a17:907:3f99:: with SMTP id hr25mr36625984ejc.231.1620802853358; Wed, 12 May 2021 00:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620802853; cv=none; d=google.com; s=arc-20160816; b=ONHLyk1isyu8INAaRRcogjOp6xJ9ppvFW9GMIxKwLeUSLk9W6PBZsXh/nMDs8xMkRm r6BbabMay7JthF1xd+rXQk2waK8kO82/qfvsPncoo0Ss87hCqMBV+6unD+TeLlum1vaD xdgzGIBy2JQKZNsj7X61Th6zD+ic5jdQlxgpP63wzUW4s7xDqz85DOr7/fmcboalBwTM n3FBlK1CKahIEaRaFvuceKzyi7iVQ47G47p1iuwEQffu/TZU3FavlmoAuuV6U7szb9wm FKMYtN/VPMSohRhmOS96lKBBbi4YchmzWP1G9OsTD/szEUtwFwdTrISI/n3l9BNJp1gA NtLw== 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=zCld6Lxx6b5EvU9h/AW3Prdo1hEAI9f3BoP0q9UvhGE=; b=tDkLx0CYa/VhaUvBs+UvmJQC6tOfdCG278NPoRrlIX4uHHzI4228dPRGufqsOnaX7Q DSV4TqxwRCojuVvKuVzsxGyQiMwWBdbMviOTES4sMklTZg9q6TeDGtmAeiRo39v8krCg 1j90bdry04mSaZzt3dC86YjNhb5aIPRMCqVBK+i6sJtv/9yRhmjfJXg8JG64FkgLPuNj SfHDHApnY/sval/HBlsEnBCPqW3bev5ytH5KNQx/jTvkCN1zsp4cHfwWE0q6W2zACqlV LNk0McgA26zAAMpj5BTRGZZf7lAo/aIlUfQXEVU90Km6WcnyI8vwvZKBajWz72RHIsAF O/AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oh3dyfJ5; 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 z18si19342952edl.459.2021.05.12.00.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:53 -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=oh3dyfJ5; 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 92E1282D54; Wed, 12 May 2021 09:00:32 +0200 (CEST) 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="oh3dyfJ5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E08882D56; Wed, 12 May 2021 09:00:25 +0200 (CEST) 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-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 5EEDA82D4B for ; Wed, 12 May 2021 09:00:15 +0200 (CEST) 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-x52e.google.com with SMTP id i14so17529384pgk.5 for ; Wed, 12 May 2021 00:00:15 -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:in-reply-to:references; bh=zCld6Lxx6b5EvU9h/AW3Prdo1hEAI9f3BoP0q9UvhGE=; b=oh3dyfJ5nd/QL/8FtyxlrPSLsvFCm6FS53E0Ce2f+DfuQooEUkSvXeJxfCsG9MSVa1 jwpahZVt4xaOdTFh5mOzr15KSoW8XR9rcPAgtwubUgJTkWVola7kcuPFHdls681mFurC 4T2Vd9FPcEePEoUTuI7TXSzwHiA7qKK51BnmY8Dwo2av9Bg0IdwsLmzEoiYngEaWHqJz SoYRnxAZiU3TkZm0xUt/VYIEXNdiiIWLC5TN7WhCw9NFdTUQkRKeo37z75SNrNyzjRQt oyYuzjhqjALQ+E8HDrSOWUqnHOOKM82wgjwgOykY8RDERPwGiboyG1JWgdMerlt7lQWj 2VAQ== 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:in-reply-to :references; bh=zCld6Lxx6b5EvU9h/AW3Prdo1hEAI9f3BoP0q9UvhGE=; b=M29f/tKUiHlML3tu3RSxfiaAipFaGueG3Lr4PMFegaDqT+W6m0sIzT1iLLR0fbqqPh NSQEIwL1zSujv8A6JsgmU06eyo/CB1iPThQDe6hS43h+VfGscCzeiSJ1L7HEwGnSfsA5 q/ZO+D5Q2VmOxC5qWpLys3MJWZOIYxqnNIit2RnG4Unqm/8VdyBRyG5jBbf1Lpi237T4 iMTQ0rR4ODEVbwBT3fqdeeXA/5OAxdIvJTE8rJfrId5oV6iYlkPhK2HIzRxXAoW9K8OV 7io0YLZawXYnW5FtO4lAjKponREFriqM/0MFsQtfBrctA2q7hFPDQS5Xvinzpruy4NdU H0pw== X-Gm-Message-State: AOAM532R6P/Q4/YYArLZ2p/yweGDnPuMa08Gkw88UjuJjvtlotu48gMd XwlWfyWCwvmAigz2dnb5a3GGqw== X-Received: by 2002:a63:7986:: with SMTP id u128mr34541240pgc.223.1620802813784; Wed, 12 May 2021 00:00:13 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id in16sm15956081pjb.14.2021.05.12.00.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 00:00:13 -0700 (PDT) From: Masahisa Kojima To: Heinrich Schuchardt Cc: Alexander Graf , Simon Glass , Ilias Apalodimas , Masahisa Kojima , Dhananjay Phadke , Takahiro Akashi , u-boot@lists.denx.de Subject: [PATCH v4 3/3] efi_loader: add required option to use hash_calculate() Date: Wed, 12 May 2021 15:59:47 +0900 Message-Id: <20210512065947.23998-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512065947.23998-1-masahisa.kojima@linaro.org> References: <20210512065947.23998-1-masahisa.kojima@linaro.org> 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 Build error occurs when CONFIG_EFI_SECURE_BOOT/ CONFIG_EFI_CAPSULE_AUTHENTICATE/CONFIG_EFI_TCG2_PROTOCOL is enabled, because hash-checksum.c is not compiled. With the following commit, commit 0bcb28dfb946 ("lib: Rename rsa-checksum.c to hash-checksum.c") CONFIG_FIT_SIGNATURE option is required to use hash_calculate() function. This commit adds CONFIG_FIT_SIGNATURE option in Kconfig, and missing required options for CONFIG_EFI_TCG2_PROTOCOL. Signed-off-by: Masahisa Kojima --- Changes in v4: - newly added in this patch series, due to rebasing the base code. lib/efi_loader/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index b76e77180e..93463fb362 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -175,6 +175,7 @@ config EFI_CAPSULE_AUTHENTICATE select PKCS7_VERIFY select IMAGE_SIGN_INFO select EFI_SIGNATURE_SUPPORT + select FIT_SIGNATURE default n help Select this option if you want to enable capsule @@ -302,6 +303,12 @@ config EFI_RNG_PROTOCOL config EFI_TCG2_PROTOCOL bool "EFI_TCG2_PROTOCOL support" depends on TPM_V2 + select FIT_SIGNATURE + select SHA1 + select SHA256 + select SHA512_ALGO + select SHA384 + select SHA512 help Provide a EFI_TCG2_PROTOCOL implementation using the TPM hardware of the platform. @@ -338,6 +345,7 @@ config EFI_SECURE_BOOT select PKCS7_MESSAGE_PARSER select PKCS7_VERIFY select EFI_SIGNATURE_SUPPORT + select FIT_SIGNATURE default n help Select this option to enable EFI secure boot support.