From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77323+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77323+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056479; cv=none; d=zohomail.com; s=zohoarc; b=On+2rDMUBRPTX/ClgRODeTIpzesu7f+PdePOOzdya57qQBUdtPbyAniSDbEsIUSxVC4BVIPlyLYaqCGLjU2BH4TyEr5FGyLeZFbA5scd6wGPB9Sm2NcpblA98VVKhp9D9QEBD7Tqa2aK/zYn9Mn3164o067hvrhP9wVVfSOgX9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056479; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=iw1CPyecGXC3L/gOkCevSE4Km7fJbqihhwe5j11zPmk=; b=mqf/z86lP01ExldBD3pM8aySFijRQuhSvVnTlvZGxD8T1iZuKIpN1bT+m1tMy/xo5HY5X1vjRgVOSQe5JuYEpMine86AHhBSSoeo6Pm/H3Gli+araf63Jh9a1rk7t27NNqO22GFz3mAI7wK0ILgN9xenCUHxKiMrVlcB7dJ4ESE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77323+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056479373293.82256242501785; Wed, 30 Jun 2021 05:34:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7nRDYY1788612xpdAEO8LIou; Wed, 30 Jun 2021 05:34:38 -0700 X-Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by mx.groups.io with SMTP id smtpd.web10.5327.1625056472831556883 for ; Wed, 30 Jun 2021 05:34:33 -0700 X-Received: by mail-lj1-f177.google.com with SMTP id q4so3012159ljp.13 for ; Wed, 30 Jun 2021 05:34:32 -0700 (PDT) X-Gm-Message-State: vC7OXRzDYNK1VoVDwAfSMSLQx1787277AA= X-Google-Smtp-Source: ABdhPJycQR45GImnb3iMOLFUFoMi6JuRACs4eeYBlmflfkpi5vFfWoxaS4nK7bjiOZEHIgTJ4V4uzA== X-Received: by 2002:a2e:888c:: with SMTP id k12mr7624386lji.185.1625056470241; Wed, 30 Jun 2021 05:34:30 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:29 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [PATCH v4 1/8] SecurityPkg: Create library for setting Secure Boot variables. Date: Wed, 30 Jun 2021 14:34:01 +0200 Message-Id: <20210630123412.996158-2-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056478; bh=UEhT99fS54ubgh3eGkmnlMJESslOWyHNC9i5XZvWbko=; h=Cc:Date:From:Reply-To:Subject:To; b=TUQhHpsl5dt98N/CO0l6jPH3xHJtz9qMWHV4OTY+P45xn1acWzvH8HUbAnu80xBAGDN +kOs92s39ukD4zFAobUrt2/RG7YHxKVj8oty+WnMigR1WAOJ0x2gvPw0PkBEy71xd3wzl i8YvDszqJ5GK93PzxMqW7F1cOS9ij7j0yQM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commits add library, which consist functions related creation/removal Secure Boot variables. Some of the functions was moved from SecureBootConfigImpl.c file. Signed-off-by: Grzegorz Bernacki --- SecurityPkg/SecurityPkg.dsc = | 1 + SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf = | 79 ++ SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.= inf | 1 + SecurityPkg/Include/Library/SecureBootVariableLib.h = | 251 +++++ SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c = | 980 ++++++++++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl= .c | 189 +--- SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.uni = | 16 + 7 files changed, 1329 insertions(+), 188 deletions(-) create mode 100644 SecurityPkg/Library/SecureBootVariableLib/SecureBootVar= iableLib.inf create mode 100644 SecurityPkg/Include/Library/SecureBootVariableLib.h create mode 100644 SecurityPkg/Library/SecureBootVariableLib/SecureBootVar= iableLib.c create mode 100644 SecurityPkg/Library/SecureBootVariableLib/SecureBootVar= iableLib.uni diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index bd4b810bce..854f250625 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -70,6 +70,7 @@ RpmcLib|SecurityPkg/Library/RpmcLibNull/RpmcLibNull.inf TcgEventLogRecordLib|SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLo= gRecordLib.inf MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf =20 [LibraryClasses.ARM] # diff --git a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLi= b.inf b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf new file mode 100644 index 0000000000..84367841d5 --- /dev/null +++ b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf @@ -0,0 +1,79 @@ +## @file +# Provides initialization of Secure Boot keys and databases. +# +# Copyright (c) 2021, ARM Ltd. All rights reserved.
+# Copyright (c) 2021, Semihalf All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SecureBootVariableLib + MODULE_UNI_FILE =3D SecureBootVariableLib.uni + FILE_GUID =3D D4FFF5CA-6D8E-4DBD-8A4B-7C7CEBD97F6F + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SecureBootVariableLib|DXE_DRIVER DXE_= RUNTIME_DRIVER UEFI_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + SecureBootVariableLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + CryptoPkg/CryptoPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + BaseCryptLib + DxeServicesLib + +[Guids] + ## CONSUMES ## Variable:L"SetupMode" + ## PRODUCES ## Variable:L"SetupMode" + ## CONSUMES ## Variable:L"SecureBoot" + ## PRODUCES ## Variable:L"SecureBoot" + ## PRODUCES ## Variable:L"PK" + ## PRODUCES ## Variable:L"KEK" + ## CONSUMES ## Variable:L"PKDefault" + ## CONSUMES ## Variable:L"KEKDefault" + ## CONSUMES ## Variable:L"dbDefault" + ## CONSUMES ## Variable:L"dbxDefault" + ## CONSUMES ## Variable:L"dbtDefault" + gEfiGlobalVariableGuid + + ## SOMETIMES_CONSUMES ## Variable:L"DB" + ## SOMETIMES_CONSUMES ## Variable:L"DBX" + ## SOMETIMES_CONSUMES ## Variable:L"DBT" + gEfiImageSecurityDatabaseGuid + + ## CONSUMES ## Variable:L"SecureBootEnable" + ## PRODUCES ## Variable:L"SecureBootEnable" + gEfiSecureBootEnableDisableGuid + + ## CONSUMES ## Variable:L"CustomMode" + ## PRODUCES ## Variable:L"CustomMode" + gEfiCustomModeEnableGuid + + gEfiCertTypeRsa2048Sha256Guid ## CONSUMES + gEfiCertX509Guid ## CONSUMES + gEfiCertPkcs7Guid ## CONSUMES + + gDefaultPKFileGuid + gDefaultKEKFileGuid + gDefaultdbFileGuid + gDefaultdbxFileGuid + gDefaultdbtFileGuid + diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Sec= ureBootConfigDxe.inf index 573efa6379..30d9cd8025 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf @@ -54,6 +54,7 @@ DevicePathLib FileExplorerLib PeCoffLib + SecureBootVariableLib =20 [Guids] ## SOMETIMES_CONSUMES ## Variable:L"CustomMode" diff --git a/SecurityPkg/Include/Library/SecureBootVariableLib.h b/Security= Pkg/Include/Library/SecureBootVariableLib.h new file mode 100644 index 0000000000..e010667165 --- /dev/null +++ b/SecurityPkg/Include/Library/SecureBootVariableLib.h @@ -0,0 +1,251 @@ +/** @file + Provides a function to enroll keys based on default values. + +Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2018 Hewlett Packard Enterprise Development LP
+Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __SECURE_BOOT_VARIABLE_LIB_H__ +#define __SECURE_BOOT_VARIABLE_LIB_H__ + +/** + Set the platform secure boot mode into "Custom" or "Standard" mode. + + @param[in] SecureBootMode New secure boot mode: STANDARD_SECURE= _BOOT_MODE or + CUSTOM_SECURE_BOOT_MODE. + + @return EFI_SUCCESS The platform has switched to the spec= ial mode successfully. + @return other Fail to operate the secure boot mode. + +--*/ +EFI_STATUS +SetSecureBootMode ( + IN UINT8 SecureBootMode +); + +/** + Fetches the value of SetupMode variable. + + @param[out] SetupMode Pointer to UINT8 for SetupMode output + + @retval other Error codes from GetVariable. +--*/ +EFI_STATUS +EFIAPI +GetSetupMode ( + OUT UINT8 *SetupMode +); + +/** + Create a time based data payload by concatenating the EFI_VARIABLE_AUTHE= NTICATION_2 + descriptor with the input data. NO authentication is required in this fu= nction. + + @param[in, out] DataSize On input, the size of Data buffer in by= tes. + On output, the size of data returned in= Data + buffer in bytes. + @param[in, out] Data On input, Pointer to data buffer to be = wrapped or + pointer to NULL to wrap an empty payloa= d. + On output, Pointer to the new payload d= ate buffer allocated from pool, + it's caller's responsibility to free th= e memory when finish using it. + + @retval EFI_SUCCESS Create time based payload successfully. + @retval EFI_OUT_OF_RESOURCES There are not enough memory resources t= o create time based payload. + @retval EFI_INVALID_PARAMETER The parameter is invalid. + @retval Others Unexpected error happens. + +--*/ +EFI_STATUS +CreateTimeBasedPayload ( + IN OUT UINTN *DataSize, + IN OUT UINT8 **Data +); + +/** + Sets the content of the 'db' variable based on 'dbDefault' variable cont= ent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +EnrollDbFromDefault ( + VOID +); + +/** + Clears the content of the 'db' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +DeleteDb ( + VOID +); + +/** + Sets the content of the 'dbx' variable based on 'dbxDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +EnrollDbxFromDefault ( + VOID +); + +/** + Clears the content of the 'dbx' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +DeleteDbx ( + VOID +); + +/** + Sets the content of the 'dbt' variable based on 'dbtDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +EnrollDbtFromDefault ( + VOID +); + +/** + Clears the content of the 'dbt' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +DeleteDbt ( + VOID +); + +/** + Sets the content of the 'KEK' variable based on 'KEKDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +EnrollKEKFromDefault ( + VOID +); + +/** + Clears the content of the 'KEK' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +DeleteKEK ( + VOID +); + +/** + Sets the content of the 'PK' variable based on 'PKDefault' variable cont= ent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +EnrollPKFromDefault ( + VOID +); + +/** + Clears the content of the 'PK' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2(), GetTime() = and SetVariable() +--*/ +EFI_STATUS +EFIAPI +DeletePlatformKey ( + VOID +); + +/** + Initializes PKDefault variable with data from FFS section. + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitPKDefault ( + IN VOID + ); + +/** + Initializes KEKDefault variable with data from FFS section. + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitKEKDefault ( + IN VOID + ); + +/** + Initializes dbDefault variable with data from FFS section. + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbDefault ( + IN VOID + ); + +/** + Initializes dbtDefault variable with data from FFS section. + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbtDefault ( + IN VOID + ); + +/** + Initializes dbxDefault variable with data from FFS section. + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbxDefault ( + IN VOID + ); +#endif diff --git a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLi= b.c b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c new file mode 100644 index 0000000000..f3dafeca6e --- /dev/null +++ b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c @@ -0,0 +1,980 @@ +/** @file + This library provides functions to set/clear Secure Boot + keys and databases. + +Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2018 Hewlett Packard Enterprise Development LP
+Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Library/DxeServicesLib.h" + +/** Creates EFI Signature List structure. + + @param[in] Data A pointer to signature data. + @param[in] Size Size of signature data. + @param[out] SigList Created Signature List. + + @retval EFI_SUCCESS Signature List was created successfully. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +--*/ +STATIC +EFI_STATUS +CreateSigList ( + IN VOID *Data, + IN UINTN Size, + OUT EFI_SIGNATURE_LIST **SigList + ) +{ + UINTN SigListSize; + EFI_SIGNATURE_LIST *TmpSigList; + EFI_SIGNATURE_DATA *SigData; + + // + // Allocate data for Signature Database + // + SigListSize =3D sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA= ) - 1 + Size; + TmpSigList =3D (EFI_SIGNATURE_LIST *) AllocateZeroPool (SigListSize); + if (TmpSigList =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Only gEfiCertX509Guid type is supported + // + TmpSigList->SignatureListSize =3D (UINT32)SigListSize; + TmpSigList->SignatureSize =3D (UINT32) (sizeof (EFI_SIGNATURE_DATA) - 1 = + Size); + TmpSigList->SignatureHeaderSize =3D 0; + CopyGuid (&TmpSigList->SignatureType, &gEfiCertX509Guid); + + // + // Copy key data + // + SigData =3D (EFI_SIGNATURE_DATA *) (TmpSigList + 1); + CopyGuid (&SigData->SignatureOwner, &gEfiGlobalVariableGuid); + CopyMem (&SigData->SignatureData[0], Data, Size); + + *SigList =3D TmpSigList; + + return EFI_SUCCESS; +} + +/** Adds new signature list to signature database. + + @param[in] SigLists A pointer to signature database. + @param[in] SiglListAppend A signature list to be added. + @param[out] *SigListOut Created signature database. + @param[out] SigListsSize A size of created signature database. + + @retval EFI_SUCCESS Signature List was added successfully. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +--*/ +STATIC +EFI_STATUS +ConcatenateSigList ( + IN EFI_SIGNATURE_LIST *SigLists, + IN EFI_SIGNATURE_LIST *SigListAppend, + OUT EFI_SIGNATURE_LIST **SigListOut, + IN OUT UINTN *SigListsSize +) +{ + EFI_SIGNATURE_LIST *TmpSigList; + UINT8 *Offset; + UINTN NewSigListsSize; + + NewSigListsSize =3D *SigListsSize + SigListAppend->SignatureListSize; + + TmpSigList =3D (EFI_SIGNATURE_LIST *) AllocateZeroPool (NewSigListsSize); + if (TmpSigList =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (TmpSigList, SigLists, *SigListsSize); + + Offset =3D (UINT8 *)TmpSigList; + Offset +=3D *SigListsSize; + CopyMem ((VOID *)Offset, SigListAppend, SigListAppend->SignatureListSize= ); + + *SigListsSize =3D NewSigListsSize; + *SigListOut =3D TmpSigList; + return EFI_SUCCESS; +} + +/** + Create a EFI Signature List with data fetched from section specified as = a argument. + Found keys are verified using RsaGetPublicKeyFromX509(). + + @param[in] KeyFileGuid A pointer to to the FFS filename GUID + @param[out] SigListsSize A pointer to size of signature list + @param[out] SigListsOut a pointer to a callee-allocated buffer = with signature lists + + @retval EFI_SUCCESS Create time based payload successfully. + @retval EFI_NOT_FOUND Section with key has not been found. + @retval EFI_INVALID_PARAMETER Embedded key has a wrong format. + @retval Others Unexpected error happens. + +--*/ +STATIC +EFI_STATUS +SecureBootFetchData ( + IN EFI_GUID *KeyFileGuid, + OUT UINTN *SigListsSize, + OUT EFI_SIGNATURE_LIST **SigListOut +) +{ + EFI_SIGNATURE_LIST *EfiSig; + EFI_SIGNATURE_LIST *TmpEfiSig; + EFI_SIGNATURE_LIST *TmpEfiSig2; + EFI_STATUS Status; + VOID *Buffer; + VOID *RsaPubKey; + UINTN Size; + UINTN KeyIndex; + + + KeyIndex =3D 0; + EfiSig =3D NULL; + *SigListsSize =3D 0; + while (1) { + Status =3D GetSectionFromAnyFv ( + KeyFileGuid, + EFI_SECTION_RAW, + KeyIndex, + &Buffer, + &Size + ); + + if (Status =3D=3D EFI_SUCCESS) { + RsaPubKey =3D NULL; + if (RsaGetPublicKeyFromX509 (Buffer, Size, &RsaPubKey) =3D=3D FALSE)= { + DEBUG ((DEBUG_ERROR, "%a: Invalid key format: %d\n", __FUNCTION__,= KeyIndex)); + if (EfiSig !=3D NULL) { + FreePool(EfiSig); + } + FreePool(Buffer); + return EFI_INVALID_PARAMETER; + } + + Status =3D CreateSigList (Buffer, Size, &TmpEfiSig); + + // + // Concatenate lists if more than one section found + // + if (KeyIndex =3D=3D 0) { + EfiSig =3D TmpEfiSig; + *SigListsSize =3D TmpEfiSig->SignatureListSize; + } else { + ConcatenateSigList (EfiSig, TmpEfiSig, &TmpEfiSig2, SigListsSize); + FreePool (EfiSig); + FreePool (TmpEfiSig); + EfiSig =3D TmpEfiSig2; + } + + KeyIndex++; + FreePool (Buffer); + } if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + }; + + if (KeyIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + *SigListOut =3D EfiSig; + + return EFI_SUCCESS; +} + +/** + Create a time based data payload by concatenating the EFI_VARIABLE_AUTHE= NTICATION_2 + descriptor with the input data. NO authentication is required in this fu= nction. + + @param[in, out] DataSize On input, the size of Data buffer in by= tes. + On output, the size of data returned in= Data + buffer in bytes. + @param[in, out] Data On input, Pointer to data buffer to be = wrapped or + pointer to NULL to wrap an empty payloa= d. + On output, Pointer to the new payload d= ate buffer allocated from pool, + it's caller's responsibility to free th= e memory when finish using it. + + @retval EFI_SUCCESS Create time based payload successfully. + @retval EFI_OUT_OF_RESOURCES There are not enough memory resources t= o create time based payload. + @retval EFI_INVALID_PARAMETER The parameter is invalid. + @retval Others Unexpected error happens. + +--*/ +EFI_STATUS +CreateTimeBasedPayload ( + IN OUT UINTN *DataSize, + IN OUT UINT8 **Data + ) +{ + EFI_STATUS Status; + UINT8 *NewData; + UINT8 *Payload; + UINTN PayloadSize; + EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData; + UINTN DescriptorSize; + EFI_TIME Time; + + if (Data =3D=3D NULL || DataSize =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // In Setup mode or Custom mode, the variable does not need to be signed= but the + // parameters to the SetVariable() call still need to be prepared as aut= henticated + // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor withou= t certificate + // data in it. + // + Payload =3D *Data; + PayloadSize =3D *DataSize; + + DescriptorSize =3D OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo= ) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData); + NewData =3D (UINT8*) AllocateZeroPool (DescriptorSize + PayloadSize); + if (NewData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + if ((Payload !=3D NULL) && (PayloadSize !=3D 0)) { + CopyMem (NewData + DescriptorSize, Payload, PayloadSize); + } + + DescriptorData =3D (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData); + + ZeroMem (&Time, sizeof (EFI_TIME)); + Status =3D gRT->GetTime (&Time, NULL); + if (EFI_ERROR (Status)) { + FreePool(NewData); + return Status; + } + Time.Pad1 =3D 0; + Time.Nanosecond =3D 0; + Time.TimeZone =3D 0; + Time.Daylight =3D 0; + Time.Pad2 =3D 0; + CopyMem (&DescriptorData->TimeStamp, &Time, sizeof (EFI_TIME)); + + DescriptorData->AuthInfo.Hdr.dwLength =3D OFFSET_OF (WIN_CERTIFI= CATE_UEFI_GUID, CertData); + DescriptorData->AuthInfo.Hdr.wRevision =3D 0x0200; + DescriptorData->AuthInfo.Hdr.wCertificateType =3D WIN_CERT_TYPE_EFI_GUID; + CopyGuid (&DescriptorData->AuthInfo.CertType, &gEfiCertPkcs7Guid); + + if (Payload !=3D NULL) { + FreePool(Payload); + } + + *DataSize =3D DescriptorSize + PayloadSize; + *Data =3D NewData; + return EFI_SUCCESS; +} + +/** + Internal helper function to delete a Variable given its name and GUID, N= O authentication + required. + + @param[in] VariableName Name of the Variable. + @param[in] VendorGuid GUID of the Variable. + + @retval EFI_SUCCESS Variable deleted successfully. + @retval Others The driver failed to start the device. + +--*/ +EFI_STATUS +DeleteVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status; + VOID* Variable; + UINT8 *Data; + UINTN DataSize; + UINT32 Attr; + + GetVariable2 (VariableName, VendorGuid, &Variable, NULL); + if (Variable =3D=3D NULL) { + return EFI_SUCCESS; + } + FreePool (Variable); + + Data =3D NULL; + DataSize =3D 0; + Attr =3D EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | E= FI_VARIABLE_BOOTSERVICE_ACCESS + | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; + + Status =3D CreateTimeBasedPayload (&DataSize, &Data); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Fail to create time-based data payload: %r", Sta= tus)); + return Status; + } + + Status =3D gRT->SetVariable ( + VariableName, + VendorGuid, + Attr, + DataSize, + Data + ); + if (Data !=3D NULL) { + FreePool (Data); + } + return Status; +} + +/** + + Set the platform secure boot mode into "Custom" or "Standard" mode. + + @param[in] SecureBootMode New secure boot mode: STANDARD_SECURE= _BOOT_MODE or + CUSTOM_SECURE_BOOT_MODE. + + @return EFI_SUCCESS The platform has switched to the spec= ial mode successfully. + @return other Fail to operate the secure boot mode. + +--*/ +EFI_STATUS +SetSecureBootMode ( + IN UINT8 SecureBootMode + ) +{ + return gRT->SetVariable ( + EFI_CUSTOM_MODE_NAME, + &gEfiCustomModeEnableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCES= S, + sizeof (UINT8), + &SecureBootMode + ); +} + + +/** + Enroll a key/certificate based on a default variable. + + @param[in] VariableName The name of the key/database. + @param[in] DefaultName The name of the default variable. + @param[in] VendorGuid The namespace (ie. vendor GUID) of the va= riable + + + @retval EFI_OUT_OF_RESOURCES Out of memory while allocating AuthHeader. + @retval EFI_SUCCESS Successful enrollment. + @return Error codes from GetTime () and SetVariab= le (). +--*/ +STATIC +EFI_STATUS +EnrollFromDefault ( + IN CHAR16 *VariableName, + IN CHAR16 *DefaultName, + IN EFI_GUID *VendorGuid + ) +{ + VOID *Data; + UINTN DataSize; + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + + DataSize =3D 0; + Status =3D GetVariable2 (DefaultName, &gEfiGlobalVariableGuid, &Data, &D= ataSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "error: GetVariable (\"%s): %r\n", DefaultName,= Status)); + return Status; + } + + CreateTimeBasedPayload (&DataSize, (UINT8 **)&Data); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Fail to create time-based data payload: %r", Sta= tus)); + return Status; + } + + // + // Allocate memory for auth variable + // + Status =3D gRT->SetVariable ( + VariableName, + VendorGuid, + (EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS), + DataSize, + Data + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "error: %a (\"%s\", %g): %r\n", __FUNCTION__, Var= iableName, + VendorGuid, Status)); + } + + if (Data !=3D NULL) { + FreePool (Data); + } + + return Status; +} + +/** Initializes PKDefault variable with data from FFS section. + + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitPKDefault ( + IN VOID + ) +{ + EFI_SIGNATURE_LIST *EfiSig; + UINTN SigListsSize; + EFI_STATUS Status; + UINT8 *Data; + UINTN DataSize; + + // + // Check if variable exists, if so do not change it + // + Status =3D GetVariable2 (EFI_PK_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariab= leGuid, (VOID **) &Data, &DataSize); + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EF= I_PK_DEFAULT_VARIABLE_NAME)); + FreePool (Data); + return EFI_UNSUPPORTED; + } + + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + return Status; + } + + // + // Variable does not exist, can be initialized + // + DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_PK_DEFAULT_VARI= ABLE_NAME)); + + Status =3D SecureBootFetchData (&gDefaultPKFileGuid, &SigListsSize, &Efi= Sig); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Content for %s not found\n", EFI_PK_DEFAULT_VARIA= BLE_NAME)); + return Status; + } + + Status =3D gRT->SetVariable ( + EFI_PK_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + SigListsSize, + (VOID *)EfiSig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Failed to set %s\n", EFI_PK_DEFAULT_VARIABLE_NAME= )); + } + + FreePool (EfiSig); + + return Status; +} + +/** Initializes KEKDefault variable with data from FFS section. + + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitKEKDefault ( + IN VOID + ) +{ + EFI_SIGNATURE_LIST *EfiSig; + UINTN SigListsSize; + EFI_STATUS Status; + UINT8 *Data; + UINTN DataSize; + + // + // Check if variable exists, if so do not change it + // + Status =3D GetVariable2 (EFI_KEK_DEFAULT_VARIABLE_NAME, &gEfiGlobalVaria= bleGuid, (VOID **) &Data, &DataSize); + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EF= I_KEK_DEFAULT_VARIABLE_NAME)); + FreePool (Data); + return EFI_UNSUPPORTED; + } + + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + return Status; + } + + // + // Variable does not exist, can be initialized + // + DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_KEK_DEFAULT_VAR= IABLE_NAME)); + + Status =3D SecureBootFetchData (&gDefaultKEKFileGuid, &SigListsSize, &Ef= iSig); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Content for %s not found\n", EFI_KEK_DEFAULT_VARI= ABLE_NAME)); + return Status; + } + + + Status =3D gRT->SetVariable ( + EFI_KEK_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + SigListsSize, + (VOID *)EfiSig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Failed to set %s\n", EFI_KEK_DEFAULT_VARIABLE_NAM= E)); + } + + FreePool (EfiSig); + + return Status; +} + +/** Initializes dbDefault variable with data from FFS section. + + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbDefault ( + IN VOID + ) +{ + EFI_SIGNATURE_LIST *EfiSig; + UINTN SigListsSize; + EFI_STATUS Status; + UINT8 *Data; + UINTN DataSize; + + Status =3D GetVariable2 (EFI_DB_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariab= leGuid, (VOID **) &Data, &DataSize); + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EF= I_DB_DEFAULT_VARIABLE_NAME)); + FreePool (Data); + return EFI_UNSUPPORTED; + } + + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + return Status; + } + + DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_DB_DEFAULT_VARI= ABLE_NAME)); + + Status =3D SecureBootFetchData (&gDefaultdbFileGuid, &SigListsSize, &Efi= Sig); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gRT->SetVariable ( + EFI_DB_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + SigListsSize, + (VOID *)EfiSig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Failed to set %s\n", EFI_DB_DEFAULT_VARIABLE_NA= ME)); + } + + FreePool (EfiSig); + + return Status; +} + +/** Initializes dbxDefault variable with data from FFS section. + + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbxDefault ( + IN VOID + ) +{ + EFI_SIGNATURE_LIST *EfiSig; + UINTN SigListsSize; + EFI_STATUS Status; + UINT8 *Data; + UINTN DataSize; + + // + // Check if variable exists, if so do not change it + // + Status =3D GetVariable2 (EFI_DBX_DEFAULT_VARIABLE_NAME, &gEfiGlobalVaria= bleGuid, (VOID **) &Data, &DataSize); + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EF= I_DBX_DEFAULT_VARIABLE_NAME)); + FreePool (Data); + return EFI_UNSUPPORTED; + } + + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + return Status; + } + + // + // Variable does not exist, can be initialized + // + DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_DBX_DEFAULT_VAR= IABLE_NAME)); + + Status =3D SecureBootFetchData (&gDefaultdbxFileGuid, &SigListsSize, &Ef= iSig); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Content for %s not found\n", EFI_DBX_DEFAULT_VARI= ABLE_NAME)); + return Status; + } + + Status =3D gRT->SetVariable ( + EFI_DBX_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + SigListsSize, + (VOID *)EfiSig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Failed to set %s\n", EFI_DBX_DEFAULT_VARIABLE_NAM= E)); + } + + FreePool (EfiSig); + + return Status; +} + +/** Initializes dbtDefault variable with data from FFS section. + + + @retval EFI_SUCCESS Variable was initialized successfully. + @retval EFI_UNSUPPORTED Variable already exists. +--*/ +EFI_STATUS +SecureBootInitdbtDefault ( + IN VOID + ) +{ + EFI_SIGNATURE_LIST *EfiSig; + UINTN SigListsSize; + EFI_STATUS Status; + UINT8 *Data; + UINTN DataSize; + + // + // Check if variable exists, if so do not change it + // + Status =3D GetVariable2 (EFI_DBT_DEFAULT_VARIABLE_NAME, &gEfiGlobalVaria= bleGuid, (VOID **) &Data, &DataSize); + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EF= I_DBT_DEFAULT_VARIABLE_NAME)); + FreePool (Data); + return EFI_UNSUPPORTED; + } + + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + return Status; + } + + // + // Variable does not exist, can be initialized + // + DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_DBT_DEFAULT_VAR= IABLE_NAME)); + + Status =3D SecureBootFetchData (&gDefaultdbtFileGuid, &SigListsSize, &Ef= iSig); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gRT->SetVariable ( + EFI_DBT_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + SigListsSize, + (VOID *)EfiSig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Failed to set %s\n", EFI_DBT_DEFAULT_VARIABLE_NAM= E)); + } + + FreePool (EfiSig); + + return EFI_SUCCESS; +} + +/** + Fetches the value of SetupMode variable. + + @param[out] SetupMode Pointer to UINT8 for SetupMode output + + @retval other Retval from GetVariable. +--*/ +EFI_STATUS +EFIAPI +GetSetupMode ( + OUT UINT8 *SetupMode +) +{ + UINTN Size; + EFI_STATUS Status; + + Size =3D sizeof (*SetupMode); + Status =3D gRT->GetVariable ( + EFI_SETUP_MODE_NAME, + &gEfiGlobalVariableGuid, + NULL, + &Size, + SetupMode + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} + +/** + Sets the content of the 'db' variable based on 'dbDefault' variable cont= ent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +EnrollDbFromDefault ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D EnrollFromDefault ( + EFI_IMAGE_SECURITY_DATABASE, + EFI_DB_DEFAULT_VARIABLE_NAME, + &gEfiImageSecurityDatabaseGuid + ); + + return Status; +} + +/** + Clears the content of the 'db' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +DeleteDb ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D DeleteVariable ( + EFI_IMAGE_SECURITY_DATABASE, + &gEfiImageSecurityDatabaseGuid + ); + + return Status; +} + +/** + Sets the content of the 'dbx' variable based on 'dbxDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +EnrollDbxFromDefault ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D EnrollFromDefault ( + EFI_IMAGE_SECURITY_DATABASE1, + EFI_DBX_DEFAULT_VARIABLE_NAME, + &gEfiImageSecurityDatabaseGuid + ); + + return Status; +} + +/** + Clears the content of the 'dbx' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +DeleteDbx ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D DeleteVariable ( + EFI_IMAGE_SECURITY_DATABASE1, + &gEfiImageSecurityDatabaseGuid + ); + + return Status; +} + +/** + Sets the content of the 'dbt' variable based on 'dbtDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +EnrollDbtFromDefault ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D EnrollFromDefault ( + EFI_IMAGE_SECURITY_DATABASE2, + EFI_DBT_DEFAULT_VARIABLE_NAME, + &gEfiImageSecurityDatabaseGuid); + + return Status; +} + +/** + Clears the content of the 'dbt' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +DeleteDbt ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D DeleteVariable ( + EFI_IMAGE_SECURITY_DATABASE2, + &gEfiImageSecurityDatabaseGuid + ); + + return Status; +} + +/** + Sets the content of the 'KEK' variable based on 'KEKDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +EnrollKEKFromDefault ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D EnrollFromDefault ( + EFI_KEY_EXCHANGE_KEY_NAME, + EFI_KEK_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid + ); + + return Status; +} + +/** + Clears the content of the 'KEK' variable. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +DeleteKEK ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D DeleteVariable ( + EFI_KEY_EXCHANGE_KEY_NAME, + &gEfiGlobalVariableGuid + ); + + return Status; +} + +/** + Sets the content of the 'KEK' variable based on 'KEKDefault' variable co= ntent. + + @retval EFI_OUT_OF_RESOURCES If memory allocation for EFI_VARIABLE_= AUTHENTICATION_2 fails + while VendorGuid is NULL. + @retval other Errors from GetVariable2 (), GetTime (= ) and SetVariable () +--*/ +EFI_STATUS +EFIAPI +EnrollPKFromDefault ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D EnrollFromDefault ( + EFI_PLATFORM_KEY_NAME, + EFI_PK_DEFAULT_VARIABLE_NAME, + &gEfiGlobalVariableGuid + ); + + return Status; +} + +/** + Remove the PK variable. + + @retval EFI_SUCCESS Delete PK successfully. + @retval Others Could not allow to delete PK. + +--*/ +EFI_STATUS +EFIAPI +DeletePlatformKey ( + VOID +) +{ + EFI_STATUS Status; + + Status =3D SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D DeleteVariable ( + EFI_PLATFORM_KEY_NAME, + &gEfiGlobalVariableGuid + ); + return Status; +} diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secu= reBootConfigImpl.c index e82bfe7757..67e5e594ed 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "SecureBootConfigImpl.h" #include +#include =20 CHAR16 mSecureBootStorageName[] =3D L"SECUREBOOT_CONFIGURATIO= N"; =20 @@ -237,168 +238,6 @@ SaveSecureBootVariable ( return Status; } =20 -/** - Create a time based data payload by concatenating the EFI_VARIABLE_AUTHE= NTICATION_2 - descriptor with the input data. NO authentication is required in this fu= nction. - - @param[in, out] DataSize On input, the size of Data buffer in by= tes. - On output, the size of data returned in= Data - buffer in bytes. - @param[in, out] Data On input, Pointer to data buffer to be = wrapped or - pointer to NULL to wrap an empty payloa= d. - On output, Pointer to the new payload d= ate buffer allocated from pool, - it's caller's responsibility to free th= e memory when finish using it. - - @retval EFI_SUCCESS Create time based payload successfully. - @retval EFI_OUT_OF_RESOURCES There are not enough memory resources t= o create time based payload. - @retval EFI_INVALID_PARAMETER The parameter is invalid. - @retval Others Unexpected error happens. - -**/ -EFI_STATUS -CreateTimeBasedPayload ( - IN OUT UINTN *DataSize, - IN OUT UINT8 **Data - ) -{ - EFI_STATUS Status; - UINT8 *NewData; - UINT8 *Payload; - UINTN PayloadSize; - EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData; - UINTN DescriptorSize; - EFI_TIME Time; - - if (Data =3D=3D NULL || DataSize =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // In Setup mode or Custom mode, the variable does not need to be signed= but the - // parameters to the SetVariable() call still need to be prepared as aut= henticated - // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor withou= t certificate - // data in it. - // - Payload =3D *Data; - PayloadSize =3D *DataSize; - - DescriptorSize =3D OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo= ) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData); - NewData =3D (UINT8*) AllocateZeroPool (DescriptorSize + PayloadSize); - if (NewData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - if ((Payload !=3D NULL) && (PayloadSize !=3D 0)) { - CopyMem (NewData + DescriptorSize, Payload, PayloadSize); - } - - DescriptorData =3D (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData); - - ZeroMem (&Time, sizeof (EFI_TIME)); - Status =3D gRT->GetTime (&Time, NULL); - if (EFI_ERROR (Status)) { - FreePool(NewData); - return Status; - } - Time.Pad1 =3D 0; - Time.Nanosecond =3D 0; - Time.TimeZone =3D 0; - Time.Daylight =3D 0; - Time.Pad2 =3D 0; - CopyMem (&DescriptorData->TimeStamp, &Time, sizeof (EFI_TIME)); - - DescriptorData->AuthInfo.Hdr.dwLength =3D OFFSET_OF (WIN_CERTIFI= CATE_UEFI_GUID, CertData); - DescriptorData->AuthInfo.Hdr.wRevision =3D 0x0200; - DescriptorData->AuthInfo.Hdr.wCertificateType =3D WIN_CERT_TYPE_EFI_GUID; - CopyGuid (&DescriptorData->AuthInfo.CertType, &gEfiCertPkcs7Guid); - - if (Payload !=3D NULL) { - FreePool(Payload); - } - - *DataSize =3D DescriptorSize + PayloadSize; - *Data =3D NewData; - return EFI_SUCCESS; -} - -/** - Internal helper function to delete a Variable given its name and GUID, N= O authentication - required. - - @param[in] VariableName Name of the Variable. - @param[in] VendorGuid GUID of the Variable. - - @retval EFI_SUCCESS Variable deleted successfully. - @retval Others The driver failed to start the device. - -**/ -EFI_STATUS -DeleteVariable ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid - ) -{ - EFI_STATUS Status; - VOID* Variable; - UINT8 *Data; - UINTN DataSize; - UINT32 Attr; - - GetVariable2 (VariableName, VendorGuid, &Variable, NULL); - if (Variable =3D=3D NULL) { - return EFI_SUCCESS; - } - FreePool (Variable); - - Data =3D NULL; - DataSize =3D 0; - Attr =3D EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | E= FI_VARIABLE_BOOTSERVICE_ACCESS - | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; - - Status =3D CreateTimeBasedPayload (&DataSize, &Data); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "Fail to create time-based data payload: %r", Sta= tus)); - return Status; - } - - Status =3D gRT->SetVariable ( - VariableName, - VendorGuid, - Attr, - DataSize, - Data - ); - if (Data !=3D NULL) { - FreePool (Data); - } - return Status; -} - -/** - - Set the platform secure boot mode into "Custom" or "Standard" mode. - - @param[in] SecureBootMode New secure boot mode: STANDARD_SECURE= _BOOT_MODE or - CUSTOM_SECURE_BOOT_MODE. - - @return EFI_SUCCESS The platform has switched to the spec= ial mode successfully. - @return other Fail to operate the secure boot mode. - -**/ -EFI_STATUS -SetSecureBootMode ( - IN UINT8 SecureBootMode - ) -{ - return gRT->SetVariable ( - EFI_CUSTOM_MODE_NAME, - &gEfiCustomModeEnableGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCES= S, - sizeof (UINT8), - &SecureBootMode - ); -} - /** This code checks if the encode type and key strength of X.509 certificate is qualified. @@ -646,32 +485,6 @@ ON_EXIT: return Status; } =20 -/** - Remove the PK variable. - - @retval EFI_SUCCESS Delete PK successfully. - @retval Others Could not allow to delete PK. - -**/ -EFI_STATUS -DeletePlatformKey ( - VOID -) -{ - EFI_STATUS Status; - - Status =3D SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D DeleteVariable ( - EFI_PLATFORM_KEY_NAME, - &gEfiGlobalVariableGuid - ); - return Status; -} - /** Enroll a new KEK item from public key storing file (*.pbk). =20 diff --git a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLi= b.uni b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.uni new file mode 100644 index 0000000000..2c51e4db53 --- /dev/null +++ b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.uni @@ -0,0 +1,16 @@ +// /** @file +// +// Provides initialization of Secure Boot keys and databases. +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Provides function= to initialize PK, KEK and databases based on default variables." + +#string STR_MODULE_DESCRIPTION #language en-US "Provides function= to initialize PK, KEK and databases based on default variables." + --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77323): https://edk2.groups.io/g/devel/message/77323 Mute This Topic: https://groups.io/mt/83891028/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77324+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77324+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056480; cv=none; d=zohomail.com; s=zohoarc; b=Z3HEy2UooNgHhIgvZtxFwqLfQFJBAyKV3w4cptdAoNGwQizPV+7sqIr7PGPUjc0W8hKz7ibgLYLiCJkjWIHnwVR6xaBfuW/2LJzGfMIO5hoWM/RvjulyrJVzXl6HH8trPlb+4ic/W5ymrizRRuXcMB8brMaH+vqy9Cd7doroU6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056480; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=FrFEXkScAkkZ+4xol9B3N3dfgzLQrxnyLtS6H0TebfE=; b=DJAcBUIM5nuuesG4EXtddfJEOHZNE9Be9K6rZJWlNsdJIZFZ2104MU92x3D7YX2IVLtGumgMxM2u/9YNjmO4DtVWUTVd7jRGvsG3jIzsPkumDEOi2onUmM+iPbM/5TGPn2TeNMfSQNDcAZ/utst5Cm7RzJw8B17JtC0+ivwxmlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77324+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056480148228.39347850808258; Wed, 30 Jun 2021 05:34:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4pvbYY1788612xobMfWPsUO5; Wed, 30 Jun 2021 05:34:39 -0700 X-Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web09.5196.1625056473514672460 for ; Wed, 30 Jun 2021 05:34:34 -0700 X-Received: by mail-lf1-f51.google.com with SMTP id w19so4797020lfk.5 for ; Wed, 30 Jun 2021 05:34:33 -0700 (PDT) X-Gm-Message-State: TO9v0C3YUb5ECxOaoItgPsVvx1787277AA= X-Google-Smtp-Source: ABdhPJyOxbJmoaQi6BCULbWplm5FjQivhwNWK8bdp6hFcS3lXDieKLptYno/RU/OT5rardBgBlXc4Q== X-Received: by 2002:a05:6512:314c:: with SMTP id s12mr4164833lfi.349.1625056471649; Wed, 30 Jun 2021 05:34:31 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:31 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [PATCH v4 2/8] ArmVirtPkg: add SecureBootVariableLib class resolution Date: Wed, 30 Jun 2021 14:34:02 +0200 Message-Id: <20210630123412.996158-3-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056479; bh=W0G9HP/6Fct0iaYvZwvea/1BNiiA4w3GZ0WV4ZwiOxo=; h=Cc:Date:From:Reply-To:Subject:To; b=w0e9sC9c8YYKwROl6TeFk5futS2H0sbWJ3kv2Tq8QmVSanZo5Cvt+a94uPs9F15dTFN D6JftbmZvSpVyK5KTxsoyCCAun2CGCFQX/hys9FzTTRKmvkwatOdXV20x/wpbss8Z36G4 aoEekqeY/v0b/1mAWDP7JLTiq6EtgaDhtAM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The edk2 patch SecurityPkg: Create library for setting Secure Boot variables. removes generic functions from SecureBootConfigDxe and places them into SecureBootVariableLib. This patch adds SecureBootVariableLib mapping for ArmVirtPkg platform. Signed-off-by: Grzegorz Bernacki --- ArmVirtPkg/ArmVirt.dsc.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index d9abadbe70..11c1f53537 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -168,6 +168,7 @@ # !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf =20 # re-use the UserPhysicalPresent() dummy implementation from the ovmf tr= ee PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77324): https://edk2.groups.io/g/devel/message/77324 Mute This Topic: https://groups.io/mt/83891029/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77325+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77325+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056481; cv=none; d=zohomail.com; s=zohoarc; b=lEE/XaJ92ZUkGqT6HUU6whrrDOluYECBDiUoZpD8qnwsSadcOMzn18Tvcy9wXg5FNaKm4GGAGOOLD6RsRJ0ov2gLDtFYVdnwNKhrL4XCibWQPNO1nnUgCG+6l3smE1B1iAqvb6T/pEZiUZaYinuoE3FJuSP1s1hrG0bPUQouIGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056481; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AlwyVLA7sTANq7FYot1lo6XRehj0n4LbC16ftv3KQGA=; b=j61yRzG2tYPwQMfwWZtYQe+bx0bi8HlwBTc0Lka5uQBZZRorFwu3rxEVH+OAk9QW8+nHff4VPCGuZetfgkFvc2oTTQYnw6P5JITm/jtRtT1GhvEWe3WXh0PvgmwBJ1qzkjxLuD2QaGsNxuEoItWLZSe9+deo0i/fBj82WTDplyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77325+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056481146245.12445610364603; Wed, 30 Jun 2021 05:34:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 56HfYY1788612xiwnCwUFAnK; Wed, 30 Jun 2021 05:34:40 -0700 X-Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by mx.groups.io with SMTP id smtpd.web09.5197.1625056474968363767 for ; Wed, 30 Jun 2021 05:34:35 -0700 X-Received: by mail-lj1-f169.google.com with SMTP id k8so3076648lja.4 for ; Wed, 30 Jun 2021 05:34:34 -0700 (PDT) X-Gm-Message-State: XyKm9PKEEg9xqaNb7imJIhE3x1787277AA= X-Google-Smtp-Source: ABdhPJyyXaFXIPugIP7VIHRSCcw7FTQbroNQdZErQmQmjDZ78CkghbHTxZzMbrbQXCdQiaeaCu1Rnw== X-Received: by 2002:a05:651c:211b:: with SMTP id a27mr7721528ljq.211.1625056473085; Wed, 30 Jun 2021 05:34:33 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:32 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [PATCH v4 3/8] Intel Platforms: add SecureBootVariableLib class resolution Date: Wed, 30 Jun 2021 14:34:03 +0200 Message-Id: <20210630123412.996158-4-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056480; bh=000jDl3ZSQSycHCRhJegVf0EHn0e69kVMUrubOGNLSQ=; h=Cc:Date:From:Reply-To:Subject:To; b=rgpCd+ER9RMF/ulX519jl0bGb0mF1jnAkout4PQLKcdWX29sjNW1fsvRf8vDVsj5boD uK8QhleZDRMYeqP5dqGkIEeQpuIy9IeVd+taOvHpa08hWIkenarUB/j1vM1VWr6YojDP9 rxHQzvbMSkecsC9NfQavmbCW+5mYxB2NwPY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The edk2 patch SecurityPkg: Create library for setting Secure Boot variables. removes generic functions from SecureBootConfigDxe and places them into SecureBootVariableLib. This patch adds SecureBootVariableLib mapping for each Intel platform which uses SecureBootConfigDxe. Signed-off-by: Grzegorz Bernacki --- EmulatorPkg/EmulatorPkg.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 5 files changed, 5 insertions(+) diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index 20e5468398..966cc7af01 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -132,6 +132,7 @@ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index cbf896e89b..bcc0b2f2f4 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -196,6 +196,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Bhyve/Library/PlatformSecureLib/PlatformSecure= Lib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index f53efeae79..9225966541 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -204,6 +204,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index b3662e17f2..5d53327edb 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -208,6 +208,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 0a237a9058..509acf7926 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -208,6 +208,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77325): https://edk2.groups.io/g/devel/message/77325 Mute This Topic: https://groups.io/mt/83891031/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77326+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77326+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056477; cv=none; d=zohomail.com; s=zohoarc; b=Cw/+Z2J9IfCVDnEfjPW/1L0GwjFK8K/Ly101iKhMmPSIP7MZCAiK/ZfQs2fmuDP01AfTlIXtt4EXHVXgSAfhVoouJ+lWEsoO+mL++qP1GJvRSx/8bjIjRANNwxOwQGODaxFhBgBlDyGBejtu4DlwahIewyES2kwFjsq74KvBcB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056477; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=FwkJX4eLagzULPE1larpmpdaGd3L7TaehQ+R7F2EsMA=; b=WXqE36NkPj9DyLxLO5GAucGAxBDEQu1zmcBmPi9ni+gqsMv2awWvAlgCEF7NVb7Lw9nTG1zjO9V7eV6KpLvR9GeY/ZQdqwu4Jur9zb2nuvQwcI4+YR9DdYhXRzEs9hul7nCHVa4nKBBJgpUYNGOBufMmw8rypi8DChCy9vSKveQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77326+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056477740865.3902963945568; Wed, 30 Jun 2021 05:34:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ImA7YY1788612xtGkFDGhMtj; Wed, 30 Jun 2021 05:34:37 -0700 X-Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by mx.groups.io with SMTP id smtpd.web12.5199.1625056476534248827 for ; Wed, 30 Jun 2021 05:34:36 -0700 X-Received: by mail-lj1-f173.google.com with SMTP id u20so3013663ljo.12 for ; Wed, 30 Jun 2021 05:34:36 -0700 (PDT) X-Gm-Message-State: srMHrDu2pNkauwZewj1yUi2vx1787277AA= X-Google-Smtp-Source: ABdhPJwfKHmlyvgUfVn/a09WY1FUFuG04XJmxr66m7NPiZKYRmD/ABzXr9jFywkMZfIh8bZ1FXH1rA== X-Received: by 2002:a2e:b5d4:: with SMTP id g20mr7640916ljn.509.1625056474445; Wed, 30 Jun 2021 05:34:34 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:34 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [PATCH v4 4/8] ArmPlatformPkg: Create include file for default key content. Date: Wed, 30 Jun 2021 14:34:04 +0200 Message-Id: <20210630123412.996158-5-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056477; bh=9fUL6vX5FCBDN1aiqdKUnxQcggZn4VGObvsah1ceNYU=; h=Cc:Date:From:Reply-To:Subject:To; b=l8G5eUEFibx4ekA9pyWQRdwPb3WGTfFg0aBsuCSLrgFvGZBbJYyKYuNWSPbCGWWrDhQ q1BaapZuHMCAtDBZGsDL6varMImjt5s37+7erc9Q/pEXB02fSeaAe/lE31eQJ/9UOifGw miIQvBVBpXXhJubnnEijWKRGNfZJAQyRlb4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commits add file which can be included by platform Flash Description File. It allows to specify certificate files, which will be embedded into binary file. The content of these files can be used to initialize Secure Boot default keys and databases. Signed-off-by: Grzegorz Bernacki --- ArmPlatformPkg/SecureBootDefaultKeys.fdf.inc | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ArmPlatformPkg/SecureBootDefaultKeys.fdf.inc diff --git a/ArmPlatformPkg/SecureBootDefaultKeys.fdf.inc b/ArmPlatformPkg/= SecureBootDefaultKeys.fdf.inc new file mode 100644 index 0000000000..bf4f2d42de --- /dev/null +++ b/ArmPlatformPkg/SecureBootDefaultKeys.fdf.inc @@ -0,0 +1,70 @@ +## @file +# FDF include file which allows to embed Secure Boot keys +# +# Copyright (c) 2021, ARM Limited. All rights reserved. +# Copyright (c) 2021, Semihalf. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +!if $(DEFAULT_KEYS) =3D=3D TRUE + FILE FREEFORM =3D 85254ea7-4759-4fc4-82d4-5eed5fb0a4a0 { + !ifdef $(PK_DEFAULT_FILE) + SECTION RAW =3D $(PK_DEFAULT_FILE) + !endif + SECTION UI =3D "PK Default" + } + + FILE FREEFORM =3D 6f64916e-9f7a-4c35-b952-cd041efb05a3 { + !ifdef $(KEK_DEFAULT_FILE1) + SECTION RAW =3D $(KEK_DEFAULT_FILE1) + !endif + !ifdef $(KEK_DEFAULT_FILE2) + SECTION RAW =3D $(KEK_DEFAULT_FILE2) + !endif + !ifdef $(KEK_DEFAULT_FILE3) + SECTION RAW =3D $(KEK_DEFAULT_FILE3) + !endif + SECTION UI =3D "KEK Default" + } + + FILE FREEFORM =3D c491d352-7623-4843-accc-2791a7574421 { + !ifdef $(DB_DEFAULT_FILE1) + SECTION RAW =3D $(DB_DEFAULT_FILE1) + !endif + !ifdef $(DB_DEFAULT_FILE2) + SECTION RAW =3D $(DB_DEFAULT_FILE2) + !endif + !ifdef $(DB_DEFAULT_FILE3) + SECTION RAW =3D $(DB_DEFAULT_FILE3) + !endif + SECTION UI =3D "DB Default" + } + + FILE FREEFORM =3D 36c513ee-a338-4976-a0fb-6ddba3dafe87 { + !ifdef $(DBT_DEFAULT_FILE1) + SECTION RAW =3D $(DBT_DEFAULT_FILE1) + !endif + !ifdef $(DBT_DEFAULT_FILE2) + SECTION RAW =3D $(DBT_DEFAULT_FILE2) + !endif + !ifdef $(DBT_DEFAULT_FILE3) + SECTION RAW =3D $(DBT_DEFAULT_FILE3) + !endif + SECTION UI =3D "DBT Default" + } + + FILE FREEFORM =3D 5740766a-718e-4dc0-9935-c36f7d3f884f { + !ifdef $(DBX_DEFAULT_FILE1) + SECTION RAW =3D $(DBX_DEFAULT_FILE1) + !endif + !ifdef $(DBX_DEFAULT_FILE2) + SECTION RAW =3D $(DBX_DEFAULT_FILE2) + !endif + !ifdef $(DBX_DEFAULT_FILE3) + SECTION RAW =3D $(DBX_DEFAULT_FILE3) + !endif + SECTION UI =3D "DBX Default" + } + +!endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77326): https://edk2.groups.io/g/devel/message/77326 Mute This Topic: https://groups.io/mt/83891032/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77327+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77327+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056484; cv=none; d=zohomail.com; s=zohoarc; b=a84CfBr9uFTg8OFnA2EIVKShylQbtrEnpIKG6qsuIr7tElP603qkGsLe/+uC8rHZh+wewqE3Uq64TPTJ1mIGQrOpPMYx2HtqO9RdTmd3ZJ/P/K4Mkl5Zmv94eiY/3ivsu9PATCCUS6X5YW7WCUIE902XNHMEklVpvH94T3vqHNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056484; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=s5X9xgMfTyLvoB8ImdwuEG+uFtutmn84eQDA1h/isGg=; b=Z84xIdzT9F4T7ZEleYZvAfNM1de4x/NKjEKBFQa8p9Pwg3/SRMaLjJ7uC59YTVzfnS2KD3XCSjArKuBkgcQhO7UxtFmM6CrsFJWP/rQpjWgHckqLYhyCTfE8NrxyaFEUAw1k/54dvy6yUsetdAjm12e8pyfJkKR4YvnYK1wSplk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77327+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056484072362.8417785146736; Wed, 30 Jun 2021 05:34:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id okEzYY1788612xpCSVaHmsKm; Wed, 30 Jun 2021 05:34:43 -0700 X-Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.5328.1625056477912359220 for ; Wed, 30 Jun 2021 05:34:38 -0700 X-Received: by mail-lf1-f43.google.com with SMTP id q18so4784039lfc.7 for ; Wed, 30 Jun 2021 05:34:37 -0700 (PDT) X-Gm-Message-State: pcfFVAkeqL2veyoltxQnc5ocx1787277AA= X-Google-Smtp-Source: ABdhPJzKdWKr5YO63tPB3kby+Y+ew4CCC0WKM4UreY6CFqvB0feIFw4IxYv1l3HSmuY2+U47lKycAw== X-Received: by 2002:ac2:5095:: with SMTP id f21mr27513845lfm.246.1625056475978; Wed, 30 Jun 2021 05:34:35 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:35 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki , Sunny Wang Subject: [edk2-devel] [PATCH v4 5/8] SecurityPkg: Add SecureBootDefaultKeysDxe driver Date: Wed, 30 Jun 2021 14:34:05 +0200 Message-Id: <20210630123412.996158-6-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056483; bh=Q7DFFhsM9VvrFdBsDra3CrrGD+GB3KWzBkZ3/Bmw+cM=; h=Cc:Date:From:Reply-To:Subject:To; b=oNOvHLCOkqcnoMU5wFZ9WDG6fysuz0XnaEs5zMSrxHlMxfA2LY1j8+KnZdAErqcjT8t HRxEcc+ykEGYr8oXstJI8o7gyeSXNat0D9glAvFlke7QptRhc7z3+Q0LqSVKADj8gYDWK 7NXIxEKl7KNf4cP1emApXY0sAFO1uym2URU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This driver initializes default Secure Boot keys and databases based on keys embedded in flash. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang Reviewed-by: Pete Batard Tested-by: Pete Batard on Raspberry Pi --- SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefau= ltKeysDxe.inf | 45 +++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefau= ltKeysDxe.c | 68 ++++++++++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefau= ltKeysDxe.uni | 16 +++++ 3 files changed, 129 insertions(+) create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeys= Dxe/SecureBootDefaultKeysDxe.inf create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeys= Dxe/SecureBootDefaultKeysDxe.c create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeys= Dxe/SecureBootDefaultKeysDxe.uni diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/Sec= ureBootDefaultKeysDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootDef= aultKeysDxe/SecureBootDefaultKeysDxe.inf new file mode 100644 index 0000000000..0af7563a3b --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoot= DefaultKeysDxe.inf @@ -0,0 +1,45 @@ +## @file +# Initializes Secure Boot default keys +# +# Copyright (c) 2021, ARM Ltd. All rights reserved.
+# Copyright (c) 2021, Semihalf All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SecureBootDefaultKeysDxe + FILE_GUID =3D C937FCB7-25AC-4376-89A2-4EA8B317DE83 + MODULE_TYPE =3D DXE_DRIVER + ENTRY_POINT =3D SecureBootDefaultKeysEntryPoint + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# +[Sources] + SecureBootDefaultKeysDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MemoryAllocationLib + UefiDriverEntryPoint + DebugLib + SecureBootVariableLib + +[Guids] + ## SOMETIMES_PRODUCES ## Variable:L"PKDefault" + ## SOMETIMES_PRODUCES ## Variable:L"KEKDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbtDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbxDefault" + gEfiGlobalVariableGuid + +[Depex] + gEfiVariableArchProtocolGuid AND + gEfiVariableWriteArchProtocolGuid diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/Sec= ureBootDefaultKeysDxe.c b/SecurityPkg/VariableAuthenticated/SecureBootDefau= ltKeysDxe/SecureBootDefaultKeysDxe.c new file mode 100644 index 0000000000..12a18dc352 --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoot= DefaultKeysDxe.c @@ -0,0 +1,68 @@ +/** @file + This driver init default Secure Boot variables + +Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + The entry point for SecureBootDefaultKeys driver. + + @param[in] ImageHandle The image handle of the driver. + @param[in] SystemTable The system table. + + @retval EFI_ALREADY_STARTED The driver already exists in system. + @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack o= f resources. + @retval EFI_SUCCESS All the related protocols are installed o= n the driver. + @retval Others Fail to get the SecureBootEnable variable. + +**/ +EFI_STATUS +EFIAPI +SecureBootDefaultKeysEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D SecureBootInitPKDefault (); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __FUNCTIO= N__, Status)); + return Status; + } + + Status =3D SecureBootInitKEKDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", __FUNCT= ION__, Status)); + return Status; + } + Status =3D SecureBootInitdbDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", __FUNCTI= ON__, Status)); + return Status; + } + + Status =3D SecureBootInitdbtDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: dbtDefault not initialized\n", __FUNCTION__)); + } + + Status =3D SecureBootInitdbxDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: dbxDefault not initialized\n", __FUNCTION__)); + } + + return Status; +} diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/Sec= ureBootDefaultKeysDxe.uni b/SecurityPkg/VariableAuthenticated/SecureBootDef= aultKeysDxe/SecureBootDefaultKeysDxe.uni new file mode 100644 index 0000000000..2b6cb7f950 --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoot= DefaultKeysDxe.uni @@ -0,0 +1,16 @@ +// /** @file +// Provides the capability to intialize Secure Boot default variables +// +// Module which initializes Secure boot default variables. +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Module which init= ializes Secure boot default variables" + +#string STR_MODULE_DESCRIPTION #language en-US "This module reads= embedded keys and initializes Secure Boot default variables." --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77327): https://edk2.groups.io/g/devel/message/77327 Mute This Topic: https://groups.io/mt/83891033/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77328+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77328+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056485; cv=none; d=zohomail.com; s=zohoarc; b=Dw2kd/WZUDXhxo4U9F5j1SxRNoqS+pzReeIouBlCR2FYN630vc4oNornfvIwkm2OrNiVyeVpIW4fmvxRoKORTOQ79fMpQ6+Mb2SUFcAaebPNry255Pw6b2yN5zMxlY+mK06tF/AqfPypy9Sq7wJ4IohGbGqriFqP1d9An78YJaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056485; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YLOwOZnOX/reRAsZnRGT/eY1z3nbznypeK4PqWR+YT0=; b=HoJ/OmEKfSqI7z0Q0rVImbJS42EqoaMuhQCmOUhbb1U4nv4hJW91nSIFshS5Bm9ffTtUauV0Vvv4A5bMu4grNkC7O/lkvP34wXikNz8QIjT5I8DVIXXjznUwiIm9uvTzJuZ+mnuT+PGA7r2bILN6lUD1x+PPlkY26r+fKhmDqV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77328+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 162505648547721.775249325289224; Wed, 30 Jun 2021 05:34:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mhJNYY1788612xM1Qqngm7jL; Wed, 30 Jun 2021 05:34:45 -0700 X-Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by mx.groups.io with SMTP id smtpd.web08.5139.1625056479443217548 for ; Wed, 30 Jun 2021 05:34:39 -0700 X-Received: by mail-lf1-f53.google.com with SMTP id a11so4748104lfg.11 for ; Wed, 30 Jun 2021 05:34:39 -0700 (PDT) X-Gm-Message-State: qdFlVu363Y38VkHc3Dh8cVLLx1787277AA= X-Google-Smtp-Source: ABdhPJyRA8eJhjfcHjciXdDHbdru2B5obWxO+QWttw/waqGSAxEHIl7ACFAdZ60TrJ9X8QW6jRoflg== X-Received: by 2002:ac2:4187:: with SMTP id z7mr10040882lfh.574.1625056477453; Wed, 30 Jun 2021 05:34:37 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:37 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [PATCH v4 6/8] SecurityPkg: Add EnrollFromDefaultKeys application. Date: Wed, 30 Jun 2021 14:34:06 +0200 Message-Id: <20210630123412.996158-7-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056485; bh=5boerhW7iwndWUXJHRYOcuMos8a/mw7bib+pO9Gusg0=; h=Cc:Date:From:Reply-To:Subject:To; b=gYez63FgglAdNzq9lPFyVhV0qqRinjC/BVP8y+W/qGeVu5lt6QbTPySq8l9ox7M+OSi Cy3xcFg3CyqAY5XAgxdxu5Wq68uo368OxAP2RTtbI2IvVsA+iYHfNmwcz7xbGdSDXIRMC 5SuBmjfN+jPqXSrRGILAk+tyr8+hBCuNCZc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This application allows user to force key enrollment from Secure Boot default variables. Signed-off-by: Grzegorz Bernacki --- SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf | 47 ++= +++++++ SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c | 109 ++= ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultK= eysApp.inf create mode 100644 SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultK= eysApp.c diff --git a/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.= inf b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf new file mode 100644 index 0000000000..4d79ca3844 --- /dev/null +++ b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf @@ -0,0 +1,47 @@ +## @file +# Enroll PK, KEK, db, dbx from Default variables +# +# Copyright (c) 2021, ARM Ltd. All rights reserved.
+# Copyright (c) 2021, Semihalf All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.28 + BASE_NAME =3D EnrollFromDefaultKeysApp + FILE_GUID =3D 6F18CB2F-1293-4BC1-ABB8-35F84C71812E + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 0.1 + ENTRY_POINT =3D UefiMain + +[Sources] + EnrollFromDefaultKeysApp.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[Guids] + gEfiCertPkcs7Guid + gEfiCertSha256Guid + gEfiCertX509Guid + gEfiCustomModeEnableGuid + gEfiGlobalVariableGuid + gEfiImageSecurityDatabaseGuid + gEfiSecureBootEnableDisableGuid + +[Protocols] + gEfiSmbiosProtocolGuid ## CONSUMES + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrintLib + UefiApplicationEntryPoint + UefiBootServicesTableLib + UefiLib + UefiRuntimeServicesTableLib + SecureBootVariableLib diff --git a/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.= c b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c new file mode 100644 index 0000000000..3407c1c4b9 --- /dev/null +++ b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c @@ -0,0 +1,109 @@ +/** @file + Enroll default PK, KEK, db, dbx. + +Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // gEfiCustomModeEnableGu= id +#include // EFI_SETUP_MODE_NAME +#include // EFI_IMAGE_SECURITY_DAT= ABASE +#include // GUID_STRING_LENGTH +#include // CopyGuid() +#include // ASSERT() +#include // FreePool() +#include // AsciiSPrint() +#include // gBS +#include // AsciiPrint() +#include // gRT +#include +#include + +/** + Entry point function of this shell application. +**/ +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINT8 SetupMode; + + Status =3D GetSetupMode (&SetupMode); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot get SetupMode variable: = %r\n", Status); + return 1; + } + + if (SetupMode =3D=3D USER_MODE) { + AsciiPrint ("EnrollFromDefaultKeysApp: Skipped - USER_MODE\n"); + return 1; + } + + Status =3D SetSecureBootMode (CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot set CUSTOM_SECURE_BOOT_M= ODE: %r\n", Status); + return 1; + } + + Status =3D EnrollDbFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll db: %r\n", Status= ); + goto error; + } + + Status =3D EnrollDbxFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbt: %r\n", Statu= s); + } + + Status =3D EnrollDbtFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbx: %r\n", Statu= s); + } + + Status =3D EnrollKEKFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll KEK: %r\n", Statu= s); + goto cleardbs; + } + + Status =3D EnrollPKFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll PK: %r\n", Status= ); + goto clearKEK; + } + + Status =3D SetSecureBootMode (STANDARD_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ( + "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_= BOOT_MODE\n" + "Please do it manually, otherwise system can be easily compromised\n" + ); + } + return 0; + +clearKEK: + DeleteKEK (); + +cleardbs: + DeleteDbt (); + DeleteDbx (); + DeleteDb (); + +error: + Status =3D SetSecureBootMode (STANDARD_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ( + "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_= BOOT_MODE\n" + "Please do it manually, otherwise system can be easily compromised\n" + ); + } + + return 1; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77328): https://edk2.groups.io/g/devel/message/77328 Mute This Topic: https://groups.io/mt/83891034/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77329+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77329+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056487; cv=none; d=zohomail.com; s=zohoarc; b=A7CXUSrT64Tn3W8EtNRr8sE13CWBRO/ggtvyBHQWdMq+Nd3hf9jirv8Om7v9FmprlSmjKYelcAwDoMZLlMaHXwjwaIqhULrGtddT6UClbHt9t89gehLNp7/mmrUk/xenOz6m6aHT3e2TTvW55XPKOkVLroW1b3YBeMSTUqtH2FI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056487; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=isJfcqyirSHdqT6P67FIWYoIDeUiA8/4UZv1anyCP+s=; b=dZ9HKCG3vAZpfGIHHrLOPb+YFAp/39GAOTDSQTa/KAXeuQ3gy2LOeGepBz8a2TALMU1appsoth5Hz/d/hjIDwsbK4Eur8Ep1mBWoarFCQn26rbRYywVNXDNKiVuFnwla6yTmEv8xO79VWYZcgQHF9zlA09K0DtSYJrcFK/qV8SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77329+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056487565963.3885737458005; Wed, 30 Jun 2021 05:34:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VGjTYY1788612xNjXyN23XSE; Wed, 30 Jun 2021 05:34:47 -0700 X-Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mx.groups.io with SMTP id smtpd.web10.5330.1625056481368351825 for ; Wed, 30 Jun 2021 05:34:41 -0700 X-Received: by mail-lf1-f45.google.com with SMTP id h15so4745696lfv.12 for ; Wed, 30 Jun 2021 05:34:41 -0700 (PDT) X-Gm-Message-State: 3cb0vKzMcsQxp2kqjcqUiYUGx1787277AA= X-Google-Smtp-Source: ABdhPJzMsEyc/+DzZiBTJDCu7FNvQh51R7ELB30O2HVYTeGYnzy4p6KRPfAVPEsln4jiU8dSPDQ7Iw== X-Received: by 2002:a05:6512:239a:: with SMTP id c26mr26499425lfv.33.1625056478986; Wed, 30 Jun 2021 05:34:38 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:38 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki , Sunny Wang Subject: [edk2-devel] [PATCH v4 7/8] SecurityPkg: Add new modules to Security package. Date: Wed, 30 Jun 2021 14:34:07 +0200 Message-Id: <20210630123412.996158-8-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056487; bh=F7NUe3do/0qX5AqoPKxN2BYY3mqIkoSZtYLct07CEOs=; h=Cc:Date:From:Reply-To:Subject:To; b=wpGpzbBlwG9xxjOprGXT8pBpaksrj5hqevTdZgciPhCT0DPwUlKI/QYn8h/Nv00Jw/9 Dr9qJ7HFjExxY624gpHIgHJ+Dj7/63fAxrXLLJsWVRCWnZKP30RM6ssbVtZXSksGsM9uq w3d3qfXf+/cwF8xjM1N5pGz0vxxtSCGqmT0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commits adds modules related to initialization and usage of default Secure Boot key variables to SecurityPkg. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang Reviewed-by: Pete Batard Tested-by: Pete Batard on Raspberry Pi 4 --- SecurityPkg/SecurityPkg.dec | 14 ++++++++++++++ SecurityPkg/SecurityPkg.dsc | 3 +++ 2 files changed, 17 insertions(+) diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index 4001650fa2..e6aab4dce7 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -190,6 +190,20 @@ ## GUID used to enforce loading order between Tcg2Acpi and Tcg2Smm gTcg2MmSwSmiRegisteredGuid =3D { 0x9d4548b9, 0xa48d, 0x4db4, { 0= x9a, 0x68, 0x32, 0xc5, 0x13, 0x9e, 0x20, 0x18 } } =20 + ## GUID used to specify section with default PK content + gDefaultPKFileGuid =3D { 0x85254ea7, 0x4759, 0x4fc4, { 0= x82, 0xd4, 0x5e, 0xed, 0x5f, 0xb0, 0xa4, 0xa0 } } + + ## GUID used to specify section with default KEK content + gDefaultKEKFileGuid =3D { 0x6f64916e, 0x9f7a, 0x4c35, { 0= xb9, 0x52, 0xcd, 0x04, 0x1e, 0xfb, 0x05, 0xa3 } } + + ## GUID used to specify section with default db content + gDefaultdbFileGuid =3D { 0xc491d352, 0x7623, 0x4843, { 0= xac, 0xcc, 0x27, 0x91, 0xa7, 0x57, 0x44, 0x21 } } + + ## GUID used to specify section with default dbx content + gDefaultdbxFileGuid =3D { 0x5740766a, 0x718e, 0x4dc0, { 0= x99, 0x35, 0xc3, 0x6f, 0x7d, 0x3f, 0x88, 0x4f } } + + ## GUID used to specify section with default dbt content + gDefaultdbtFileGuid =3D { 0x36c513ee, 0xa338, 0x4976, { 0= xa0, 0xfb, 0x6d, 0xdb, 0xa3, 0xda, 0xfe, 0x87 } } =20 [Ppis] ## The PPI GUID for that TPM physical presence should be locked. diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 854f250625..f2f90f49de 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -259,6 +259,9 @@ =20 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64] SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf + SecurityPkg/EnrollFromDefaultKeys/EnrollFromDefaultKeys.inf + SecurityPkg/VariableAuthenticated/SecureBootDefaultKeys/SecureBootDefaul= tKeys.inf =20 [Components.IA32, Components.X64, Components.AARCH64] # --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77329): https://edk2.groups.io/g/devel/message/77329 Mute This Topic: https://groups.io/mt/83891036/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77330+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77330+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056488; cv=none; d=zohomail.com; s=zohoarc; b=d8BHqAEGQgQtiBmjnmCwlec5IvxQQ1/H3dQZ3Yo2F7WuzgDqfndEmB49YHIlrvmFVuxbKfVC9pt17r72lVif3zahMz+mCmFVSHHgNwEOp1QQJ4YlQNWiadJeG8H6p0SkqwOu2C6Hs746/kYUdo2CPK28fk/CSvfo7Czw4p8vdQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056488; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=t/X44a89uDmYuBRyw/RdoqXg9wfzdgf/cQUM4YZnJcg=; b=iNHR7VshPRsi1ddy9a3zNCzypQou8o0hU1gBpp70kI4+see6ntkyaY5I6GSJmHUsAvRgyipir+PhzZA/8ratn3SAt4pL/TcA7XYg7f/LWVpnpzZQjyseXMmKV0zyiknZ1UyKZe7Dxclbe+SsMGwpt5AR6Se9NEMM6dPZxqa1JoE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77330+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056488635531.8201220811213; Wed, 30 Jun 2021 05:34:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ioNXYY1788612x6kGIt693s9; Wed, 30 Jun 2021 05:34:48 -0700 X-Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mx.groups.io with SMTP id smtpd.web11.5298.1625056482351601495 for ; Wed, 30 Jun 2021 05:34:42 -0700 X-Received: by mail-lf1-f48.google.com with SMTP id n14so4774821lfu.8 for ; Wed, 30 Jun 2021 05:34:42 -0700 (PDT) X-Gm-Message-State: olqaI8L6uQstxVwnlxdzvLzMx1787277AA= X-Google-Smtp-Source: ABdhPJzmRpDb7QD0aKJNzVT4OL5gwaOPr+hrXR3YnUzvvsfNja51YEE3ka4rMCk1lHAs5qGE239huA== X-Received: by 2002:a19:ca0e:: with SMTP id a14mr3443066lfg.384.1625056480427; Wed, 30 Jun 2021 05:34:40 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:40 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki , Sunny Wang Subject: [edk2-devel] [PATCH v4 8/8] SecurityPkg: Add option to reset secure boot keys. Date: Wed, 30 Jun 2021 14:34:08 +0200 Message-Id: <20210630123412.996158-9-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056488; bh=rVQJc480Lto8xnWw3iB3wIW8lYJbtZ9u7iaAAx8x9Ew=; h=Cc:Date:From:Reply-To:Subject:To; b=spnRfTEFfAHUOWB4TJzXGb/mE9IGI/Di3bKfevQxMd/t/nFGHp3FnefG3nlwaWtDGUh PV0sgn4heFCSP3hOZvTAA8Hrx1zmfigYMw8MhBguTlwu7T2rNgupaCBQ57IrXtHavVHaE N36MsHRHJyybtD33L3pEMzp3d1J7+ZEqlyc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commit add option which allows reset content of Secure Boot keys and databases to default variables. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang Reviewed-by: Pete Batard Tested-by: Pete Batard on Raspberry Pi 4 --- SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.= inf | 1 + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvDa= ta.h | 2 + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr= | 6 + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl= .c | 154 ++++++++++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStri= ngs.uni | 4 + 5 files changed, 167 insertions(+) diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Sec= ureBootConfigDxe.inf index 30d9cd8025..bd8d256dde 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf @@ -109,6 +109,7 @@ [Protocols] gEfiHiiConfigAccessProtocolGuid ## PRODUCES gEfiDevicePathProtocolGuid ## PRODUCES + gEfiHiiPopupProtocolGuid =20 [Depex] gEfiHiiConfigRoutingProtocolGuid AND diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigNvData.h b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Se= cureBootConfigNvData.h index 6e54a4b0f2..4ecc25efc3 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gNvData.h +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gNvData.h @@ -54,6 +54,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #define KEY_VALUE_FROM_DBX_TO_LIST_FORM 0x100f =20 +#define KEY_SECURE_BOOT_RESET_TO_DEFAULT 0x1010 + #define KEY_SECURE_BOOT_OPTION 0x1100 #define KEY_SECURE_BOOT_PK_OPTION 0x1101 #define KEY_SECURE_BOOT_KEK_OPTION 0x1102 diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfig.vfr b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secure= BootConfig.vfr index fa7e11848c..e4560c592c 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= g.vfr +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= g.vfr @@ -69,6 +69,12 @@ formset endif; endif; =20 + text + help =3D STRING_TOKEN(STR_SECURE_RESET_TO_DEFAULTS_HELP), + text =3D STRING_TOKEN(STR_SECURE_RESET_TO_DEFAULTS), + flags =3D INTERACTIVE, + key =3D KEY_SECURE_BOOT_RESET_TO_DEFAULT; + endform; =20 // diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secu= reBootConfigImpl.c index 67e5e594ed..47f281873b 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include "SecureBootConfigImpl.h" +#include #include #include =20 @@ -4154,6 +4155,132 @@ ON_EXIT: return Status; } =20 +/** + This function reinitializes Secure Boot variables with default values. + + @retval EFI_SUCCESS Success to update the signature list page + @retval others Fail to delete or enroll signature data. +**/ + +STATIC EFI_STATUS +EFIAPI +KeyEnrollReset ( + VOID + ) +{ + EFI_STATUS Status; + UINT8 SetupMode; + + Status =3D EFI_SUCCESS; + + Status =3D SetSecureBootMode (CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR(Status)) { + return Status; + } + + // Clear all the keys and databases + Status =3D DeleteDb (); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + DEBUG ((DEBUG_ERROR, "Fail to clear DB: %r\n", Status)); + return Status; + } + + Status =3D DeleteDbx (); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + DEBUG ((DEBUG_ERROR, "Fail to clear DBX: %r\n", Status)); + return Status; + } + + Status =3D DeleteDbt (); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + DEBUG ((DEBUG_ERROR, "Fail to clear DBT: %r\n", Status)); + return Status; + } + + Status =3D DeleteKEK (); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + DEBUG ((DEBUG_ERROR, "Fail to clear KEK: %r\n", Status)); + return Status; + } + + Status =3D DeletePlatformKey (); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + DEBUG ((DEBUG_ERROR, "Fail to clear PK: %r\n", Status)); + return Status; + } + + // After PK clear, Setup Mode shall be enabled + Status =3D GetSetupMode (&SetupMode); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot get SetupMode variable: %r\n", + Status)); + return Status; + } + + if (SetupMode =3D=3D USER_MODE) { + DEBUG((DEBUG_INFO, "Skipped - USER_MODE\n")); + return EFI_SUCCESS; + } + + Status =3D SetSecureBootMode (CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot set CUSTOM_SECURE_BOOT_MODE: %r\n", + Status)); + return EFI_SUCCESS; + } + + // Enroll all the keys from default variables + Status =3D EnrollDbFromDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot enroll db: %r\n", Status)); + goto error; + } + + Status =3D EnrollDbxFromDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot enroll dbx: %r\n", Status)); + } + + Status =3D EnrollDbtFromDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot enroll dbt: %r\n", Status)); + } + + Status =3D EnrollKEKFromDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot enroll KEK: %r\n", Status)); + goto cleardbs; + } + + Status =3D EnrollPKFromDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot enroll PK: %r\n", Status)); + goto clearKEK; + } + + Status =3D SetSecureBootMode (STANDARD_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Cannot set CustomMode to STANDARD_SECURE_BOOT_MO= DE\n" + "Please do it manually, otherwise system can be easily compromised\n= ")); + } + + return Status; + +clearKEK: + DeleteKEK (); + +cleardbs: + DeleteDbt (); + DeleteDbx (); + DeleteDb (); + +error: + if (SetSecureBootMode (STANDARD_SECURE_BOOT_MODE) !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Cannot set mode to Secure: %r\n", Status)); + } + return Status; +} + /** This function is called to provide results data to the driver. =20 @@ -4205,6 +4332,8 @@ SecureBootCallback ( SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData; BOOLEAN GetBrowserDataResult; ENROLL_KEY_ERROR EnrollKeyErrorCode; + EFI_HII_POPUP_PROTOCOL *HiiPopup; + EFI_HII_POPUP_SELECTION UserSelection; =20 Status =3D EFI_SUCCESS; SecureBootEnable =3D NULL; @@ -4755,6 +4884,31 @@ SecureBootCallback ( FreePool (SetupMode); } break; + case KEY_SECURE_BOOT_RESET_TO_DEFAULT: + { + Status =3D gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VO= ID **) &HiiPopup); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D HiiPopup->CreatePopup ( + HiiPopup, + EfiHiiPopupStyleInfo, + EfiHiiPopupTypeYesNo, + Private->HiiHandle, + STRING_TOKEN (STR_RESET_TO_DEFAULTS_POPUP), + &UserSelection + ); + if (UserSelection =3D=3D EfiHiiPopupSelectionYes) { + Status =3D KeyEnrollReset (); + } + // + // Update secure boot strings after key reset + // + if (Status =3D=3D EFI_SUCCESS) { + Status =3D UpdateSecureBootString (Private); + SecureBootExtractConfigFromVariable (Private, IfrNvData); + } + } default: break; } diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigStrings.uni b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe= /SecureBootConfigStrings.uni index ac783453cc..0d01701de7 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gStrings.uni +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gStrings.uni @@ -21,6 +21,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #string STR_SECURE_BOOT_PROMPT #language en-US "Attempt Secure= Boot" #string STR_SECURE_BOOT_HELP #language en-US "Enable/Disable= the Secure Boot feature after platform reset" =20 +#string STR_SECURE_RESET_TO_DEFAULTS_HELP #language en-US "Enroll keys wi= th data from default variables" +#string STR_SECURE_RESET_TO_DEFAULTS #language en-US "Reset Secure B= oot Keys" +#string STR_RESET_TO_DEFAULTS_POPUP #language en-US "Secure Boot Ke= ys & databases will be initialized from defaults.\n Are you sure?" + #string STR_SECURE_BOOT_ENROLL_SIGNATURE #language en-US "Enroll Signatu= re" #string STR_SECURE_BOOT_DELETE_SIGNATURE #language en-US "Delete Signatu= re" #string STR_SECURE_BOOT_DELETE_LIST_FORM #language en-US "Delete Signatu= re List Form" --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77330): https://edk2.groups.io/g/devel/message/77330 Mute This Topic: https://groups.io/mt/83891038/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77331+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77331+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056490; cv=none; d=zohomail.com; s=zohoarc; b=VDqDOP9C1V9lTv7viVviKtZdKbY8AO7KDI9dEjeCLHQlR4ogsOEXiRvQSpEFnXicI0sY9K/DaKfBPTejeAZjyPBTQi732zK2siwlum6Oc3XH8nV/bD+EQMcKsZ/F5ZUmoQURbETWn5nAACP2WmLChcMvyrwF++eiZZISJHemnGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056490; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Ci6slfpm6mpaPPnkiwBu49RVnZ+wmaRnahzdlGRU+HU=; b=KImmrcZy8ZMLazbCX5+Szc9s4VIlCSvMnQqBZdiL6nZQkmsenh1sYuAfnU7ioYaKJP4EiCGk5hEqmYd1EGhDbsIKyThepII5uz/cUXAs9VLU+wtT7t0/AM2AydbzQ/FlJSPpTnXMZrD/8df95kr8NJw5FQ/bbA9W35IstX1JtiA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77331+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056490188132.48194505970196; Wed, 30 Jun 2021 05:34:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jjUgYY1788612xtlIm9XSR6q; Wed, 30 Jun 2021 05:34:49 -0700 X-Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by mx.groups.io with SMTP id smtpd.web08.5141.1625056483789192226 for ; Wed, 30 Jun 2021 05:34:44 -0700 X-Received: by mail-lf1-f47.google.com with SMTP id n14so4774975lfu.8 for ; Wed, 30 Jun 2021 05:34:43 -0700 (PDT) X-Gm-Message-State: G1pKPTpfuXDRLTWQUHZjmi7dx1787277AA= X-Google-Smtp-Source: ABdhPJwIW6fSFxSZUxvSL3S1EqR4RZJM1cRAyzL2S8537b0netZbmXKomTt/9Y6rYEEMzaW7Nvx1bA== X-Received: by 2002:ac2:4ec4:: with SMTP id p4mr7052886lfr.163.1625056481920; Wed, 30 Jun 2021 05:34:41 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:41 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [edk2-platforms PATCH v4 09/12] Intel Platforms: add SecureBootVariableLib class resolution Date: Wed, 30 Jun 2021 14:34:09 +0200 Message-Id: <20210630123412.996158-10-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056489; bh=qmrGoP0LjceBOhiDixh07HgLLifdFZZaUDvkWxqp2B0=; h=Cc:Date:From:Reply-To:Subject:To; b=YwIOJs5ti0nJSS7ohYr+ciHZL/mEMeu+mgCcoHYD4HZy02eIMI+l0YQ/8QBZlRWsmMn Lgq8/KXyxMP/TOLPPNr4rWyJ9ylDqAD8Da4QeN+MvaxSrLbxWkGWwc+afEj664YFe8IAF BmWJ+gcRbcq1txqjJ1CnnDxKBIkkC1V0eNg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The edk2 patch SecurityPkg: Create library for setting Secure Boot variables. removes generic functions from SecureBootConfigDxe and places them into SecureBootVariableLib. This patch adds SecureBootVariableLib mapping for each Intel platform which uses SecureBootConfigDxe. Signed-off-by: Grzegorz Bernacki --- Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 1 + Platform/Intel/QuarkPlatformPkg/Quark.dsc | 1 + Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 1 + Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc b/= Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc index b154f9615d..5157c87a9a 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc @@ -139,6 +139,7 @@ =20 !if gMinPlatformPkgTokenSpaceGuid.PcdUefiSecureBootEnable =3D=3D TRUE AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !endif =20 SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf diff --git a/Platform/Intel/QuarkPlatformPkg/Quark.dsc b/Platform/Intel/Qua= rkPlatformPkg/Quark.dsc index cc1eba4df4..35f99429f7 100644 --- a/Platform/Intel/QuarkPlatformPkg/Quark.dsc +++ b/Platform/Intel/QuarkPlatformPkg/Quark.dsc @@ -175,6 +175,7 @@ !if $(SECURE_BOOT_ENABLE) PlatformSecureLib|QuarkPlatformPkg/Library/PlatformSecureLib/PlatformSec= ureLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc b/Platfor= m/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc index d15da40819..5a0d3e31e1 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc @@ -227,6 +227,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc b/Platform= /Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc index 4a5548b80e..36a5ae333c 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc @@ -1,4 +1,4 @@ -#/** @file +e # Platform description. # # Copyright (c) 2012 - 2021, Intel Corporation. All rights reserved.
@@ -229,6 +229,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf !endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77331): https://edk2.groups.io/g/devel/message/77331 Mute This Topic: https://groups.io/mt/83891039/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77332+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77332+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056491; cv=none; d=zohomail.com; s=zohoarc; b=G/whlEZXq8r9E4yiDCv8bfqyuvdDLXntcMVIQIXKs6XI7LK0Orbw3Hh3Z/6MG/KDSQGwGx7X84jJVXoIc6rCP3AEMcBAplWBxcLIcgfNtWuU/MkGpaPFa3PSjDheIkYjUV+oLDZkt23QTSsBpfB4cfkYAME/AniFIA8qXL7HTK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056491; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KXscwJczgggWuZ+EiNlT82DW+NZVxBblMMNAEMnBEIc=; b=DFOWBbHot1JtxulXtTT8t/YWG5ebsQUz3DwAZnJzBS/vmjjByf+Cszhea+oodQXD8AZCJULJtnbnyq1kFO2twQ6OusojDESUrYZTEDjrNN21yxxvD6gt56G9UO1aj3NlL9yRNiixt+nDvAN95vE4NXA4S9OJnoDV8611FgJW5w4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77332+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056491580510.5600112813281; Wed, 30 Jun 2021 05:34:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GenJYY1788612xHrKHW58AdJ; Wed, 30 Jun 2021 05:34:51 -0700 X-Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mx.groups.io with SMTP id smtpd.web11.5300.1625056485277521277 for ; Wed, 30 Jun 2021 05:34:45 -0700 X-Received: by mail-lf1-f54.google.com with SMTP id a15so4791403lfr.6 for ; Wed, 30 Jun 2021 05:34:45 -0700 (PDT) X-Gm-Message-State: mmbn3M7vj0Fps7O0H7JTxVXHx1787277AA= X-Google-Smtp-Source: ABdhPJwRovwIfeakg1Ka+b3XYokPNO1ETI070dvukSRljN578VtVhMLM5GDQg7Gd0vSNM0j0r345GQ== X-Received: by 2002:a05:6512:10cb:: with SMTP id k11mr26920528lfg.182.1625056483342; Wed, 30 Jun 2021 05:34:43 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:42 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [edk2-platforms PATCH v4 10/12] ARM Silicon and Platforms: add SecureBootVariableLib class resolution Date: Wed, 30 Jun 2021 14:34:10 +0200 Message-Id: <20210630123412.996158-11-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056491; bh=e4+FB/+Y5A95z1QrkV+n0Yi7iLq47CpjA61vtNU9Z5k=; h=Cc:Date:From:Reply-To:Subject:To; b=lZQSQRa+Pfqd3nUa3sPkm0pqaf6zo+4Lr3w1AuimE02OLp92k1gmcNkKOtUFTV3GvJ0 XHNU8xODDM1yZxm9ILM1VLozuOBScS/BSsxx61ZPgLfPydXgbcgTf4vOOPAvs7n/uh6yM h2kIDTlv9Ro4cmEyJirDg/vkzEd4ZqzbdVc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The edk2 patch SecurityPkg: Create library for setting Secure Boot variables. removes generic functions from SecureBootConfigDxe and places them into SecureBootVariableLib. This patch adds SecureBootVariableLib mapping for each ARM platform which uses SecureBootConfigDxe. Signed-off-by: Grzegorz Bernacki Reviewed-by: Graeme Gregory --- Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc | 1 + Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 1 + Platform/RaspberryPi/RPi3/RPi3.dsc | 1 + Platform/RaspberryPi/RPi4/RPi4.dsc | 1 + Platform/Socionext/DeveloperBox/DeveloperBox.dsc | 4 ++++ 5 files changed, 8 insertions(+) diff --git a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc b/Platform/ARM/VE= xpressPkg/ArmVExpress.dsc.inc index fee7cfcc2d..60fdb244ba 100644 --- a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc +++ b/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc @@ -129,6 +129,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf =20 # re-use the UserPhysicalPresent() dummy implementation from the ovmf tr= ee PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/S= bsaQemu.dsc index 11ce361cdb..b1c4030ec9 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc @@ -156,6 +156,7 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE =3D FALSE # TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf =20 # re-use the UserPhysicalPresent() dummy implementation from the ovmf tr= ee PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 53825bcf62..73f7f2f8c3 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -167,6 +167,7 @@ =20 # re-use the UserPhysicalPresent() dummy implementation from the ovmf tr= ee PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index fd73c4d14b..d38fee8fb8 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -164,6 +164,7 @@ !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf =20 # re-use the UserPhysicalPresent() dummy implementation from the ovmf tr= ee PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/So= cionext/DeveloperBox/DeveloperBox.dsc index 88454c1f90..41b7c3bced 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -52,6 +52,10 @@ =20 MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf =20 +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf +!endif + [LibraryClasses.common.SEC] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77332): https://edk2.groups.io/g/devel/message/77332 Mute This Topic: https://groups.io/mt/83891040/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77333+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77333+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056493; cv=none; d=zohomail.com; s=zohoarc; b=a4LWsFbOlC0om5ipJVBE9MMCP/yCuBvEKIhFr9/Yu1j8s+HRVBe+LbDDRWNrFmdLnQPwVafHOXXKl4H/TCaBrg4aS9jspDIXwEi2eSsYF5n9T7yMjOLsKKpqwypsJFoQmTfFhZSEvnZeyDX44SCZ24yNBJfaM8H75zamGOmpI5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056493; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=krFGJF8+RNAvJ2Y7b1aDltt9KhveBl14hXMVqQ8Rlzs=; b=SWcAi34eu9SVJk5fyq3Bby0k3jtUP6s0PmQ+N62Wc26dgGd4x30daU0MKfIFIOL8JJwAAhFZZUTMejUx72oEPG/tMayNXr/URpS6y3mOaYqduiMMjaP6R4dg/MFU9vO4rk0RZfW3FBuKRLgMBFsbIqY0C6rnRccdfBPoU25gnOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77333+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056493076533.5491687899115; Wed, 30 Jun 2021 05:34:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uXxEYY1788612xTKnlA7sLZA; Wed, 30 Jun 2021 05:34:52 -0700 X-Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mx.groups.io with SMTP id smtpd.web12.5201.1625056486848479622 for ; Wed, 30 Jun 2021 05:34:47 -0700 X-Received: by mail-lf1-f45.google.com with SMTP id a15so4791522lfr.6 for ; Wed, 30 Jun 2021 05:34:46 -0700 (PDT) X-Gm-Message-State: DmNVumcjmQf784qqWTmWIP1ux1787277AA= X-Google-Smtp-Source: ABdhPJxlNw+Z8x4GD+MUb8rCv7b0TzAoSWT67bzSlv8YYvcFcIz7QoFxR3IfkoalY5Fg6fYixzjWVg== X-Received: by 2002:a19:c506:: with SMTP id w6mr27339408lfe.656.1625056484988; Wed, 30 Jun 2021 05:34:44 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:44 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [edk2-devel] [edk2-platforms PATCH v4 11/12] RISC-V Platforms: add SecureBootVariableLib class resolution Date: Wed, 30 Jun 2021 14:34:11 +0200 Message-Id: <20210630123412.996158-12-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056492; bh=WQTJmxLhaHHryIQ5ZmoqJmvodfVy15R6uYiWMLuxL1M=; h=Cc:Date:From:Reply-To:Subject:To; b=vLizfZzf1J8XYu0guCpf0rkH3DlMJ0Y1UN9KqNi5ADFLe5JItim35K7gxjmI4a1ziAq WO+q2eTzy/H0TOH/LUKHF9QVmlwRZHCfMyWD2urEsgXtE1SQgmO+k/c08hI+ZgNvuDdd1 lxhGwCio4sitW+T+anUga5nlrphmP70aUCg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The edk2 patch SecurityPkg: Create library for setting Secure Boot variables. removes generic functions from SecureBootConfigDxe and places them into SecureBootVariableLib. This patch adds SecureBootVariableLib mapping for each RICS-V platform which uses SecureBootConfigDxe. Signed-off-by: Grzegorz Bernacki Reviewed-by: Abner Chang Reviewed-by: Daniel Schaefer --- Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc | 1 + Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc b/P= latform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc index b91823ceeb..fc5ba2a07f 100644 --- a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc +++ b/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc @@ -122,6 +122,7 @@ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U5= 40.dsc b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.d= sc index 0eafe29880..71add8ff9a 100644 --- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc +++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc @@ -122,6 +122,7 @@ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf + SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBo= otVariableLib.inf !else TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77333): https://edk2.groups.io/g/devel/message/77333 Mute This Topic: https://groups.io/mt/83891041/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 03:12:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77334+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77334+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1625056489; cv=none; d=zohomail.com; s=zohoarc; b=Ae7dTkOj0GwQkM8jLryLtIflo0RgdH7LeFHMu43jPb3dE9WVrjOVYrwsxMByZc0QDiS3B6IPutbV90oMGqeRO9Vl4otXKbgzQvIeVNEx+CbGHyYqB/laoM45xJ4NW6RJjnRJrWMe+eY4rBNv7njVbpOCE7/DSc8miFAzKIlotew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625056489; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Sgusf5ikOldoonW1KUZi80irZg6n3yUUIrIBLPNj0Lw=; b=W/9dRyz8Ux0VP9nrDrYy3bCa5uRrynmF2mieLIM8LLUdEgCs7SJFaZJsaLn3eTN5bSWUwRGk0nN/uVD8IKlZaXOkRB2i7uecCnaXWc2GgwMW6O33H6+zBC5ST435Ui+T7KAeXOEIRDhJWQ7aFIzNjtd+Gp3/S7m+RsKSwnfnsRo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77334+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1625056489617776.4793388194861; Wed, 30 Jun 2021 05:34:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yNVuYY1788612xfAw12vUlwO; Wed, 30 Jun 2021 05:34:49 -0700 X-Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mx.groups.io with SMTP id smtpd.web08.5143.1625056488353720782 for ; Wed, 30 Jun 2021 05:34:48 -0700 X-Received: by mail-lf1-f48.google.com with SMTP id a15so4791659lfr.6 for ; Wed, 30 Jun 2021 05:34:48 -0700 (PDT) X-Gm-Message-State: 82ggPNVfYJzLyWqCyBnmc39Qx1787277AA= X-Google-Smtp-Source: ABdhPJyaaJfzj7KpRVeW6U+EuIqdnxCO5JiLvwwqElPXp3Xx98DJ6z5NqytViik8p4ebq0eQ7WpA4Q== X-Received: by 2002:a05:6512:138a:: with SMTP id p10mr27232045lfa.505.1625056486475; Wed, 30 Jun 2021 05:34:46 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id d29sm1285624lfv.20.2021.06.30.05.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:34:46 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki , Sunny Wang Subject: [edk2-devel] [edk2-platforms PATCH v4 12/12] Platform/RaspberryPi: Enable default Secure Boot variables initialization Date: Wed, 30 Jun 2021 14:34:12 +0200 Message-Id: <20210630123412.996158-13-gjb@semihalf.com> In-Reply-To: <20210630123412.996158-1-gjb@semihalf.com> References: <20210630123412.996158-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1625056489; bh=QR+U9zfwe6TghHM+oVmtjFdsHqa3uXWESJL4PJO3YHk=; h=Cc:Date:From:Reply-To:Subject:To; b=Y2/mUBZRTs+HaVHDeAaQ8kQBKRtIVx4Ue8ujv7Qyu9TIkB3ffnPvUoysTybs3S5iK0W nLVlFMycWHvehGPAB3uPpBecWmiSxy19EEAf7R2lfVBODvNAmVC92Kh89La11enzp4iQG euxESkb3E6FjgbFwxrT3sUXyJ/qgl/6/xb0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commit allows to initialize Secure Boot default key and databases from data embedded in firmware binary. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang Reviewed-by: Pete Batard Tested-by: Pete Batard on Raspberry Pi 4 --- Platform/RaspberryPi/RPi4/RPi4.dsc | 3 +++ Platform/RaspberryPi/RPi4/RPi4.fdf | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index d38fee8fb8..54bb282ff2 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -218,6 +218,7 @@ MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf =20 [LibraryClasses.common.UEFI_DRIVER] @@ -621,6 +622,8 @@ NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificatio= nLib.inf } SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDx= e.inf + SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf + SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDef= aultKeysDxe.inf !else MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf !endif diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4= /RPi4.fdf index 1e13909a57..8508065a77 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf @@ -189,7 +189,9 @@ READ_LOCK_STATUS =3D TRUE INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.i= nf INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE +!include ArmPlatformPkg/SecureBootDefaultKeys.fdf.inc INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConf= igDxe.inf + INF SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoo= tDefaultKeysDxe.inf !endif INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRu= ntimeDxe.inf INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77334): https://edk2.groups.io/g/devel/message/77334 Mute This Topic: https://groups.io/mt/83891042/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-