From nobody Sun May 5 19:00:53 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+90587+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+90587+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1655519545; cv=none; d=zohomail.com; s=zohoarc; b=N9XhIHGuAM/cX1hTK14Q7gKCOBTwVoDUbAMSppq+7Ru/EPY0Ca/8CimVWGl3WFA93+dpOnMlnvt+2B2H8StkiBatX43UeFsTmGy/XNUZK+ElkABRTtYEwS7YMaVma9EyXcNdHDj1HtiEU12726zl0x4dWG1Fw979SrZ8p/S5V58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655519545; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=mxXC+OfOe96KuPpBnfNk1wvY70vzDrf4c308lm2FZJ0=; b=DiSI2qGCDPEyxZTrxRUzQmHxyyh6RYODoMm5aS/hX4CTBPH2IdTHP1NqUS18cKUYFov9fuMXGAZiEgyQBqBmIgOx5yDH4FX2ThEJ7GCtw0W0IJ9Mll8PeeBD/SBcUqOrnqyDihrgTjkic5AXqQ36zFE/ODIAG9RrYBg4XH5Jh0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90587+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1655519545511841.1971610904067; Fri, 17 Jun 2022 19:32:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yxo5YY1788612xJofmrDXl1K; Fri, 17 Jun 2022 19:32:24 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.5676.1655519541534598350 for ; Fri, 17 Jun 2022 19:32:24 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="280355741" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="280355741" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:22 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="642270312" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.173.231]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:20 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [edk2-devel] [PATCH 1/3] OvmfPkg: Move TdxValidateCfv from PeilessStartupLib to PlatformInitLib Date: Sat, 18 Jun 2022 10:32:01 +0800 Message-Id: <3b3dce962500443d1281db91fd5e0ba2619aaf15.1655518585.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: UfAau7T7f3ysyjQ4yUbeiLlJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1655519544; bh=+AYp764QWAAyXiSOAFMhr8R4hgg/oVp+cwnda4MM5lA=; h=Cc:Date:From:Reply-To:Subject:To; b=Hp3gJJuklaxKvp/xCOji9golO2d2aILiq6hrTr2rq1AuZSH/O8uFzWq+CzMW58jg+Vz A31EOqZ843xsIrrf9glbsYHWbiEP7qmqUb2P259d/7N/ex76xdkQ936JseTa+MooDEsjD VVPIVLvl8m1ITKIP999AK5am8KZ5j3xGlzg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1655519546682100006 Content-Type: text/plain; charset="utf-8" From: Min M Xu TdxValidateCfv validates the integrity of Configuration FV (CFV). It was implemented in PeilessStartupLib which is included in IntelTdxX64. In OvmfPkgX64 we should validate CFV as well. So it is moved from PeilessStartupLib to PlatformInitLib so that it can be called in both OvmfPkgX64 and IntelTdxX64. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Include/Library/PlatformInitLib.h | 17 ++ OvmfPkg/Library/PeilessStartupLib/IntelTdx.c | 153 ------------------ .../PeilessStartupInternal.h | 17 -- OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 153 ++++++++++++++++++ 4 files changed, 170 insertions(+), 170 deletions(-) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index 2987a367cc9c..a3acfb1fb196 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -234,4 +234,21 @@ PlatformTdxPublishRamRegions ( VOID ); =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 + ); + #endif // PLATFORM_INIT_LIB_H_ 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/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 diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/P= latformInitLib/IntelTdx.c index c6d7c8bb6e0e..626a670c9c64 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include =20 @@ -561,3 +563,154 @@ PlatformTdxPublishRamRegions ( ); } } + +/** + 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; +} --=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 (#90587): https://edk2.groups.io/g/devel/message/90587 Mute This Topic: https://groups.io/mt/91835107/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 19:00:53 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+90588+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+90588+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1655519546; cv=none; d=zohomail.com; s=zohoarc; b=i+Qu3iBnjb7SdmF1SL8cG+XZZiYpu/kV/lf/7fPn+N3tO0WQ5AiTbZvqYgFF7owKGjL9NWq8UcjJH02yVAwLVpheTJu1+s80mNNm2eaPrG7PG2zpdURUoxRPQL+Mjfc17Z4P3k3hFjfq9irnWcPYQbT4NJySgfaJ8O2QGBR62bg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655519546; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xswbFh9sbt5Ut/GRV7/yFPvquqZYQ/TxUh70i+VDMIY=; b=N3ISqeyBNm7RMFhGd9jg9xFvMx3gKAeaHoI9CwOlws/O1/BIVJWG3pFO0ZuBxXHxQ1ObXw6lQxoSaKbN634h/qZKy0n5R+730o7nIi8RBq4pQDwzVzVW2Xb3bwhM6iexnOt+mRLM4HRhp0YAhvohVxoMhmI8Zvv1c41jGFb9WRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90588+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1655519546093697.3795283355689; Fri, 17 Jun 2022 19:32:26 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id x6ngYY1788612xIBwqvWLVHH; Fri, 17 Jun 2022 19:32:25 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.5676.1655519541534598350 for ; Fri, 17 Jun 2022 19:32:25 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="280355753" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="280355753" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:24 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="642270316" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.173.231]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:22 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [edk2-devel] [PATCH 2/3] OvmfPkg: Validate Cfv integrity in Tdx guest Date: Sat, 18 Jun 2022 10:32:02 +0800 Message-Id: <7d0710ff12be66b838fa2893f48d0837da7c2cec.1655518585.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: e60xmMjhxYrG3PLBAsz7r7QAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1655519545; bh=QolCPS/51KCmKd5Yuq3opfSXkSzyNlaHgK8PktAqoSY=; h=Cc:Date:From:Reply-To:Subject:To; b=Pmx2joQkAP4ibFpOXx3wfbLxu/fPb644s+ZdnpJe030DUnbQucAjrz4nSsYraE+Dk8V 4kxG5XZDfSCwY4B4ZwlrEyquCqQ1uoj6cpjH2ScpcxVl76AnNOWYAQuXnRLknoVOcKiCA 7G6oDnqe/VAexOrfXIJ+T4mV9FL638YHcz4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1655519546672100005 Content-Type: text/plain; charset="utf-8" From: Min M Xu Validate Configurtion FV (CFV) in Tdx guest. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Sec/SecMain.c | 8 ++++++++ OvmfPkg/Sec/SecMain.inf | 2 ++ 2 files changed, 10 insertions(+) diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 1167d22a68cc..f6c00b8dab96 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -768,6 +768,14 @@ SecCoreStartupWithStack ( if (ProcessTdxHobList () !=3D EFI_SUCCESS) { CpuDeadLoop (); } + + // + // Config FV (Cfv) contains the configuration information and its inte= grity + // should be validated. + // + if (!TdxValidateCfv ((UINT8 *)(UINTN)FixedPcdGet32 (PcdCfvBase), Fixed= PcdGet32 (PcdCfvRawDataSize))) { + CpuDeadLoop (); + } } =20 #endif diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 561a840f29c5..ae0094a15eda 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -84,6 +84,8 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdCfvBase + gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire --=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 (#90588): https://edk2.groups.io/g/devel/message/90588 Mute This Topic: https://groups.io/mt/91835109/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 19:00:53 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+90589+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+90589+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1655519548; cv=none; d=zohomail.com; s=zohoarc; b=G4VT9z9P4CZUBByWZOypERayz8B/OSqL6SzVeZNHvuuomy5zrloC6qDMqpfn6x0m5OWLtjDZi93yStos775xVegl0H+hNUYdt3VG5bcg/m+ChdoREWEClxYuT7FdMJUDis5NidRiHd1KdHOi/7edzsUhapSwrlux2NbVgB4KuX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655519548; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=mbMdZFwJEGwQ1465GzjX2VQ7reqqgbLxLFJFBPVEsJY=; b=MCKqq6yOviGatW0aFlekOHHOZVg0C8GQNJnmZtHTibZg3TaP9Lf0iViobTHeA5YqqwskiWAMDrPUHVm+kx73OiC4MFPxV907u/6lE9x8HxMJn5bq/MRekO0+ceq8wKcM8+cy+Esxx6oItTQySR44VHdRGhsNcVKRtJEWR5xUOE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90589+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1655519548334847.9592967583201; Fri, 17 Jun 2022 19:32:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TI5aYY1788612xZg3NASHyq0; Fri, 17 Jun 2022 19:32:28 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.5676.1655519541534598350 for ; Fri, 17 Jun 2022 19:32:27 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="280355770" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="280355770" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:26 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="642270321" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.173.231]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:24 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [edk2-devel] [PATCH 3/3] OvmfPkg: Initialize NvVarStore with Configuration FV in Td guest Date: Sat, 18 Jun 2022 10:32:03 +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: 1sbIuEnH8xe7umACdRPJ8skpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1655519548; bh=Mo3EqRU4PiptuRAry4nPgmGbhY2HiE1cIPsSwfuRUdc=; h=Cc:Date:From:Reply-To:Subject:To; b=YxDUGUhVoF+uEsnzySZBRUajAcjkD8tnVkQfjAQjX12jzwfZ64Fa+7+HwZG13LvfVdl RxEXn0Xfcsa7iggzsc7hWWSa9rw3h8EPzvVkPXcE51gLALvNbuzT6ohMBAk7EmKcAB4lL uIKfs4rw3/Cv36Xa3gGE8NVtJRzQoCmU0sc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1655519548684100013 Content-Type: text/plain; charset="utf-8" From: Min M Xu QEMU command option -pflash is not supported in Tdx guest. When Tdx guest is booted, EmuVariableFvbRuntimeDxe driver is loaded and the NvVarStore is initialized with empty content. This patch is to initialize the NvVarStore with the content of Configuration FV (CFV). Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c | 19 +++++++++++++++++++ OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf | 2 ++ 2 files changed, 21 insertions(+) diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFv= bRuntimeDxe/Fvb.c index 4fc715dc3681..96895272d806 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c @@ -717,6 +717,8 @@ FvbInitialize ( EFI_HANDLE Handle; EFI_PHYSICAL_ADDRESS Address; RETURN_STATUS PcdStatus; + UINT8 *CfvBase; + UINT32 CfvSize; =20 DEBUG ((DEBUG_INFO, "EMU Variable FVB Started\n")); =20 @@ -774,6 +776,23 @@ FvbInitialize ( =20 mEmuVarsFvb.BufferPtr =3D Ptr; =20 + // + // In Tdx guest the VarNvStore content should be initialized by the Conf= iguration FV (CFV). + // Integrity of the CFV has been validated by TdxValidateCfv (@PlatformI= nitLib) + // + if (TdIsEnabled ()) { + CfvBase =3D (UINT8 *)(UINTN)PcdGet32 (PcdCfvBase); + CfvSize =3D (UINT32)PcdGet32 (PcdCfvRawDataSize); + + if (CfvSize > mEmuVarsFvb.Size) { + DEBUG ((DEBUG_ERROR, "Size of CFV is larger than the EMU Variable FV= B.\n")); + ASSERT (FALSE); + } else { + CopyMem (Ptr, CfvBase, CfvSize); + Initialize =3D FALSE; + } + } + // // Initialize the main FV header and variable store header // diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf b/OvmfPkg/EmuVariable= FvbRuntimeDxe/Fvb.inf index 0811545cf7b3..15e8e673e8a0 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf @@ -56,6 +56,8 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + gUefiOvmfPkgTokenSpaceGuid.PcdCfvBase + gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 --=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 (#90589): https://edk2.groups.io/g/devel/message/90589 Mute This Topic: https://groups.io/mt/91835110/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-