From nobody Fri May 17 20:30:39 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+90836+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+90836+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493075517298.2155725563042; Wed, 29 Jun 2022 01:57:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tqkIYY1788612x66cfGmKSmI; Wed, 29 Jun 2022 01:57:55 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web09.9274.1656493074222649597 for ; Wed, 29 Jun 2022 01:57:54 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383729" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383729" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:50 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595158987" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:49 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 1/7] OvmfPkg/PeilessStartupLib: Delete TdxValidateCfv Date: Wed, 29 Jun 2022 16:56:57 +0800 Message-Id: In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: R3isjEWtm43XLPsBai5FBbwox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493075; bh=h5e1vCFafhjGk8Icg8FX4CpCN3vNGMKDO9nxrvj2vOs=; h=Cc:Date:From:Reply-To:Subject:To; b=VT1WA8rSE04UqiDHuvjU+YcNdLjicVIcxt1N2Wv5kDdXE9W+Wm2UEATUK77synw08aS No9qsghWf58Kwg8UAMCSZ57n89eO0kVjqtPp1aADMxvZlMP23jKwmrPOmXcGLAHY8n0WX Evq5pVGZUBIW4IheE7cfutPi/gtfwLeOdBE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493076053100001 Content-Type: text/plain; charset="utf-8" From: Min M Xu TdxValidateCfv is used to validate the integrity of FlashNvVarStore (PcdOvmfFlashNvStorageVariableBase) and it is not Tdx specific. So it will be moved to PlatformInitLib and be renamed to PlatformValidateNvVarStore in the following patch. And it will be called before EmuVaribleNvStore is initialized with the content in FlashNvVarStore. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Library/PeilessStartupLib/IntelTdx.c | 153 ------------------ .../PeilessStartupLib/PeilessStartup.c | 8 - .../PeilessStartupInternal.h | 17 -- 3 files changed, 178 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c b/OvmfPkg/Library= /PeilessStartupLib/IntelTdx.c index 484fd21057c8..216c413caad5 100644 --- a/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c +++ b/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include #include #include @@ -37,157 +35,6 @@ typedef struct { =20 #pragma pack() =20 -/** - Check padding data all bit should be 1. - - @param[in] Buffer - A pointer to buffer header - @param[in] BufferSize - Buffer size - - @retval TRUE - The padding data is valid. - @retval TRUE - The padding data is invalid. - -**/ -BOOLEAN -CheckPaddingData ( - IN UINT8 *Buffer, - IN UINT32 BufferSize - ) -{ - UINT32 index; - - for (index =3D 0; index < BufferSize; index++) { - if (Buffer[index] !=3D 0xFF) { - return FALSE; - } - } - - return TRUE; -} - -/** - Check the integrity of CFV data. - - @param[in] TdxCfvBase - A pointer to CFV header - @param[in] TdxCfvSize - CFV data size - - @retval TRUE - The CFV data is valid. - @retval FALSE - The CFV data is invalid. - -**/ -BOOLEAN -EFIAPI -TdxValidateCfv ( - IN UINT8 *TdxCfvBase, - IN UINT32 TdxCfvSize - ) -{ - UINT16 Checksum; - UINTN VariableBase; - UINT32 VariableOffset; - UINT32 VariableOffsetBeforeAlign; - EFI_FIRMWARE_VOLUME_HEADER *CfvFvHeader; - VARIABLE_STORE_HEADER *CfvVariableStoreHeader; - AUTHENTICATED_VARIABLE_HEADER *VariableHeader; - - static EFI_GUID FvHdrGUID =3D EFI_SYSTEM_NV_DATA_FV_GUID; - static EFI_GUID VarStoreHdrGUID =3D EFI_AUTHENTICATED_VARIABLE_GUID; - - VariableOffset =3D 0; - - if (TdxCfvBase =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "TDX CFV: CFV pointer is NULL\n")); - return FALSE; - } - - // - // Verify the header zerovetor, filesystemguid, - // revision, signature, attributes, fvlength, checksum - // HeaderLength cannot be an odd number - // - CfvFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)TdxCfvBase; - - if ((!IsZeroBuffer (CfvFvHeader->ZeroVector, 16)) || - (!CompareGuid (&FvHdrGUID, &CfvFvHeader->FileSystemGuid)) || - (CfvFvHeader->Signature !=3D EFI_FVH_SIGNATURE) || - (CfvFvHeader->Attributes !=3D 0x4feff) || - (CfvFvHeader->Revision !=3D EFI_FVH_REVISION) || - (CfvFvHeader->FvLength !=3D TdxCfvSize) - ) - { - DEBUG ((DEBUG_ERROR, "TDX CFV: Basic FV headers were invalid\n")); - return FALSE; - } - - // - // Verify the header checksum - // - Checksum =3D CalculateSum16 ((VOID *)CfvFvHeader, CfvFvHeader->HeaderLen= gth); - - if (Checksum !=3D 0) { - DEBUG ((DEBUG_ERROR, "TDX CFV: FV checksum was invalid\n")); - return FALSE; - } - - // - // Verify the header signature, size, format, state - // - CfvVariableStoreHeader =3D (VARIABLE_STORE_HEADER *)(TdxCfvBase + CfvFvH= eader->HeaderLength); - if ((!CompareGuid (&VarStoreHdrGUID, &CfvVariableStoreHeader->Signature)= ) || - (CfvVariableStoreHeader->Format !=3D VARIABLE_STORE_FORMATTED) || - (CfvVariableStoreHeader->State !=3D VARIABLE_STORE_HEALTHY) || - (CfvVariableStoreHeader->Size > (CfvFvHeader->FvLength - CfvFvHeader= ->HeaderLength)) || - (CfvVariableStoreHeader->Size < sizeof (VARIABLE_STORE_HEADER)) - ) - { - DEBUG ((DEBUG_ERROR, "TDX CFV: Variable Store header was invalid\n")); - return FALSE; - } - - // - // Verify the header startId, state - // Verify data to the end - // - VariableBase =3D (UINTN)TdxCfvBase + CfvFvHeader->HeaderLength + sizeof = (VARIABLE_STORE_HEADER); - while (VariableOffset < (CfvVariableStoreHeader->Size - sizeof (VARIABL= E_STORE_HEADER))) { - VariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)(VariableBase + Va= riableOffset); - if (VariableHeader->StartId !=3D VARIABLE_DATA) { - if (!CheckPaddingData ((UINT8 *)VariableHeader, CfvVariableStoreHead= er->Size - sizeof (VARIABLE_STORE_HEADER) - VariableOffset)) { - DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n")); - return FALSE; - } - - VariableOffset =3D CfvVariableStoreHeader->Size - sizeof (VARIABLE_S= TORE_HEADER); - } else { - if (!((VariableHeader->State =3D=3D VAR_IN_DELETED_TRANSITION) || - (VariableHeader->State =3D=3D VAR_DELETED) || - (VariableHeader->State =3D=3D VAR_HEADER_VALID_ONLY) || - (VariableHeader->State =3D=3D VAR_ADDED))) - { - DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n")); - return FALSE; - } - - VariableOffset +=3D sizeof (AUTHENTICATED_VARIABLE_HEADER) + Variabl= eHeader->NameSize + VariableHeader->DataSize; - // Verify VariableOffset should be less than or equal CfvVariableSto= reHeader->Size - sizeof(VARIABLE_STORE_HEADER) - if (VariableOffset > (CfvVariableStoreHeader->Size - sizeof (VARIABL= E_STORE_HEADER))) { - DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n")); - return FALSE; - } - - VariableOffsetBeforeAlign =3D VariableOffset; - // 4 byte align - VariableOffset =3D (VariableOffset + 3) & (UINTN)(~3); - - if (!CheckPaddingData ((UINT8 *)(VariableBase + VariableOffsetBefore= Align), VariableOffset - VariableOffsetBeforeAlign)) { - DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n")); - return FALSE; - } - } - } - - return TRUE; -} - /** Measure the Hoblist passed from the VMM. =20 diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index fdfefd00d732..7502ec44669e 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -179,14 +179,6 @@ PeilessStartup ( CpuDeadLoop (); } =20 - // - // Validate Tdx CFV - // - if (!TdxValidateCfv (CfvBase, FixedPcdGet32 (PcdCfvRawDataSize))) { - ASSERT (FALSE); - CpuDeadLoop (); - } - // // Measure Tdx CFV // diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h b/O= vmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h index 74b5f46552c2..09cac3e26c67 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h @@ -52,23 +52,6 @@ EFIAPI ConstructSecHobList ( ); =20 -/** - Check the integrity of CFV data. - - @param[in] TdxCfvBase - A pointer to CFV header - @param[in] TdxCfvSize - CFV data size - - @retval TRUE - The CFV data is valid. - @retval FALSE - The CFV data is invalid. - -**/ -BOOLEAN -EFIAPI -TdxValidateCfv ( - IN UINT8 *TdxCfvBase, - IN UINT32 TdxCfvSize - ); - /** Measure the Hoblist passed from the VMM. =20 --=20 2.29.2.windows.2 -=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 (#90836): https://edk2.groups.io/g/devel/message/90836 Mute This Topic: https://groups.io/mt/92061201/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 Fri May 17 20:30:39 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+90837+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+90837+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493075973862.9383989574171; Wed, 29 Jun 2022 01:57:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RkvTYY1788612x8VIG78eDNN; Wed, 29 Jun 2022 01:57:55 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web08.9254.1656493074684678755 for ; Wed, 29 Jun 2022 01:57:54 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383734" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383734" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:53 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159000" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:50 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 2/7] OvmfPkg/PlatformInitLib: Add functions for EmuVariableNvStore Date: Wed, 29 Jun 2022 16:56:58 +0800 Message-Id: <57573356b7c746205dd408d826ea2e2d387deef6.1656479990.git.min.m.xu@intel.com> In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: 5VoQg5WCUmx5bmuInvGKA3zJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493075; bh=g/exfIr2vld2QBx0GuzXlPn7R3T3yymV08l8hnkzaVU=; h=Cc:Date:From:Reply-To:Subject:To; b=kee0CVXXqBg0W39rlhAw0mXEE23YoiEuzQ9/wqwVrJNm9lr+2dnulBpMt5t96nAPVXb GqMioz6WIi4k+zxeHRDpHx9EO/OCSirzPD9YcxH9udNoms2uLbZ+OnPOg9Nh4Fn1ta1M+ ioL3gSkG0SmeJpIu82BnyyA5ZT/DojtZZL4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493077915100008 Content-Type: text/plain; charset="utf-8" From: Min M Xu There are 3 functions added for EmuVariableNvStore: - PlatformReserveEmuVariableNvStore - PlatformInitEmuVariableNvStore - PlatformValidateNvVarStore PlatformReserveEmuVariableNvStore allocate storage for NV variables early on so it will be at a consistent address. PlatformInitEmuVariableNvStore copies the content in PcdOvmfFlashNvStorageVariableBase to the storage allocated by PlatformReserveEmuVariableNvStore. This is used in the case that OVMF is launched with -bios parameter. Because in that situation UEFI variables will be partially emulated, and non-volatile variables may lose their contents after a reboot. This makes the secure boot feature not working. PlatformValidateNvVarStore is renamed from TdxValidateCfv and it is used to validate the integrity of FlashNvVarStore (PcdOvmfFlashNvStorageVariableBase). It should be called before PlatformInitEmuVariableNvStore is called to copy over the content. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Include/Library/PlatformInitLib.h | 51 ++++ OvmfPkg/Library/PlatformInitLib/Platform.c | 238 ++++++++++++++++++ .../PlatformInitLib/PlatformInitLib.inf | 3 + 3 files changed, 292 insertions(+) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index 2987a367cc9c..c5234bf26d45 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -234,4 +234,55 @@ PlatformTdxPublishRamRegions ( VOID ); =20 +/** + Check the integrity of NvVarStore. + + @param[in] NvVarStoreBase - A pointer to NvVarStore header + @param[in] NvVarStoreSize - NvVarStore size + + @retval TRUE - The NvVarStore is valid. + @retval FALSE - The NvVarStore is invalid. + +**/ +BOOLEAN +EFIAPI +PlatformValidateNvVarStore ( + IN UINT8 *NvVarStoreBase, + IN UINT32 NvVarStoreSize + ); + +/** + Allocate storage for NV variables early on so it will be + at a consistent address. Since VM memory is preserved + across reboots, this allows the NV variable storage to survive + a VM reboot. + + * + * @retval VOID* The pointer to the storage for NV Variables + */ +VOID * +EFIAPI +PlatformReserveEmuVariableNvStore ( + VOID + ); + +/** + When OVMF is lauched with -bios parameter, UEFI variables will be + partially emulated, and non-volatile variables may lose their contents + after a reboot. This makes the secure boot feature not working. + + This function is used to initialize the EmuVariableNvStore + with the conent in PcdOvmfFlashNvStorageVariableBase. + + @param[in] EmuVariableNvStore - A pointer to EmuVariableNvStore + + @retval EFI_SUCCESS - Successfully init the EmuVariableNvStore + @retval Others - As the error code indicates + */ +EFI_STATUS +EFIAPI +PlatformInitEmuVariableNvStore ( + IN VOID *EmuVariableNvStore + ); + #endif // PLATFORM_INIT_LIB_H_ diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index c3d34e43af5a..2582689ffe35 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -25,10 +25,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include =20 #include @@ -576,3 +579,238 @@ PlatformMaxCpuCountInitialization ( PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber =3D MaxCpuCount; PlatformInfoHob->PcdCpuBootLogicalProcessorNumber =3D BootCpuCount; } + +/** + Check padding data all bit should be 1. + + @param[in] Buffer - A pointer to buffer header + @param[in] BufferSize - Buffer size + + @retval TRUE - The padding data is valid. + @retval TRUE - The padding data is invalid. + +**/ +BOOLEAN +CheckPaddingData ( + IN UINT8 *Buffer, + IN UINT32 BufferSize + ) +{ + UINT32 index; + + for (index =3D 0; index < BufferSize; index++) { + if (Buffer[index] !=3D 0xFF) { + return FALSE; + } + } + + return TRUE; +} + +/** + Check the integrity of NvVarStore. + + @param[in] NvVarStoreBase - A pointer to NvVarStore header + @param[in] NvVarStoreSize - NvVarStore size + + @retval TRUE - The NvVarStore is valid. + @retval FALSE - The NvVarStore is invalid. + +**/ +BOOLEAN +EFIAPI +PlatformValidateNvVarStore ( + IN UINT8 *NvVarStoreBase, + IN UINT32 NvVarStoreSize + ) +{ + UINT16 Checksum; + UINTN VariableBase; + UINT32 VariableOffset; + UINT32 VariableOffsetBeforeAlign; + EFI_FIRMWARE_VOLUME_HEADER *NvVarStoreFvHeader; + VARIABLE_STORE_HEADER *NvVarStoreHeader; + AUTHENTICATED_VARIABLE_HEADER *VariableHeader; + + static EFI_GUID FvHdrGUID =3D EFI_SYSTEM_NV_DATA_FV_GUID; + static EFI_GUID VarStoreHdrGUID =3D EFI_AUTHENTICATED_VARIABLE_GUID; + + VariableOffset =3D 0; + + if (NvVarStoreBase =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "NvVarStore pointer is NULL.\n")); + return FALSE; + } + + // + // Verify the header zerovetor, filesystemguid, + // revision, signature, attributes, fvlength, checksum + // HeaderLength cannot be an odd number + // + NvVarStoreFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)NvVarStoreBase; + + if ((!IsZeroBuffer (NvVarStoreFvHeader->ZeroVector, 16)) || + (!CompareGuid (&FvHdrGUID, &NvVarStoreFvHeader->FileSystemGuid)) || + (NvVarStoreFvHeader->Signature !=3D EFI_FVH_SIGNATURE) || + (NvVarStoreFvHeader->Attributes !=3D 0x4feff) || + (NvVarStoreFvHeader->Revision !=3D EFI_FVH_REVISION) || + (NvVarStoreFvHeader->FvLength !=3D NvVarStoreSize) + ) + { + DEBUG ((DEBUG_ERROR, "NvVarStore FV headers were invalid.\n")); + return FALSE; + } + + // + // Verify the header checksum + // + Checksum =3D CalculateSum16 ((VOID *)NvVarStoreFvHeader, NvVarStoreFvHea= der->HeaderLength); + + if (Checksum !=3D 0) { + DEBUG ((DEBUG_ERROR, "NvVarStore FV checksum was invalid.\n")); + return FALSE; + } + + // + // Verify the header signature, size, format, state + // + NvVarStoreHeader =3D (VARIABLE_STORE_HEADER *)(NvVarStoreBase + NvVarSto= reFvHeader->HeaderLength); + if ((!CompareGuid (&VarStoreHdrGUID, &NvVarStoreHeader->Signature)) || + (NvVarStoreHeader->Format !=3D VARIABLE_STORE_FORMATTED) || + (NvVarStoreHeader->State !=3D VARIABLE_STORE_HEALTHY) || + (NvVarStoreHeader->Size > (NvVarStoreFvHeader->FvLength - NvVarStore= FvHeader->HeaderLength)) || + (NvVarStoreHeader->Size < sizeof (VARIABLE_STORE_HEADER)) + ) + { + DEBUG ((DEBUG_ERROR, "NvVarStore header signature/size/format/state we= re invalid.\n")); + return FALSE; + } + + // + // Verify the header startId, state + // Verify data to the end + // + VariableBase =3D (UINTN)NvVarStoreBase + NvVarStoreFvHeader->HeaderLengt= h + sizeof (VARIABLE_STORE_HEADER); + while (VariableOffset < (NvVarStoreHeader->Size - sizeof (VARIABLE_STOR= E_HEADER))) { + VariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)(VariableBase + Va= riableOffset); + if (VariableHeader->StartId !=3D VARIABLE_DATA) { + if (!CheckPaddingData ((UINT8 *)VariableHeader, NvVarStoreHeader->Si= ze - sizeof (VARIABLE_STORE_HEADER) - VariableOffset)) { + DEBUG ((DEBUG_ERROR, "NvVarStore variable header StartId was inval= id.\n")); + return FALSE; + } + + VariableOffset =3D NvVarStoreHeader->Size - sizeof (VARIABLE_STORE_H= EADER); + } else { + if (!((VariableHeader->State =3D=3D VAR_IN_DELETED_TRANSITION) || + (VariableHeader->State =3D=3D VAR_DELETED) || + (VariableHeader->State =3D=3D VAR_HEADER_VALID_ONLY) || + (VariableHeader->State =3D=3D VAR_ADDED))) + { + DEBUG ((DEBUG_ERROR, "NvVarStore Variable header State was invalid= .\n")); + return FALSE; + } + + VariableOffset +=3D sizeof (AUTHENTICATED_VARIABLE_HEADER) + Variabl= eHeader->NameSize + VariableHeader->DataSize; + // Verify VariableOffset should be less than or equal NvVarStoreHead= er->Size - sizeof(VARIABLE_STORE_HEADER) + if (VariableOffset > (NvVarStoreHeader->Size - sizeof (VARIABLE_STOR= E_HEADER))) { + DEBUG ((DEBUG_ERROR, "NvVarStore Variable header VariableOffset wa= s invalid.\n")); + return FALSE; + } + + VariableOffsetBeforeAlign =3D VariableOffset; + // 4 byte align + VariableOffset =3D (VariableOffset + 3) & (UINTN)(~3); + + if (!CheckPaddingData ((UINT8 *)(VariableBase + VariableOffsetBefore= Align), VariableOffset - VariableOffsetBeforeAlign)) { + DEBUG ((DEBUG_ERROR, "NvVarStore Variable header PaddingData was i= nvalid.\n")); + return FALSE; + } + } + } + + return TRUE; +} + +/** + Allocate storage for NV variables early on so it will be + at a consistent address. Since VM memory is preserved + across reboots, this allows the NV variable storage to survive + a VM reboot. + + * + * @retval VOID* The pointer to the storage for NV Variables + */ +VOID * +EFIAPI +PlatformReserveEmuVariableNvStore ( + VOID + ) +{ + VOID *VariableStore; + UINT32 VarStoreSize; + + VarStoreSize =3D 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize); + // + // Allocate storage for NV variables early on so it will be + // at a consistent address. Since VM memory is preserved + // across reboots, this allows the NV variable storage to survive + // a VM reboot. + // + VariableStore =3D + AllocateRuntimePages ( + EFI_SIZE_TO_PAGES (VarStoreSize) + ); + DEBUG (( + DEBUG_INFO, + "Reserved variable store memory: 0x%p; size: %dkb\n", + VariableStore, + VarStoreSize / 1024 + )); + + return VariableStore; +} + +/** + When OVMF is lauched with -bios parameter, UEFI variables will be + partially emulated, and non-volatile variables may lose their contents + after a reboot. This makes the secure boot feature not working. + + This function is used to initialize the EmuVariableNvStore + with the conent in PcdOvmfFlashNvStorageVariableBase. + + @param[in] EmuVariableNvStore - A pointer to EmuVariableNvStore + + @retval EFI_SUCCESS - Successfully init the EmuVariableNvStore + @retval Others - As the error code indicates + */ +EFI_STATUS +EFIAPI +PlatformInitEmuVariableNvStore ( + IN VOID *EmuVariableNvStore + ) +{ + UINT8 *Base; + UINT32 Size; + UINT32 EmuVariableNvStoreSize; + + EmuVariableNvStoreSize =3D 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize); + if ((EmuVariableNvStore =3D=3D NULL) || (EmuVariableNvStoreSize =3D=3D 0= )) { + DEBUG ((DEBUG_ERROR, "Invalid EmuVariableNvStore parameter.\n")); + return EFI_INVALID_PARAMETER; + } + + Base =3D (UINT8 *)(UINTN)PcdGet32 (PcdOvmfFlashNvStorageVariableBase); + Size =3D (UINT32)PcdGet32 (PcdFlashNvStorageVariableSize); + ASSERT (Size < EmuVariableNvStoreSize); + + if (!PlatformValidateNvVarStore (Base, PcdGet32 (PcdCfvRawDataSize))) { + ASSERT (FALSE); + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "Init EmuVariableNvStore with the content in FlashNv= Storage\n")); + + CopyMem (EmuVariableNvStore, Base, Size); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index d2fa2d998df8..86a82ad3e084 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -47,6 +47,7 @@ HobLib QemuFwCfgLib QemuFwCfgSimpleParserLib + MemoryAllocationLib MtrrLib PcdLib PciLib @@ -96,6 +97,8 @@ gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize =20 gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase + gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize =20 [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode --=20 2.29.2.windows.2 -=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 (#90837): https://edk2.groups.io/g/devel/message/90837 Mute This Topic: https://groups.io/mt/92061202/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 Fri May 17 20:30:39 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+90838+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+90838+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493076883481.0506597463442; Wed, 29 Jun 2022 01:57:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jirCYY1788612xtt9fE7RnP8; Wed, 29 Jun 2022 01:57:56 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.9272.1656493075185691776 for ; Wed, 29 Jun 2022 01:57:55 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383744" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383744" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:54 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159014" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:53 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 3/7] OvmfPkg/PlatformPei: Update ReserveEmuVariableNvStore Date: Wed, 29 Jun 2022 16:56:59 +0800 Message-Id: In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: 5WVole6gdQF8VHGYJST54hMGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493076; bh=OqGsckkKPz8wYflbtsQWNy2HaWcTxRCh8SwBzUAGi7U=; h=Cc:Date:From:Reply-To:Subject:To; b=px24f+XH4nMLtTZV22koUGFl9OCC9UllDbHpx5aNDp1QhQVjNwz+HFihp4KXTebJuSG wdNPAGpopFvLW4hqo2h0EOxOuatwAi1UvEhjPNzG10SIw5khrJ6IKFlFKeGVp4mIVg5As ycSh7TwimnjeuPUxgBnetH6QyT6mkJ4n83s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493077874100007 Content-Type: text/plain; charset="utf-8" From: Min M Xu ReserveEmuVariableNvStore is updated with below 2 functions defined in PlatformInitLib: - PlatformReserveEmuVariableNvStore - PlatformInitEmuVariableNvStore PlatformInitEmuVariableNvStore works when secure boot feature is enabled. This is because secure boot needs the EFI variables (PK/KEK/DB/DBX, etc) and EmuVariableNvStore is cleared when OVMF is launched with -bios parameter. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/PlatformPei/Platform.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 009db67ee60a..b1f8140d6041 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -220,24 +220,13 @@ ReserveEmuVariableNvStore ( EFI_PHYSICAL_ADDRESS VariableStore; RETURN_STATUS PcdStatus; =20 - // - // Allocate storage for NV variables early on so it will be - // at a consistent address. Since VM memory is preserved - // across reboots, this allows the NV variable storage to survive - // a VM reboot. - // - VariableStore =3D - (EFI_PHYSICAL_ADDRESS)(UINTN) - AllocateRuntimePages ( - EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) - ); - DEBUG (( - DEBUG_INFO, - "Reserved variable store memory: 0x%lX; size: %dkb\n", - VariableStore, - (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 - )); - PcdStatus =3D PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); + VariableStore =3D (EFI_PHYSICAL_ADDRESS)(UINTN)PlatformReserveEmuVariabl= eNvStore (); + PcdStatus =3D PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStor= e); + + #ifdef SECURE_BOOT_FEATURE_ENABLED + PlatformInitEmuVariableNvStore ((VOID *)(UINTN)VariableStore); + #endif + ASSERT_RETURN_ERROR (PcdStatus); } =20 --=20 2.29.2.windows.2 -=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 (#90838): https://edk2.groups.io/g/devel/message/90838 Mute This Topic: https://groups.io/mt/92061203/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 Fri May 17 20:30:39 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+90839+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+90839+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493077994835.5085128617073; Wed, 29 Jun 2022 01:57:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QSf1YY1788612xiG0Sqn6kz4; Wed, 29 Jun 2022 01:57:57 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.9272.1656493075185691776 for ; Wed, 29 Jun 2022 01:57:57 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383761" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383761" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:56 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159034" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:55 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 4/7] OvmfPkg: Reserve and init EmuVariableNvStore in Pei-less Startup Date: Wed, 29 Jun 2022 16:57:00 +0800 Message-Id: <3926260258c8b6a9054630a7772b792caa6b2f8b.1656479990.git.min.m.xu@intel.com> In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: KUx4xRV65IwnYGVEZ2PYS8iDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493077; bh=cE9TNRQ9YzzA5LV2P8o71IiLhKg0nW5obOEBp7Gkfqo=; h=Cc:Date:From:Reply-To:Subject:To; b=BsY04m+U/q6POlT4Ic5OBVB4t/5xwIS5b/QkS+zzaclzvLYCV3sGN8fubhwK08ls6Js ioOmOdyO0dVOLRaSM8WblN0m69va6qR+4JMn6GHqXso6z8yq6AVZ8pv1j0Jt795Zyu9Ki Il+6IBmC7gUbo60Itt2FU3ErQSEMBJKlnkM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493079889100017 Content-Type: text/plain; charset="utf-8" From: Min M Xu EmuVariableNvStore is reserved and init with below 2 functions defined in PlatformInitLib: - PlatformReserveEmuVariableNvStore - PlatformInitEmuVariableNvStore PlatformInitEmuVariableNvStore works when secure boot feature is enabled. This is because secure boot needs the EFI variables (PK/KEK/DB/DBX, etc) and EmuVariableNvStore is cleared when OVMF is launched with -bios parameter. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index 7502ec44669e..380e71597206 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -42,6 +42,7 @@ InitializePlatform ( ) { UINT32 LowerMemorySize; + VOID *VariableStore; =20 DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n")); PlatformDebugDumpCmos (); @@ -79,6 +80,12 @@ InitializePlatform ( LowerMemorySize )); =20 + VariableStore =3D PlatformReserveEmuVar= iableNvStore (); + PlatformInfoHob->PcdEmuVariableNvStoreReserved =3D (UINT64)(UINTN)Variab= leStore; + #ifdef SECURE_BOOT_FEATURE_ENABLED + PlatformInitEmuVariableNvStore (VariableStore); + #endif + if (TdIsEnabled ()) { PlatformTdxPublishRamRegions (); } else { --=20 2.29.2.windows.2 -=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 (#90839): https://edk2.groups.io/g/devel/message/90839 Mute This Topic: https://groups.io/mt/92061205/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 Fri May 17 20:30:39 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+90840+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+90840+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16564930797851000.476035048378; Wed, 29 Jun 2022 01:57:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qJfCYY1788612xv0oJpyOE1D; Wed, 29 Jun 2022 01:57:59 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.9272.1656493075185691776 for ; Wed, 29 Jun 2022 01:57:58 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383777" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383777" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:58 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159059" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:56 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 5/7] OvmfPkg/NvVarsFileLib: Shortcut ConnectNvVarsToFileSystem in secure-boot Date: Wed, 29 Jun 2022 16:57:01 +0800 Message-Id: In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: FEW4VLFm7h8lma52GvVLciy6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493079; bh=fUXKXzZ6+lZQQKDOUqSfIjTjE1GzKe4+s5bJ7oLLfXs=; h=Cc:Date:From:Reply-To:Subject:To; b=Ne47rHELPou+hjGo/2D61xutt4cn/+V46jhO8JlxAtu/rtxdkpAdgbAgPcVIQBntSeG XVsWQLd1B5HbQyqZrXSuVW9LacOd90cTHw+IXIdc+H/dIAqUu1PreZrUv1KezvD1HomZK Ox9hDwIPgmibcQ/RCA0MvijVQzLwQQHbY7Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493081879100023 Content-Type: text/plain; charset="utf-8" From: Min M Xu OvmfPkg/Library/NvVarsFileLib allows loading variables into emulated varstore from a on-disk NvVars file. We can't allow that when secure boot is active. So check secure-boot feature and shortcut the ConnectNvVarsToFileSystem() function when sb is enabled. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Suggested-by: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c b/OvmfPkg/Librar= y/NvVarsFileLib/NvVarsFileLib.c index 21b71524ea48..72289da35819 100644 --- a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c +++ b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c @@ -28,6 +28,12 @@ ConnectNvVarsToFileSystem ( IN EFI_HANDLE FsHandle ) { + #ifdef SECURE_BOOT_FEATURE_ENABLED + + return EFI_UNSUPPORTED; + + #else + EFI_STATUS Status; =20 // @@ -46,6 +52,7 @@ ConnectNvVarsToFileSystem ( } =20 return Status; + #endif } =20 /** --=20 2.29.2.windows.2 -=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 (#90840): https://edk2.groups.io/g/devel/message/90840 Mute This Topic: https://groups.io/mt/92061207/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 Fri May 17 20:30:39 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+90841+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+90841+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493081723560.4737803014038; Wed, 29 Jun 2022 01:58:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id upLyYY1788612xjRvDJJu1LD; Wed, 29 Jun 2022 01:58:01 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.9272.1656493075185691776 for ; Wed, 29 Jun 2022 01:58:00 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383797" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383797" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:58:00 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159075" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:57:58 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 6/7] OvmfPkg/TdxDxe: Set PcdEmuVariableNvStoreReserved Date: Wed, 29 Jun 2022 16:57:02 +0800 Message-Id: <982b776e42e16aa8bdaa10bf26345b5579bfe489.1656479990.git.min.m.xu@intel.com> In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: 4zZmBrNizbiSCH6ce4YRnSUAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493081; bh=aqDVIDbse9MSow/MFh9jjBrN1RzTVMDlKBRBo7cp6KA=; h=Cc:Date:From:Reply-To:Subject:To; b=eMZ4XyalHsX429sIFtAJqHy0jPpO9o9i7R/EwLectPRr2W3qVZDsGNvpQwPnLeRB8AA oddbtr2r/OQrojCvzQLzm8D1PHTAtFMR3QPhb9hm56b0UoPSsP+n72uukxmu9HnDadSse sR5jlNGLhcvk4usUf8befnCJcY4Gh5G+mY4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493081920100024 Content-Type: text/plain; charset="utf-8" From: Min M Xu Set PcdEmuVariableNvStoreReserved with the value in PlatformInfoHob. It is the address of the EmuVariableNvStore reserved in Pei-less startup. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/TdxDxe/TdxDxe.c | 2 ++ OvmfPkg/TdxDxe/TdxDxe.inf | 1 + 2 files changed, 3 insertions(+) diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c index 2318db989792..837f1f8e3024 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.c +++ b/OvmfPkg/TdxDxe/TdxDxe.c @@ -64,6 +64,8 @@ SetPcdSettings ( PlatformInfoHob->PcdCpuBootLogicalProcessorNumber )); =20 + PcdSet64S (PcdEmuVariableNvStoreReserved, PlatformInfoHob->PcdEmuVariabl= eNvStoreReserved); + if (TdIsEnabled ()) { PcdStatus =3D PcdSet64S (PcdTdxSharedBitMask, TdSharedPageMask ()); ASSERT_RETURN_ERROR (PcdStatus); diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf index a7e0abda1522..3ce8a5c32c98 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.inf +++ b/OvmfPkg/TdxDxe/TdxDxe.inf @@ -68,3 +68,4 @@ gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved --=20 2.29.2.windows.2 -=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 (#90841): https://edk2.groups.io/g/devel/message/90841 Mute This Topic: https://groups.io/mt/92061208/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 Fri May 17 20:30:39 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+90842+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+90842+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656493083789657.8829481048701; Wed, 29 Jun 2022 01:58:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eSJyYY1788612xQygbmkZPp1; Wed, 29 Jun 2022 01:58:03 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.9272.1656493075185691776 for ; Wed, 29 Jun 2022 01:58:02 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="262383829" X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="262383829" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:58:02 -0700 X-IronPort-AV: E=Sophos;i="5.92,231,1650956400"; d="scan'208";a="595159110" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.128]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 01:58:00 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V3 7/7] OvmfPkg: Add build-flag SECURE_BOOT_FEATURE_ENABLED Date: Wed, 29 Jun 2022 16:57:03 +0800 Message-Id: <5e820f4191fdd556912b95aa47d7e67552d8270a.1656479990.git.min.m.xu@intel.com> In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: N86UIzTVgqfRDJTSUKKeOH3mx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656493083; bh=6midV4MYs5EviKoypK42LE6dYtpwmmT4tuwcj1EvJZE=; h=Cc:Date:From:Reply-To:Subject:To; b=OqVBaOHuq8YEGrfeO/iNBRkQFctdgXUrMlC0hfBe0No3ep7JPjx9I59bbKoE+PEfICW 6uNcY57SiBqXAcAnI78Dd/aE4P8E2BAIuqwTPWbk4v34eYRbR4NBCJBCehUi803P2/97p XR5jH0kFTHiFuhg9D4oervshwH3U+KaKA8c= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656493085967100003 Content-Type: text/plain; charset="utf-8" From: Min M Xu SECURE_BOOT_FEATURE_ENABLED is the build-flag defined when secure boot is enabled. Currently this flag is used in below lib: - OvmfPkg/PlatformPei - PeilessStartupLib So it is defined in below 5 .dsc - OvmfPkg/CloudHv/CloudHvX64.dsc - OvmfPkg/IntelTdx/IntelTdxX64.dsc - OvmfPkg/OvmfPkgIa32.dsc - OvmfPkg/OvmfPkgIa32X64.dsc - OvmfPkg/OvmfPkgX64.dsc Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/CloudHv/CloudHvX64.dsc | 9 +++++++++ OvmfPkg/IntelTdx/IntelTdxX64.dsc | 9 +++++++++ OvmfPkg/OvmfPkgIa32.dsc | 9 +++++++++ OvmfPkg/OvmfPkgIa32X64.dsc | 9 +++++++++ OvmfPkg/OvmfPkgX64.dsc | 9 +++++++++ 5 files changed, 45 insertions(+) diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index ca601aa09d3a..2712731caf55 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -93,6 +93,15 @@ INTEL:*_*_*_CC_FLAGS =3D /D DISABLE_NEW_DEPRECATED_INTERFACES GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES =20 + # + # SECURE_BOOT_FEATURE_ENABLED + # +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MSFT:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + INTEL:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D SECURE_BOOT_FEATURE_ENABLED +!endif + !include NetworkPkg/NetworkBuildOptions.dsc.inc =20 [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index c662ae8720ff..f4f495a9d199 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -85,6 +85,15 @@ INTEL:*_*_*_CC_FLAGS =3D /D TDX_PEI_LESS_BOOT GCC:*_*_*_CC_FLAGS =3D -D TDX_PEI_LESS_BOOT =20 + # + # SECURE_BOOT_FEATURE_ENABLED + # +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MSFT:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + INTEL:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D SECURE_BOOT_FEATURE_ENABLED +!endif + [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] GCC:*_*_*_DLINK_FLAGS =3D -z common-page-size=3D0x1000 XCODE:*_*_*_DLINK_FLAGS =3D -seg1addr 0x1000 -segalign 0x1000 diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 934edbbd2a7b..3126e695b7dd 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -89,6 +89,15 @@ INTEL:*_*_*_CC_FLAGS =3D /D DISABLE_NEW_DEPRECATED_INTERFACES GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES =20 + # + # SECURE_BOOT_FEATURE_ENABLED + # +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MSFT:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + INTEL:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D SECURE_BOOT_FEATURE_ENABLED +!endif + !include NetworkPkg/NetworkBuildOptions.dsc.inc =20 [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 4f432c294958..0c86e0b4882d 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -93,6 +93,15 @@ INTEL:*_*_*_CC_FLAGS =3D /D DISABLE_NEW_DEPRECATED_INTERFACES GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES =20 + # + # SECURE_BOOT_FEATURE_ENABLED + # +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MSFT:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + INTEL:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D SECURE_BOOT_FEATURE_ENABLED +!endif + !include NetworkPkg/NetworkBuildOptions.dsc.inc =20 [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index b22da97d4f77..a36bcef4fd3c 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -106,6 +106,15 @@ INTEL:*_*_*_CC_FLAGS =3D /D TDX_GUEST_SUPPORTED GCC:*_*_*_CC_FLAGS =3D -D TDX_GUEST_SUPPORTED =20 + # + # SECURE_BOOT_FEATURE_ENABLED + # +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MSFT:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + INTEL:*_*_*_CC_FLAGS =3D /D SECURE_BOOT_FEATURE_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D SECURE_BOOT_FEATURE_ENABLED +!endif + !include NetworkPkg/NetworkBuildOptions.dsc.inc =20 [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] --=20 2.29.2.windows.2 -=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 (#90842): https://edk2.groups.io/g/devel/message/90842 Mute This Topic: https://groups.io/mt/92061210/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-