From nobody Thu May 2 22:21:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1522268822300895.2364150446298; Wed, 28 Mar 2018 13:27:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CE3C1224DD120; Wed, 28 Mar 2018 13:20:20 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CA38F22106DCA for ; Wed, 28 Mar 2018 13:20:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A1CF81A6D33; Wed, 28 Mar 2018 20:26:57 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-75.rdu2.redhat.com [10.10.120.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21AAA10B2B26; Wed, 28 Mar 2018 20:26:55 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Wed, 28 Mar 2018 22:26:48 +0200 Message-Id: <20180328202651.1478-2-lersek@redhat.com> In-Reply-To: <20180328202651.1478-1-lersek@redhat.com> References: <20180328202651.1478-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 28 Mar 2018 20:26:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 28 Mar 2018 20:26:57 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 1/4] MdeModulePkg/Variable/RuntimeDxe: introduce PcdMaxVolatileVariableSize X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The variable driver doesn't distinguish "non-volatile non-authenticated" variables from "volatile non-authenticated" variables, when checking individual variable sizes against the permitted maximum. PcdMaxVariableSize covers both kinds. This prevents volatile non-authenticated variables from carrying large data between UEFI drivers, despite having no flash impact. One example is EFI_TLS_CA_CERTIFICATE_VARIABLE, which platforms might want to create as volatile on every boot: the certificate list can be several hundred KB in size. Introduce PcdMaxVolatileVariableSize to represent the limit on individual volatile non-authenticated variables. The default value is zero, which makes Variable/RuntimeDxe fall back to PcdMaxVariableSize (i.e. the current behavior). This is similar to the PcdMaxAuthVariableSize fallback. Whenever the size limit is enforced, consult MaxVolatileVariableSize as the last option, after checking - MaxAuthVariableSize for VARIABLE_ATTRIBUTE_AT_AW, - and MaxVariableSize for EFI_VARIABLE_NON_VOLATILE. EFI_VARIABLE_HARDWARE_ERROR_RECORD is always handled separately; it always takes priority over the three cases listed above. Introduce the GetMaxVariableSize() helper to consider PcdMaxVolatileVariableSize, in addition to GetNonVolatileMaxVariableSize(). GetNonVolatileMaxVariableSize() is currently called at three sites, and two of those need to start using GetMaxVariableSize() instead: - VariableServiceInitialize() [VariableSmm.c]: the SMM comms buffer must accommodate all kinds of variables, - VariableCommonInitialize() [Variable.c]: the preallocated scratch space must also accommodate all kinds of variables, - InitNonVolatileVariableStore() [Variable.c] can continue using GetNonVolatileMaxVariableSize(). Don't modify the ReclaimForOS() function as it is specific to non-volatile variables and should ignore PcdMaxVolatileVariableSize. Cc: Eric Dong Cc: Ruiyu Ni Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Gary Lin Tested-by: Gary Lin --- MdeModulePkg/MdeModulePkg.dec | 8 ++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 1 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 1 + MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 12 +++= ++ MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 50 +++= ++++++++++++++--- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 2 +- 7 files changed, 74 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 5d561ff48495..cc397185f7b9 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1043,6 +1043,14 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] # @Prompt Maximum authenticated variable size. gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x00|UINT32|0x3000= 0009 =20 + ## The maximum size of a single non-authenticated volatile variable. + # The default value is 0 for compatibility: in that case, the maximum + # non-authenticated volatile variable size remains specified by + # PcdMaxVariableSize. Only the MdeModulePkg/Universal/Variable/RuntimeDxe + # driver supports this PCD. + # @Prompt Maximum non-authenticated volatile variable size. + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x00|UINT32|0x= 3000000a + ## The maximum size of single hardware error record variable.

# In IA32/X64 platforms, this value should be larger than 1KB.
# In IA64 platforms, this value should be larger than 128KB.
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index f3fa616438b0..080b8a62c045 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -94,6 +94,14 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxAuthVariableSize_HELP #l= anguage en-US "The maximum size of a single authenticated variable." = "The value is 0 as default for compatibility that maximum aut= henticated variable size is specified by PcdMaxVariableSize." =20 +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxVolatileVariableSize_PROM= PT #language en-US "The maximum size of a single non-authenticated volatil= e variable." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxVolatileVariableSize_HELP= #language en-US "The maximum size of a single non-authenticated volatile = variable.

