Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6159ECAAA1 for ; Sun, 23 Oct 2022 09:45:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EE4D84F3E; Sun, 23 Oct 2022 11:45:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="GwSB0vti"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B9FB984F46; Sun, 23 Oct 2022 11:45:42 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 21AEC84EC2 for ; Sun, 23 Oct 2022 11:45:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666518329; bh=syZcCoLEFRdWQI4k2zvPHZBDs1cervfsZx1ypQycu8o=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=GwSB0vtiRfkawIdAtD7ZkLpDeUeGeZYwodA3AydAvfBiHr24zb/smO1C/H6lKn4od 92LiAN66ROZLF5Nrn2Mi0SMs1vN5p2BdYdZTh4qfM80y0O9fhCm978Ox2xUtx/s735 Tgf6CPvNRy7sBl7TOv7IDyiXbYvuBYK0VHM9xoW0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFbW0-1osd8h1ycY-00HBNd; Sun, 23 Oct 2022 11:45:29 +0200 Message-ID: <1acc6010-abae-5506-4f1f-4ce1cbada33b@gmx.de> Date: Sun, 23 Oct 2022 11:45:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v3 3/6] eficonfig: add UEFI Secure Boot Key enrollment interface From: Heinrich Schuchardt To: Masahisa Kojima Cc: Ilias Apalodimas , Takahiro Akashi , Simon Glass , Roger Knecht , Ovidiu Panait , Ashok Reddy Soma , u-boot@lists.denx.de References: <20221014065705.5249-1-masahisa.kojima@linaro.org> <20221014065705.5249-4-masahisa.kojima@linaro.org> <8b16aa17-99be-8c3e-ede7-1cad544969db@gmx.de> Content-Language: en-US In-Reply-To: <8b16aa17-99be-8c3e-ede7-1cad544969db@gmx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jg0mYWmzbIiIbjUI5DdSsWy3WzoQZd5De1fCmmfCjBcVsZ4lWK+ et3VySC1MaIsJWdL+2VYZ54P7MnuGcjQeIhmT1tx3Zpu4g2eCLwPONaf/zpD77Hw0VMyOQR zNgUIwgC0Pd5UzSDQDUqzsgu6ek99DgUWlNgSHFwxeUebzgMWyR9vvGf+bqIDLUu1BPylF0 FBt1v2tvah8E4ipFR8LYg== X-UI-Out-Filterresults: notjunk:1;V03:K0:2hKBDom0xrI=:qkcNp0Y82RIoLCbopEDM6q O+f3Eifxg2vVDLdN41LFrTVtWSg425ev5UTW6J3MhO1Q6y4qBuERffB1GGH0fUO9x333riBe8 rN1PD4MVp2mOFuVCTADvyQff/nxblHAmlH3QEuvsRUQJ73R8MCDDipDIje6ri/gm4aZGxqYmM uhH7JcOXskMmA+KKAaakBxB6lIPvEIDXpTo7Xp/L/vPuN2xq4smaX3zlvUqWvv8y1qRZaNmNJ OSP9yk3uj51ta8ux+8XMvHYm6EOnUuPuW9+d3Tlvt6bdmun5kdOh/6eRka4D4s1b5Qyd445kR JWhTVRxPyZxkZIz5T/157P0jgYMW+YE01XXDjPGBk7inBK3eWfAe3ghSkQnK9AQ50uu7y8M2Y ErD7gweCL1X4qrSvpdgk8MVLpZW70RZ46M86GUX+CYnOZlgBeP9a0EtW2rE1AnFfpoUcZDo7Y COzbgh3qtT0FFJ0ioSNQYGy9UPTbYJ+HAo1/Npelh6XmdKLrM3bHDy6LPQfmQLm8BZANlNi0f dj+Fj0LVGi9dxysA7n3AAJwo2y04Hmq4970jGJ8Nhww9QN+HoB4nfeLWP73B58rZLQvoXzpnz PWGwwQs8pAVyu1gnVBdgzmMETJZED+ZVrXhyMucav4eQrFb/1EZjHRyPKFAm0zeH1qWC1ZrsP xjYJTm2hE3ybpLmc9IFT1YgTLc9Rwemj1xnYPtTBCN5t2CefD6pfiA/PuQmWxHBUPp37/PDKj P1ucZa9HgmmivM5RrArdIiapLp2cAjC7B7lt449A08J9MIbDgxsWra3YxRTY9PBir9TtRrwkh 4G66QwDjmSCdVqEWULU6kjL1GDAGl/LKChxgw+Li0W9CdUScNY5CUmXxmXu0S6w20rQpvKvpP hhcY7BvVGoJAx3qrPW/n4jPuKKGVC0grebrvre00FC7lNFpTcTreqG+ZjFArx+ijd38aOZAT7 DfiKuic+cuCj2ljWNcOkGaJ2z2wATk5Gxy4+XHR4oDKFI8llJF6o8qrssDbfWCOfog/Qk8ojv vPrLHhaL1iXFB/lmXD7oIXGHY77Lwv8EMj67siHQX8n6boUN7rEdj0c1EbFhRJjAn1CXrJatz nz9Q8Av/DHXMuYiJkPMBG97Lh4qYa6hLkJZJB/mmtwCYDpVN0z9IrJQkfeKIKZQcyOUtLmv6O OtCXWv9zJnRLtFkOrrS+c9/FZw8WYEPMrxFAiyhNR53e+qMeI5lUhZCMTsE8L2axHmSJERAF8 DLkcNpsD0cHbMj7aw1c7qzZ9aMN1/1jNwsG8HsNPql1Y60GsyR+uKt+Om+XcR74FuGPGFuKon C0hgGKCZnMWrfY5Qhx+ZwT121/pUbW/kii0rsADNJ6erzz4QvBBgB0kgiPVls/+npjLMROqMS vZ7gNE3oOe+XjqUrk/UgPk+qC15tSldGxolE78iFUtvAxlZ5TOxKVKAAQ+fNV3rUfBOyztdRb Oc91tAAGP3wke/MVQ22JNv0GPVf88HnlCcYv7Cc9fCwcWRt2d2/ix/MdeZ3kfe84P0LDe3FmP KEBy2l8c/xKyypm9ysmF6H7+o2j2vxtIRBsvtWNzAW6gm X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean On 10/23/22 10:17, Heinrich Schuchardt wrote: > On 10/14/22 08:56, Masahisa Kojima wrote: >> This commit adds the menu-driven UEFI Secure Boot Key >> enrollment interface. User can enroll the PK, KEK, db >> and dbx by selecting EFI Signature Lists file. >> After the PK is enrolled, UEFI Secure Boot is enabled and >> EFI Signature Lists file must be signed by KEK or PK. >> >> Signed-off-by: Masahisa Kojima >> --- >> Changes in v3: >> - fix error handling >> >> Changes in v2: >> - allow to enroll .esl file >> - fix typos >> - add function comments >> >> =C2=A0 cmd/Makefile=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0=C2=A0 3 + >> =C2=A0 cmd/eficonfig.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2= =A0 3 + >> =C2=A0 cmd/eficonfig_sbkey.c | 357 ++++++++++++++++++++++++++++++++++++= ++++++ >> =C2=A0 include/efi_config.h=C2=A0 |=C2=A0=C2=A0 5 + >> =C2=A0 4 files changed, 368 insertions(+) >> =C2=A0 create mode 100644 cmd/eficonfig_sbkey.c >> >> diff --git a/cmd/Makefile b/cmd/Makefile >> index c95e09d058..f2f2857146 100644 >> --- a/cmd/Makefile >> +++ b/cmd/Makefile >> @@ -66,6 +66,9 @@ obj-$(CONFIG_CMD_EEPROM) +=3D eeprom.o >> =C2=A0 obj-$(CONFIG_EFI) +=3D efi.o >> =C2=A0 obj-$(CONFIG_CMD_EFIDEBUG) +=3D efidebug.o >> =C2=A0 obj-$(CONFIG_CMD_EFICONFIG) +=3D eficonfig.o >> +ifdef CONFIG_CMD_EFICONFIG >> +obj-$(CONFIG_EFI_SECURE_BOOT) +=3D eficonfig_sbkey.o Key enrollment does not make sense if the keys are not persisted across boots. The new feature should depend on CONFIG_EFI_MM_COMM_TEE. >> +endif >> =C2=A0 obj-$(CONFIG_CMD_ELF) +=3D elf.o >> =C2=A0 obj-$(CONFIG_CMD_EROFS) +=3D erofs.o >> =C2=A0 obj-$(CONFIG_HUSH_PARSER) +=3D exit.o >> diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c >> index 0cb0770ac3..a72f07e671 100644 >> --- a/cmd/eficonfig.c >> +++ b/cmd/eficonfig.c >> @@ -2442,6 +2442,9 @@ static const struct eficonfig_item >> maintenance_menu_items[] =3D { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {"Edit Boot Option", eficonfig_process_e= dit_boot_option}, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {"Change Boot Order", eficonfig_process_= change_boot_order}, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {"Delete Boot Option", eficonfig_process= _delete_boot_option}, >> +#if (CONFIG_IS_ENABLED(EFI_SECURE_BOOT)) >> +=C2=A0=C2=A0=C2=A0 {"Secure Boot Configuration", eficonfig_process_sec= ure_boot_config}, >> +#endif >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {"Quit", eficonfig_process_quit}, >> =C2=A0 }; >> >> diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c >> new file mode 100644 >> index 0000000000..cc27f78e66 >> --- /dev/null >> +++ b/cmd/eficonfig_sbkey.c >> @@ -0,0 +1,357 @@ >> +// SPDX-License-Identifier: GPL-2.0+ >> +/* >> + *=C2=A0 Menu-driven UEFI Secure Boot Key Maintenance >> + * >> + *=C2=A0 Copyright (c) 2022 Masahisa Kojima, Linaro Limited >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +enum efi_sbkey_signature_type { >> +=C2=A0=C2=A0=C2=A0 SIG_TYPE_X509 =3D 0, >> +=C2=A0=C2=A0=C2=A0 SIG_TYPE_HASH, >> +=C2=A0=C2=A0=C2=A0 SIG_TYPE_CRL, >> +=C2=A0=C2=A0=C2=A0 SIG_TYPE_RSA2048, >> +}; >> + >> +struct eficonfig_sigtype_to_str { >> +=C2=A0=C2=A0=C2=A0 efi_guid_t sig_type; >> +=C2=A0=C2=A0=C2=A0 char *str; >> +=C2=A0=C2=A0=C2=A0 enum efi_sbkey_signature_type type; >> +}; >> + >> +static const struct eficonfig_sigtype_to_str sigtype_to_str[] =3D { >> +=C2=A0=C2=A0=C2=A0 {EFI_CERT_X509_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 "X509",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 SIG_TYPE_X509}, >> +=C2=A0=C2=A0=C2=A0 {EFI_CERT_SHA256_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "SHA256",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SIG_TY= PE_HASH}, >> +=C2=A0=C2=A0=C2=A0 {EFI_CERT_X509_SHA256_GUID,=C2=A0=C2=A0=C2=A0 "X509= _SHA256 CRL",=C2=A0=C2=A0=C2=A0 SIG_TYPE_CRL}, >> +=C2=A0=C2=A0=C2=A0 {EFI_CERT_X509_SHA384_GUID,=C2=A0=C2=A0=C2=A0 "X509= _SHA384 CRL",=C2=A0=C2=A0=C2=A0 SIG_TYPE_CRL}, >> +=C2=A0=C2=A0=C2=A0 {EFI_CERT_X509_SHA512_GUID,=C2=A0=C2=A0=C2=A0 "X509= _SHA512 CRL",=C2=A0=C2=A0=C2=A0 SIG_TYPE_CRL}, >> +=C2=A0=C2=A0=C2=A0 /* U-Boot does not support the following signature = types */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_RSA2048_GUID,=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 "RSA2048", >> SIG_TYPE_RSA2048}, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_RSA2048_SHA256_GUID,=C2=A0=C2=A0=C2=A0 = "RSA2048_SHA256", >> SIG_TYPE_RSA2048}, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_SHA1_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "SHA1",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 SIG_TYPE_HASH}, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_RSA2048_SHA_GUID,=C2=A0=C2=A0=C2=A0 "RS= A2048_SHA", >> SIG_TYPE_RSA2048 }, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_SHA224_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "SHA224",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SIG_TY= PE_HASH}, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_SHA384_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "SHA384",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SIG_TY= PE_HASH}, */ >> +/*=C2=A0=C2=A0=C2=A0 {EFI_CERT_SHA512_GUID,=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "SHA512",=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SIG_TY= PE_HASH}, */ >> +}; >> + >> +/** >> + * is_secureboot_enabled() - check UEFI Secure Boot is enabled >> + * >> + * Return:=C2=A0=C2=A0=C2=A0 true when UEFI Secure Boot is enabled, fa= lse otherwise >> + */ >> +static bool is_secureboot_enabled(void) >> +{ >> +=C2=A0=C2=A0=C2=A0 efi_status_t ret; >> +=C2=A0=C2=A0=C2=A0 u8 secure_boot; >> +=C2=A0=C2=A0=C2=A0 efi_uintn_t size; >> + >> +=C2=A0=C2=A0=C2=A0 size =3D sizeof(secure_boot); >> +=C2=A0=C2=A0=C2=A0 ret =3D efi_get_variable_int(u"SecureBoot", &efi_gl= obal_variable_guid, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 NULL, &size, &secure_boot, NULL); >> + >> +=C2=A0=C2=A0=C2=A0 return secure_boot =3D=3D 1; >> +} >> + >> +/** >> + * create_time_based_payload() - create payload for time based >> authenticate variable >> + * >> + * @db:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pointer to the origi= nal signature database >> + * @new_db:=C2=A0=C2=A0=C2=A0 pointer to the authenticated variable pa= yload >> + * @size:=C2=A0=C2=A0=C2=A0 pointer to payload size >> + * Return:=C2=A0=C2=A0=C2=A0 status code >> + */ >> +static efi_status_t create_time_based_payload(void *db, void >> **new_db, efi_uintn_t *size) >> +{ >> +=C2=A0=C2=A0=C2=A0 efi_status_t ret; >> +=C2=A0=C2=A0=C2=A0 struct efi_time time; >> +=C2=A0=C2=A0=C2=A0 efi_uintn_t total_size; >> +=C2=A0=C2=A0=C2=A0 struct efi_variable_authentication_2 *auth; >> + >> +=C2=A0=C2=A0=C2=A0 *new_db =3D NULL; >> + >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * SetVariable() call with >> EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS >> +=C2=A0=C2=A0=C2=A0=C2=A0 * attribute requires EFI_VARIABLE_AUTHENTICAT= ED_2 descriptor, >> prepare it >> +=C2=A0=C2=A0=C2=A0=C2=A0 * without certificate data in it. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0 total_size =3D sizeof(struct efi_variable_authentic= ation_2) + *size; >> + >> +=C2=A0=C2=A0=C2=A0 auth =3D calloc(1, total_size); >> +=C2=A0=C2=A0=C2=A0 if (!auth) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return EFI_OUT_OF_RESOURCES= ; >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D EFI_CALL((*efi_runtime_services.get_time)(&= time, NULL)); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(auth); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return EFI_OUT_OF_RESOURCES= ; >> +=C2=A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0 time.pad1 =3D 0; >> +=C2=A0=C2=A0=C2=A0 time.nanosecond =3D 0; >> +=C2=A0=C2=A0=C2=A0 time.timezone =3D 0; >> +=C2=A0=C2=A0=C2=A0 time.daylight =3D 0; >> +=C2=A0=C2=A0=C2=A0 time.pad2 =3D 0; >> +=C2=A0=C2=A0=C2=A0 memcpy(&auth->time_stamp, &time, sizeof(time)); >> +=C2=A0=C2=A0=C2=A0 auth->auth_info.hdr.dwLength =3D sizeof(struct >> win_certificate_uefi_guid); >> +=C2=A0=C2=A0=C2=A0 auth->auth_info.hdr.wRevision =3D 0x0200; >> +=C2=A0=C2=A0=C2=A0 auth->auth_info.hdr.wCertificateType =3D WIN_CERT_T= YPE_EFI_GUID; >> +=C2=A0=C2=A0=C2=A0 guidcpy(&auth->auth_info.cert_type, &efi_guid_cert_= type_pkcs7); >> +=C2=A0=C2=A0=C2=A0 if (db) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 memcpy((u8 *)auth + sizeof(= struct >> efi_variable_authentication_2), db, *size); >> + >> +=C2=A0=C2=A0=C2=A0 *new_db =3D auth; >> +=C2=A0=C2=A0=C2=A0 *size =3D total_size; >> + >> +=C2=A0=C2=A0=C2=A0 return EFI_SUCCESS; >> +} >> + >> +/** >> + * file_have_auth_header() - check file has >> EFI_VARIABLE_AUTHENTICATION_2 header >> + * @buf:=C2=A0=C2=A0=C2=A0 pointer to file >> + * @size:=C2=A0=C2=A0=C2=A0 file size >> + * Return:=C2=A0=C2=A0=C2=A0 true if file has auth header, false other= wise >> + */ >> +static bool file_have_auth_header(void *buf, efi_uintn_t size) >> +{ >> +=C2=A0=C2=A0=C2=A0 struct efi_variable_authentication_2 *auth =3D buf; >> + >> +=C2=A0=C2=A0=C2=A0 if (auth->auth_info.hdr.wCertificateType !=3D WIN_C= ERT_TYPE_EFI_GUID) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return false; >> + >> +=C2=A0=C2=A0=C2=A0 if (guidcmp(&auth->auth_info.cert_type, &efi_guid_c= ert_type_pkcs7)) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return false; >> + >> +=C2=A0=C2=A0=C2=A0 return true; >> +} >> + >> +/** >> + * file_is_efi_signature_list() - check the file is efi signature list >> + * @buf:=C2=A0=C2=A0=C2=A0 pointer to file >> + * Return:=C2=A0=C2=A0=C2=A0 true if file is efi signature list, false= otherwise >> + */ >> +static bool file_is_efi_signature_list(void *buf) >> +{ >> +=C2=A0=C2=A0=C2=A0 u32 i; >> +=C2=A0=C2=A0=C2=A0 struct efi_signature_list *sig_list =3D buf; >> + >> +=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < ARRAY_SIZE(sigtype_to_str); i++) = { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!guidcmp(&sig_list->sig= nature_type, >> &sigtype_to_str[i].sig_type)) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret= urn true; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 return false; >> +} >> + >> +/** >> + * eficonfig_process_enroll_key() - enroll key into signature database >> + * >> + * @data:=C2=A0=C2=A0=C2=A0 pointer to the data for each entry >> + * Return:=C2=A0=C2=A0=C2=A0 status code >> + */ >> +static efi_status_t eficonfig_process_enroll_key(void *data) >> +{ >> +=C2=A0=C2=A0=C2=A0 u32 attr; >> +=C2=A0=C2=A0=C2=A0 char *buf =3D NULL; >> +=C2=A0=C2=A0=C2=A0 efi_uintn_t size; >> +=C2=A0=C2=A0=C2=A0 efi_status_t ret; >> +=C2=A0=C2=A0=C2=A0 void *new_db =3D NULL; >> +=C2=A0=C2=A0=C2=A0 struct efi_file_handle *f; >> +=C2=A0=C2=A0=C2=A0 struct efi_file_handle *root; >> +=C2=A0=C2=A0=C2=A0 struct eficonfig_select_file_info file_info; >> + >> +=C2=A0=C2=A0=C2=A0 file_info.current_path =3D calloc(1, EFICONFIG_FILE= _PATH_BUF_SIZE); >> +=C2=A0=C2=A0=C2=A0 if (!file_info.current_path) ret =3D EFI_OUT_OF_RESOURCES; is missing here. Best regards Heinrich >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D eficonfig_select_file_handler(&file_info); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D efi_open_volume_int(file_info.current_volum= e, &root); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D efi_file_open_int(root, &f, file_info.curre= nt_path, >> EFI_FILE_MODE_READ, 0); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 size =3D 0; >> +=C2=A0=C2=A0=C2=A0 ret =3D EFI_CALL(f->getinfo(f, &efi_file_info_guid,= &size, NULL)); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_BUFFER_TOO_SMALL) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 buf =3D calloc(1, size); >> +=C2=A0=C2=A0=C2=A0 if (!buf) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D EFI_OUT_OF_RESOURCE= S; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> +=C2=A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0 ret =3D EFI_CALL(f->getinfo(f, &efi_file_info_guid,= &size, buf)); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> + >> +=C2=A0=C2=A0=C2=A0 size =3D ((struct efi_file_info *)buf)->file_size; >> +=C2=A0=C2=A0=C2=A0 free(buf); >> + >> +=C2=A0=C2=A0=C2=A0 buf =3D calloc(1, size); >> +=C2=A0=C2=A0=C2=A0 if (!buf) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D EFI_OUT_OF_RESOURCE= S; > > This leaves ret undefined and you get an error when compiling with clang= : > > +cmd/eficonfig_sbkey.c:208:6: error: variable 'ret' is used > uninitialized whenever 'if' condition is true > [-Werror,-Wsometimes-uninitialized] > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!file_info.current_path) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~~= ~~~~~~~~~~~~~~~~~~~ > +cmd/eficonfig_sbkey.c:294:9: note: uninitialized use occurs here > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D (ret =3D=3D EFI_ABOR= TED) ? EFI_NOT_READY : ret; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 ^~~ > +cmd/eficonfig_sbkey.c:208:2: note: remove the 'if' if its condition is > always false > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > +cmd/eficonfig_sbkey.c:201:18: note: initialize the variable 'ret' to > silence this warning > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi_status_t ret; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 =3D 0 > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D efi_file_read_int(f, &size, buf); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eficonfig_print_msg("ERROR!= Failed to read file."); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> +=C2=A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0 if (size =3D=3D 0) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eficonfig_print_msg("ERROR!= File is empty."); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 /* We expect that file is EFI Signature Lists or si= gned EFI >> Signature Lists */ >> +=C2=A0=C2=A0=C2=A0 if (!file_have_auth_header(buf, size)) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!file_is_efi_signature_= list(buf)) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi= config_print_msg("ERROR! Invalid file format."); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret= =3D EFI_INVALID_PARAMETER; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 got= o out; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D create_time_based_p= ayload(buf, &new_db, &size); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi= config_print_msg("ERROR! Failed to create payload with >> timestamp."); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 got= o out; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(buf); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 buf =3D new_db; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 attr =3D EFI_VARIABLE_NON_VOLATILE | >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EFI_VARIA= BLE_BOOTSERVICE_ACCESS | >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EFI_VARIA= BLE_RUNTIME_ACCESS | >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EFI_VARIA= BLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; >> + >> +=C2=A0=C2=A0=C2=A0 /* PK can enroll only one certificate */ >> +=C2=A0=C2=A0=C2=A0 if (u16_strcmp(data, u"PK")) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi_uintn_t db_size =3D 0; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* check the variable exist= s. If exists, add APPEND_WRITE >> attribute */ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D efi_get_variable_in= t(data, efi_auth_var_get_guid(data), >> NULL, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &db_size, = NULL,=C2=A0 NULL); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret =3D=3D EFI_BUFFER_T= OO_SMALL) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 att= r |=3D EFI_VARIABLE_APPEND_WRITE; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 ret =3D efi_set_variable_int((u16 *)data, >> efi_auth_var_get_guid((u16 *)data), >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 attr, size, buf, false); >> +=C2=A0=C2=A0=C2=A0 if (ret !=3D EFI_SUCCESS) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eficonfig_print_msg("ERROR!= Failed to update signature >> database"); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; > > This goto is superfluous. > > Best regards > > Heinrich > >> +=C2=A0=C2=A0=C2=A0 } >> + >> +out: >> +=C2=A0=C2=A0=C2=A0 free(file_info.current_path); >> +=C2=A0=C2=A0=C2=A0 free(buf); >> + >> +=C2=A0=C2=A0=C2=A0 /* to stay the parent menu */ >> +=C2=A0=C2=A0=C2=A0 ret =3D (ret =3D=3D EFI_ABORTED) ? EFI_NOT_READY : = ret; >> + >> +=C2=A0=C2=A0=C2=A0 return ret; >> +} >> + >> +static struct eficonfig_item key_config_menu_items[] =3D { >> +=C2=A0=C2=A0=C2=A0 {"Enroll New Key", eficonfig_process_enroll_key}, >> +=C2=A0=C2=A0=C2=A0 {"Quit", eficonfig_process_quit}, >> +}; >> + >> +/** >> + * eficonfig_process_set_secure_boot_key() - display the key >> configuration menu >> + * >> + * @data:=C2=A0=C2=A0=C2=A0 pointer to the data for each entry >> + * Return:=C2=A0=C2=A0=C2=A0 status code >> + */ >> +static efi_status_t eficonfig_process_set_secure_boot_key(void *data) >> +{ >> +=C2=A0=C2=A0=C2=A0 u32 i; >> +=C2=A0=C2=A0=C2=A0 efi_status_t ret; >> +=C2=A0=C2=A0=C2=A0 char header_str[32]; >> +=C2=A0=C2=A0=C2=A0 struct efimenu *efi_menu; >> + >> +=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < ARRAY_SIZE(key_config_menu_items)= ; i++) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key_config_menu_items[i].da= ta =3D data; >> + >> +=C2=A0=C2=A0=C2=A0 snprintf(header_str, sizeof(header_str), "=C2=A0 **= Configure %ls **", >> (u16 *)data); >> + >> +=C2=A0=C2=A0=C2=A0 while (1) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi_menu =3D eficonfig_crea= te_fixed_menu(key_config_menu_items, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ARRAY_SIZE(key_config_menu_items))= ; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D eficonfig_process_c= ommon(efi_menu, header_str); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eficonfig_destroy(efi_menu)= ; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret =3D=3D EFI_ABORTED) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 /* to stay the parent menu */ >> +=C2=A0=C2=A0=C2=A0 ret =3D (ret =3D=3D EFI_ABORTED) ? EFI_NOT_READY : = ret; >> + >> +=C2=A0=C2=A0=C2=A0 return ret; >> +} >> + > >> +static const struct eficonfig_item secure_boot_menu_items[] =3D { >> +=C2=A0=C2=A0=C2=A0 {"PK", eficonfig_process_set_secure_boot_key, u"PK"= }, >> +=C2=A0=C2=A0=C2=A0 {"KEK", eficonfig_process_set_secure_boot_key, u"KE= K"}, >> +=C2=A0=C2=A0=C2=A0 {"db", eficonfig_process_set_secure_boot_key, u"db"= }, >> +=C2=A0=C2=A0=C2=A0 {"dbx", eficonfig_process_set_secure_boot_key, u"db= x"}, >> +=C2=A0=C2=A0=C2=A0 {"Quit", eficonfig_process_quit} > +}; >> + >> +/** >> + * eficonfig_process_secure_boot_config() - display the key list menu >> + * >> + * @data:=C2=A0=C2=A0=C2=A0 pointer to the data for each entry >> + * Return:=C2=A0=C2=A0=C2=A0 status code >> + */ >> +efi_status_t eficonfig_process_secure_boot_config(void *data) >> +{ >> +=C2=A0=C2=A0=C2=A0 efi_status_t ret; >> +=C2=A0=C2=A0=C2=A0 struct efimenu *efi_menu; >> + >> +=C2=A0=C2=A0=C2=A0 while (1) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 char header_str[64]; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 snprintf(header_str, sizeof= (header_str), >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 "=C2=A0 ** UEFI Secure Boot Key Configuration (SecureBoot : >> %s) **", >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (is_secureboot_enabled() ? "ON" : "OFF")); >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi_menu =3D eficonfig_crea= te_fixed_menu(secure_boot_menu_items, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ARRAY_SIZE(secure_boot_menu_items)= ); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!efi_menu) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret= =3D EFI_OUT_OF_RESOURCES; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D eficonfig_process_c= ommon(efi_menu, header_str); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eficonfig_destroy(efi_menu)= ; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret =3D=3D EFI_ABORTED) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 /* to stay the parent menu */ >> +=C2=A0=C2=A0=C2=A0 ret =3D (ret =3D=3D EFI_ABORTED) ? EFI_NOT_READY : = ret; >> + >> +=C2=A0=C2=A0=C2=A0 return ret; >> +} >> diff --git a/include/efi_config.h b/include/efi_config.h >> index 86bc801211..6db8e123f0 100644 >> --- a/include/efi_config.h >> +++ b/include/efi_config.h >> @@ -99,5 +99,10 @@ efi_status_t eficonfig_append_menu_entry(struct >> efimenu *efi_menu, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 char *titl= e, eficonfig_entry_func func, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 void *data= ); >> =C2=A0 efi_status_t eficonfig_append_quit_entry(struct efimenu *efi_men= u); >> +void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, >> int count); >> + >> +#ifdef CONFIG_EFI_SECURE_BOOT >> +efi_status_t eficonfig_process_secure_boot_config(void *data); >> +#endif >> >> =C2=A0 #endif >