\n" + = "The default value is 0 for compatibility: in that case, = the maximum " + = "non-authenticated volatile variable size remains specifi= ed by " + = "PcdMaxVariableSize.
\n" + = "Only the MdeModulePkg/Universal/Variable/RuntimeDxe driv= er supports this PCD.
" + #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize= _PROMPT #language en-US "Maximum HwErr variable size" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize= _HELP #language en-US "The maximum size of single hardware error record va= riable.

\n" diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.= inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf index e840fc9bff40..2d0a172ece35 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf @@ -123,6 +123,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize ## CON= SUMES diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index 69966f0d37ee..dbb0674a46ad 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -125,6 +125,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CO= NSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CO= NSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CO= NSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CO= NSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize ## CO= NSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize ## CO= NSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize ## CO= NSUMES diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.h index b35e8ab91273..938eb5de61fa 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -101,6 +101,7 @@ typedef struct { UINTN HwErrVariableTotalSize; UINTN MaxVariableSize; UINTN MaxAuthVariableSize; + UINTN MaxVolatileVariableSize; UINTN ScratchBufferSize; CHAR8 *PlatformLangCodes; CHAR8 *LangCodes; @@ -460,6 +461,17 @@ GetNonVolatileMaxVariableSize ( VOID ); =20 +/** + Get maximum variable size, covering both non-volatile and volatile varia= bles. + + @return Maximum variable size. + +**/ +UINTN +GetMaxVariableSize ( + VOID + ); + /** Initializes variable write service after FVB was ready. =20 diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index c11842b5c3ba..5a9051648004 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -2345,12 +2345,14 @@ UpdateVariable ( CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr= + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr)); =20 // - // Set Max Common/Auth Variable Data Size as default MaxDataSize. + // Set Max Auth/Non-Volatile/Volatile Variable Data Size as defaul= t MaxDataSize. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { MaxDataSize =3D mVariableModuleGlobal->MaxAuthVariableSize - Dat= aOffset; - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { MaxDataSize =3D mVariableModuleGlobal->MaxVariableSize - DataOff= set; + } else { + MaxDataSize =3D mVariableModuleGlobal->MaxVolatileVariableSize -= DataOffset; } =20 // @@ -3218,16 +3220,20 @@ VariableServiceSetVariable ( } else { // // The size of the VariableName, including the Unicode Null in bytes = plus - // the DataSize is limited to maximum size of Max(Auth)VariableSize b= ytes. + // the DataSize is limited to maximum size of Max(Auth|Volatile)Varia= bleSize bytes. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xAuthVariableSize - GetVariableHeaderSize ()) { return EFI_INVALID_PARAMETER; } - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVariableSize - GetVariableHeaderSize ()) { return EFI_INVALID_PARAMETER; } + } else { + if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVolatileVariableSize - GetVariableHeaderSize ()) { + return EFI_INVALID_PARAMETER; + } } } =20 @@ -3399,12 +3405,14 @@ VariableServiceQueryVariableInfoInternal ( } =20 // - // Let *MaximumVariableSize be Max(Auth)VariableSize with the exceptio= n of the variable header size. + // Let *MaximumVariableSize be Max(Auth|Volatile)VariableSize with the= exception of the variable header size. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { *MaximumVariableSize =3D mVariableModuleGlobal->MaxAuthVariableSize = - GetVariableHeaderSize (); - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { *MaximumVariableSize =3D mVariableModuleGlobal->MaxVariableSize - Ge= tVariableHeaderSize (); + } else { + *MaximumVariableSize =3D mVariableModuleGlobal->MaxVolatileVariableS= ize - GetVariableHeaderSize (); } } =20 @@ -3657,6 +3665,30 @@ GetNonVolatileMaxVariableSize ( } } =20 +/** + Get maximum variable size, covering both non-volatile and volatile varia= bles. + + @return Maximum variable size. + +**/ +UINTN +GetMaxVariableSize ( + VOID + ) +{ + UINTN MaxVariableSize; + + MaxVariableSize =3D GetNonVolatileMaxVariableSize(); + // + // The condition below fails implicitly if PcdMaxVolatileVariableSize eq= uals + // the default zero value. + // + if (MaxVariableSize < PcdGet32 (PcdMaxVolatileVariableSize)) { + MaxVariableSize =3D PcdGet32 (PcdMaxVolatileVariableSize); + } + return MaxVariableSize; +} + /** Init non-volatile variable store. =20 @@ -3810,6 +3842,10 @@ InitNonVolatileVariableStore ( =20 mVariableModuleGlobal->MaxVariableSize =3D PcdGet32 (PcdMaxVariableSize); mVariableModuleGlobal->MaxAuthVariableSize =3D ((PcdGet32 (PcdMaxAuthVar= iableSize) !=3D 0) ? PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlo= bal->MaxVariableSize); + mVariableModuleGlobal->MaxVolatileVariableSize =3D ((PcdGet32 (PcdMaxVol= atileVariableSize) !=3D 0) ? + PcdGet32 (PcdMaxVolati= leVariableSize) : + mVariableModuleGlobal-= >MaxVariableSize + ); =20 // // Parse non-volatile variable data and get last variable offset. @@ -4228,7 +4264,7 @@ VariableCommonInitialize ( // // Allocate memory for volatile variable store, note that there is a scr= atch space to store scratch data. // - ScratchSize =3D GetNonVolatileMaxVariableSize (); + ScratchSize =3D GetMaxVariableSize (); mVariableModuleGlobal->ScratchBufferSize =3D ScratchSize; VolatileVariableStore =3D AllocateRuntimePool (PcdGet32 (PcdVariableStor= eSize) + ScratchSize); if (VolatileVariableStore =3D=3D NULL) { diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 8d73b6edee51..e495d971a08b 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -955,7 +955,7 @@ VariableServiceInitialize ( ); ASSERT_EFI_ERROR (Status); =20 - mVariableBufferPayloadSize =3D GetNonVolatileMaxVariableSize () + + mVariableBufferPayloadSize =3D GetMaxVariableSize () + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHE= CK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize (); =20 Status =3D gSmst->SmmAllocatePool ( --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 22:21:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1522268824480117.50419211311487; Wed, 28 Mar 2018 13:27:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 44D3E224DD123; Wed, 28 Mar 2018 13:20:22 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2C3CD22106DCE for ; Wed, 28 Mar 2018 13:20:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CE0C406802A; Wed, 28 Mar 2018 20:26:58 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-75.rdu2.redhat.com [10.10.120.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CBAC10B2B26; Wed, 28 Mar 2018 20:26:57 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Wed, 28 Mar 2018 22:26:49 +0200 Message-Id: <20180328202651.1478-3-lersek@redhat.com> In-Reply-To: <20180328202651.1478-1-lersek@redhat.com> References: <20180328202651.1478-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 28 Mar 2018 20:26:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 28 Mar 2018 20:26:58 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 2/4] OvmfPkg/EmuVariableFvbRuntimeDxe: stop using PcdVariableStoreSize X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Jordan Justen , Gary Ching-Pang Lin , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In commit 62f43f7c1947c, we set PcdVariableStoreSize to the same value as PcdFlashNvStorageVariableSize (which in turn comes from VARS_LIVE_SIZE in "OvmfPkg.fdf.inc"). This equality between both PCDs is a false requirement from EmuVariableFvbRuntimeDxe. FVB drivers should use PcdFlashNvStorageVariableSize for supporting non-volatile variables (even if they happen to be kept in RAM only), along the other PcdFlashNvStorage* PCDs. Whereas PcdVariableStoreSize is for variables that are volatile at the gRT->SetVariable() / gRT->GetVariable() API level. (PlatformPei too bases the preallocation for EmuVariableFvbRuntimeDxe on PcdFlashNvStorageFtwSpareSize.) Replace PcdVariableStoreSize in EmuVariableFvbRuntimeDxe with the same-value PcdFlashNvStorageVariableSize. This means no change in behavior, and it allows us to increase PcdVariableStoreSize in a later patch without disturbing EmuVariableFvbRuntimeDxe (or PlatformPei). Cc: Anthony Perard Cc: Ard Biesheuvel Cc: Gary Ching-Pang Lin Cc: Jordan Justen Cc: Julien Grall Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Reviewed-by: Gary Lin Tested-by: Gary Lin --- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf | 3 +-- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf b/OvmfPkg/EmuVariable= FvbRuntimeDxe/Fvb.inf index 9f37938408a4..2aacf06c923d 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf @@ -58,12 +58,11 @@ [Protocols] gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_PRODUCED =20 [FixedPcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFv= bRuntimeDxe/Fvb.c index 2d106bb50bed..9480d879c935 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c @@ -665,7 +665,7 @@ InitializeFvAndVariableStoreHeaders ( =20 // UINT32 Size; ( - FixedPcdGet32 (PcdVariableStoreSize) - + FixedPcdGet32 (PcdFlashNvStorageVariableSize) - OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr) ), =20 @@ -733,7 +733,7 @@ FvbInitialize ( ASSERT (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) % EMU_FVB_BLOCK_SIZE =3D=3D 0); if ( - (PcdGet32 (PcdVariableStoreSize) + + (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) ) > EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE @@ -788,7 +788,7 @@ FvbInitialize ( // // Initialize the Fault Tolerant Write data area // - SubPtr =3D (VOID*) ((UINT8*) Ptr + PcdGet32 (PcdVariableStoreSize)); + SubPtr =3D (VOID*) ((UINT8*) Ptr + PcdGet32 (PcdFlashNvStorageVariableSi= ze)); PcdStatus =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, (UINT32)(UINTN) SubPtr); ASSERT_RETURN_ERROR (PcdStatus); --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 22:21:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 152226882672322.122108001408037; Wed, 28 Mar 2018 13:27:06 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AE3C8224DD12B; Wed, 28 Mar 2018 13:20:25 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A692B224DD123 for ; Wed, 28 Mar 2018 13:20:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED3534068053; Wed, 28 Mar 2018 20:26:59 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-75.rdu2.redhat.com [10.10.120.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id C03A910B2B26; Wed, 28 Mar 2018 20:26:58 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Wed, 28 Mar 2018 22:26:50 +0200 Message-Id: <20180328202651.1478-4-lersek@redhat.com> In-Reply-To: <20180328202651.1478-1-lersek@redhat.com> References: <20180328202651.1478-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 28 Mar 2018 20:27:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 28 Mar 2018 20:27:00 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 3/4] OvmfPkg: annotate "PcdVariableStoreSize := PcdFlashNvStorageVariableSize" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Jordan Justen , Gary Ching-Pang Lin , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As a continuation of the last patch, clarify in the DSC files that we set PcdVariableStoreSize to the same value as PcdFlashNvStorageVariableSize just for convenience; the equality is not a technical requirement. Cc: Anthony Perard Cc: Ard Biesheuvel Cc: Gary Ching-Pang Lin Cc: Jordan Justen Cc: Julien Grall Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Reviewed-by: Gary Lin Tested-by: Gary Lin --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 92c8c560a067..7664b50ddef9 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -439,11 +439,13 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 6ecaa795b288..e5969090d437 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -444,11 +444,13 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index c98a3657c6f6..7197c1984a7c 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -444,11 +444,13 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 + # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 22:21:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1522268829117762.8377380847226; Wed, 28 Mar 2018 13:27:09 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 33658224DD12F; Wed, 28 Mar 2018 13:20:26 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C0711224DD124 for ; Wed, 28 Mar 2018 13:20:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 208A640572A1; Wed, 28 Mar 2018 20:27:01 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-75.rdu2.redhat.com [10.10.120.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B8A210B2B26; Wed, 28 Mar 2018 20:27:00 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Wed, 28 Mar 2018 22:26:51 +0200 Message-Id: <20180328202651.1478-5-lersek@redhat.com> In-Reply-To: <20180328202651.1478-1-lersek@redhat.com> References: <20180328202651.1478-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 20:27:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 20:27:01 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 4/4] OvmfPkg/TlsAuthConfigLib: configure trusted CA certs for HTTPS boot X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Gary Ching-Pang Lin , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce TlsAuthConfigLib to read the list of trusted CA certificates from fw_cfg and to store it to EFI_TLS_CA_CERTIFICATE_VARIABLE. The fw_cfg file is formatted by the "p11-kit" and "update-ca-trust" utilities on the host side, so that the host settings take effect in guest HTTPS boot as well. QEMU forwards the file intact to the firmware. The contents are sanity-checked by NetworkPkg/HttpDxe code that was added in commit 0fd13678a681. Link TlsAuthConfigLib via NULL resolution into TlsAuthConfigDxe. This sets EFI_TLS_CA_CERTIFICATE_VARIABLE in time for both NetworkPkg/TlsAuthConfigDxe (for possible HII interaction with the user) and for NetworkPkg/HttpDxe (for the effective TLS configuration). The file formatted by "p11-kit" can be large. On a RHEL-7 host, the the Mozilla CA root certificate bundle -- installed with the "ca-certificates" package -- is processed into a 182KB file. Thus, create EFI_TLS_CA_CERTIFICATE_VARIABLE as a volatile & boot-time only variable. Also, in TLS_ENABLE builds, set the cumulative limit for volatile variables (PcdVariableStoreSize) to 512KB, and the individual limit for the same (PcdMaxVolatileVariableSize) to 256KB. Cc: Ard Biesheuvel Cc: Gary Ching-Pang Lin Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Reviewed-by: Gary Lin Tested-by: Gary Lin --- OvmfPkg/OvmfPkgIa32.dsc | 13 +- OvmfPkg/OvmfPkgIa32X64.dsc | 13 +- OvmfPkg/OvmfPkgX64.dsc | 13 +- OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf | 55 ++++++++ OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.c | 133 ++++++++++++++= ++++++ 5 files changed, 224 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 7664b50ddef9..c9eb248506c5 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -439,15 +439,23 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif +!endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif +!endif +!if $(TLS_ENABLE) =3D=3D TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x80000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x40000 +!endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 @@ -796,7 +804,10 @@ [Components] !endif !if $(TLS_ENABLE) =3D=3D TRUE NetworkPkg/TlsDxe/TlsDxe.inf - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } !endif OvmfPkg/VirtioNetDxe/VirtioNet.inf =20 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index e5969090d437..17aef2d4830f 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -444,15 +444,23 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif +!endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif +!endif +!if $(TLS_ENABLE) =3D=3D TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x80000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x40000 +!endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 @@ -805,7 +813,10 @@ [Components.X64] !endif !if $(TLS_ENABLE) =3D=3D TRUE NetworkPkg/TlsDxe/TlsDxe.inf - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } !endif OvmfPkg/VirtioNetDxe/VirtioNet.inf =20 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 7197c1984a7c..8af763ea9e9e 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -444,15 +444,23 @@ [PcdsFixedAtBuild] !if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif +!endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 +!if $(TLS_ENABLE) =3D=3D FALSE # match PcdFlashNvStorageVariableSize purely for convenience gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif +!endif +!if $(TLS_ENABLE) =3D=3D TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x80000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x40000 +!endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 @@ -803,7 +811,10 @@ [Components] !endif !if $(TLS_ENABLE) =3D=3D TRUE NetworkPkg/TlsDxe/TlsDxe.inf - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } !endif OvmfPkg/VirtioNetDxe/VirtioNet.inf =20 diff --git a/OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf b/OvmfPk= g/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf new file mode 100644 index 000000000000..5f83582a8313 --- /dev/null +++ b/OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf @@ -0,0 +1,55 @@ +## @file +# +# A hook-in library for NetworkPkg/TlsAuthConfigDxe, in order to set volat= ile +# variables related to TLS configuration, before TlsAuthConfigDxe or HttpD= xe +# (which is a UEFI_DRIVER) consume them. +# +# Copyright (C) 2013, 2015, 2018, Red Hat, Inc. +# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials are licensed and made availa= ble +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION =3D 1.26 + BASE_NAME =3D TlsAuthConfigLib + FILE_GUID =3D 660AB627-4C5F-4D42-A3B6-BD021E9028BD + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TlsAuthConfigLib|DXE_DRIVER + CONSTRUCTOR =3D TlsAuthConfigInit + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + TlsAuthConfigLib.c + +[Packages] + MdePkg/MdePkg.dec + NetworkPkg/NetworkPkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + QemuFwCfgLib + UefiRuntimeServicesTableLib + +[Guids] + gEfiTlsCaCertificateGuid ## PRODUCES ## Variable:L"TlsCaCertificate" + +[Depex] + gEfiVariableWriteArchProtocolGuid diff --git a/OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.c b/OvmfPkg/= Library/TlsAuthConfigLib/TlsAuthConfigLib.c new file mode 100644 index 000000000000..b5b33bc4fc69 --- /dev/null +++ b/OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.c @@ -0,0 +1,133 @@ +/** @file + + A hook-in library for NetworkPkg/TlsAuthConfigDxe, in order to set volat= ile + variables related to TLS configuration, before TlsAuthConfigDxe or HttpD= xe + (which is a UEFI_DRIVER) consume them. + + Copyright (C) 2013, 2015, 2018, Red Hat, Inc. + Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include + +#include + +#include +#include +#include +#include +#include + +/** + Read the list of trusted CA certificates from the fw_cfg file + "etc/edk2/https/cacerts", and store it to + gEfiTlsCaCertificateGuid:EFI_TLS_CA_CERTIFICATE_VARIABLE. + + The contents are validated (for well-formedness) by NetworkPkg/HttpDxe. +**/ +STATIC +VOID +SetCaCerts ( + VOID + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM HttpsCaCertsItem; + UINTN HttpsCaCertsSize; + VOID *HttpsCaCerts; + + Status =3D QemuFwCfgFindFile ("etc/edk2/https/cacerts", &HttpsCaCertsIte= m, + &HttpsCaCertsSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a:%a: not touching CA cert list\n", + gEfiCallerBaseName, __FUNCTION__)); + return; + } + + // + // Delete the current EFI_TLS_CA_CERTIFICATE_VARIABLE if it exists. This + // serves two purposes: + // + // (a) If the variable exists with EFI_VARIABLE_NON_VOLATILE attribute, = we + // cannot make it volatile without deleting it first. + // + // (b) If we fail to recreate the variable later, deleting the current o= ne is + // still justified if the fw_cfg file exists. Emptying the set of tr= usted + // CA certificates will fail HTTPS boot, which is better than trusti= ng + // any certificate that's possibly missing from the fw_cfg file. + // + Status =3D gRT->SetVariable ( + EFI_TLS_CA_CERTIFICATE_VARIABLE, // VariableName + &gEfiTlsCaCertificateGuid, // VendorGuid + 0, // Attributes + 0, // DataSize + NULL // Data + ); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_FOUND)) { + // + // This is fatal. + // + DEBUG ((DEBUG_ERROR, "%a:%a: failed to delete %g:\"%s\"\n", + gEfiCallerBaseName, __FUNCTION__, &gEfiTlsCaCertificateGuid, + EFI_TLS_CA_CERTIFICATE_VARIABLE)); + ASSERT_EFI_ERROR (Status); + CpuDeadLoop (); + } + + if (HttpsCaCertsSize =3D=3D 0) { + DEBUG ((DEBUG_VERBOSE, "%a:%a: applied empty CA cert list\n", + gEfiCallerBaseName, __FUNCTION__)); + return; + } + + HttpsCaCerts =3D AllocatePool (HttpsCaCertsSize); + if (HttpsCaCerts =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a:%a: failed to allocate HttpsCaCerts\n", + gEfiCallerBaseName, __FUNCTION__)); + return; + } + + QemuFwCfgSelectItem (HttpsCaCertsItem); + QemuFwCfgReadBytes (HttpsCaCertsSize, HttpsCaCerts); + + Status =3D gRT->SetVariable ( + EFI_TLS_CA_CERTIFICATE_VARIABLE, // VariableName + &gEfiTlsCaCertificateGuid, // VendorGuid + EFI_VARIABLE_BOOTSERVICE_ACCESS, // Attributes + HttpsCaCertsSize, // DataSize + HttpsCaCerts // Data + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a:%a: failed to set %g:\"%s\": %r\n", + gEfiCallerBaseName, __FUNCTION__, &gEfiTlsCaCertificateGuid, + EFI_TLS_CA_CERTIFICATE_VARIABLE, Status)); + goto FreeHttpsCaCerts; + } + + DEBUG ((DEBUG_VERBOSE, "%a:%a: stored CA cert list (%Lu byte(s))\n", + gEfiCallerBaseName, __FUNCTION__, (UINT64)HttpsCaCertsSize)); + +FreeHttpsCaCerts: + FreePool (HttpsCaCerts); +} + +RETURN_STATUS +EFIAPI +TlsAuthConfigInit ( + VOID + ) +{ + SetCaCerts (); + + return RETURN_SUCCESS; +} --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel