From nobody Tue Feb 10 15:29:36 2026 Delivered-To: importer@patchew.org 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+82379+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634672416740850.442881688074; Tue, 19 Oct 2021 12:40:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DlSoYY1788612xxpgyvIfk4l; Tue, 19 Oct 2021 12:40:16 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.40]) by mx.groups.io with SMTP id smtpd.web08.15127.1634672414720075034 for ; Tue, 19 Oct 2021 12:40:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QHrNLzlbhEicztB2HN8SV7/Kqwp9e1/1/VvaTAEsGOhv1LNLyPXVXdUExLW4URZpwA0kgrIlvfqSH4rsZFRL7wZF4iml+yciKssVZmM2EsRxdsub1RGa+DlPMnG4V6FJWi3zJtoK8P4m8ufY28XldnWRDEa78vM2dqP3FNSlvzEynocf6hVofx6r9V+2W2CbSpAwKFy3HqFPYMD0X4JvWOXmJoSjQszxz/XQOdnpi9Q3kyuo9rhk9rHV68mWI+bovcClmWln+8sgDwqi6d79AXOTx8q71laePa7hx8QVUh4EToQiLpRxZNUqmEUPYIBx77BNVe5tp4ZxqnD+eTkbCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fpawcFy7fy8I2ByCNp/HEI/FZgWXmWZdp3diID0fM3o=; b=OoGnoaYhHCjYb+8Z3a7x4TIf+Wi5TDPsX78w7IzzF+DaAjah2maEAyrMoPgSuW6mzCveK0F6w3o4K9VyEE8/7nzX8k4rVzBHMBOhef31jt4SMZMAtUdErwnyWWeC73xkhC2hSg7w/0SET8u9SyUkqXaJ1V7wcXrtr6n+Q7wPhg1+ohFWG+WTrCIDsTnpmv0hzmKYPRH159PZU5E7F/guDkh/cAxp1Vg1OyS6m4MWCI+qcZqoLeqdINtNeoMop8Ddek65GcXj8O0fbz65rwXSWSWcT8qTb1r79PbhraC/7arf4qUyaxL6RyfPG5UfFRZpBY6o/xgP3u6k56wAxxEQKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MWHPR14CA0066.namprd14.prod.outlook.com (2603:10b6:300:81::28) by DM6PR12MB4514.namprd12.prod.outlook.com (2603:10b6:5:2a7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 19:40:09 +0000 X-Received: from CO1NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::d) by MWHPR14CA0066.outlook.office365.com (2603:10b6:300:81::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; 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+82379+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT004.mail.protection.outlook.com (10.13.175.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:08 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 19 Oct 2021 14:40:04 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v10 18/32] OvmfPkg/SecMain: validate the memory used for decompressing Fv Date: Tue, 19 Oct 2021 14:39:20 -0500 Message-ID: <20211019193934.1052465-19-brijesh.singh@amd.com> In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 59092138-6507-4713-910c-08d99338423b X-MS-TrafficTypeDiagnostic: DM6PR12MB4514: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 2neh/p0Son05lv9XA7va04j/PLQAxQ4rHaro3ps6TJIhuLjTRLDtd2Z4kDXH3m8MOUhbukgdIosViCLHTL/DFOCAdWbOQG1pVIjoJeaFMTqBK8vh0FrVnKaaIPR3A5e2M0yKluREf1ZVc74Feyy3m/NZP94dv5bDz9MT0PjM8gD/5sOX1Zh1UFNjbTgEfWSV5ZMgUIlfIQG6pxWWSBVOZHulbaoMOYtAedhj4zNh+m/ZfbGnUyPQAYdx2ruJycWdB78EMPrVqtXDUY13evICoUsA9I/nwAxnyJV1pTqZP6YGl17t+lVa52CfBUHZgxeOWQBAf7yyC0r7h80XzYPT1uUSWcRhbmH6a2aLJoUksWzjdx40YxmjM53G23y5yZjw5Ne/SuBAiDzZtd6OaGym3HqO+nD2vSn+EwLNKPb4Y4Z07TWxUIaIEWFn4eiOksP4mBLZp8sf2T/cxU7qqxcnxwBb1PGfB5V+gaXZcQDGIMrjuvugJzaqrpKB26ZRrk6R2bTKIWXp4Gy4H+JD7cx7+CmHAmviUOLBZqlL0R/PK2bdwmz47ULk86R9iH4XMI47PcfK57fP6nbfC1yvMXD3zZVDpHqS0vP7BCtGWKG7Qr7NzzMqqqC7T+04TBBLJD+LLHqO2Ch6bDGOe67UOUfqtPZYuZgD4NKql/K/lKMCa/QWUojE2LiHvROlzZiInDCKUatBt+6K/78LStByXGrTAgDdtrFI3zmzmTsAcV56AEwGIrQvavKtt4bIQQMg1AnouUGbBQFSbRYNb/3q5D+RgpPgMLFuRhdb3WZWT2cQg97xj+/awI2o3DsCyiMj7fhe X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:08.6728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59092138-6507-4713-910c-08d99338423b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4514 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,brijesh.singh@amd.com X-Gm-Message-State: oQW4IP07HHmNm6M4qFlFTIoOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634672416; bh=gmvOfWxgMIxxQSN0eMFUEFDIpVNJ7ygAEYYa5qkVBlQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cynYWVGIc0AnTaFAWMFAiFE5dvKfSp0peoa6PO2pyr+jj7pnh508Cc6kuwd6AqAiZJ8 Kb0pomQl88LufUMcaZOcVS7kTw+CLvfUTDBhYHj2FhIxOgMxL6f8YLoOVyIKHauIuViT6 xoAHF5UtmU3tSyXMxbo2ZbiSG03VZlCS7XU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634672418659100041 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The VMM launch sequence should have pre-validated all the data pages used in the Reset vector. The range does not cover the data pages used during the SEC phase (mainly PEI and DXE firmware volume decompression memory). When SEV-SNP is active, the memory must be pre-validated before the access. Add support to pre-validate the memory range from SnpSecPreValidatedStart to SnpSecPreValidatedEnd. This should be sufficent to enter into the PEI phase. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 4 ++++ .../PeiMemEncryptSevLib.inf | 2 ++ OvmfPkg/Sec/SecMain.inf | 3 +++ OvmfPkg/Sec/AmdSev.h | 23 +++++++++++++++++++ .../X64/PeiSnpSystemRamValidate.c | 5 ++++ OvmfPkg/Sec/AmdSev.c | 22 +++++++++++++++++- OvmfPkg/Sec/SecMain.c | 5 ++++ OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 ++++ 8 files changed, 68 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index ef0f319938b9..8dde5198c7cd 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -354,6 +354,10 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|0|UINT32|0x54 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize|0|UINT32|0x55 =20 + ## The range of memory that is validated by the SEC phase. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart|0|UINT32|0x56 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd|0|UINT32|0x57 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 49d5bd1beff1..50c83859d7e7 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -60,3 +60,5 @@ [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 9523a8ea6c8f..282e60a2764f 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -51,6 +51,7 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + MemEncryptSevLib CpuExceptionHandlerLib =20 [Ppis] @@ -73,6 +74,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/AmdSev.h index adad96d23189..411bbedae4cf 100644 --- a/OvmfPkg/Sec/AmdSev.h +++ b/OvmfPkg/Sec/AmdSev.h @@ -69,4 +69,27 @@ SevEsIsEnabled ( VOID ); =20 +/** + Validate System RAM used for decompressing the PEI and DXE firmware volum= es + when SEV-SNP is active. The PCDs SecValidatedStart and SecValidatedEnd are + set in OvmfPkg/FvmainCompactScratchEnd.fdf.inc. + +**/ +VOID +SecValidateSystemRam ( + VOID + ); + +/** + Determine if SEV-SNP is active. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled + +**/ +BOOLEAN +SevSnpIsEnabled ( + VOID + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index ee8b5bc8011f..d3ed8edecb03 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -29,6 +29,11 @@ STATIC SNP_PRE_VALIDATED_RANGE mPreValidatedRange[] =3D { FixedPcdGet32 (PcdOvmfSecPageTablesBase), FixedPcdGet32 (PcdOvmfPeiMemFvBase), }, + // The below range is pre-validated by the Sec/SecMain.c + { + FixedPcdGet32 (PcdOvmfSecValidatedStart), + FixedPcdGet32 (PcdOvmfSecValidatedEnd) + }, }; =20 STATIC diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c index 9dd42b195785..4f6a2f62ef99 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -55,7 +55,6 @@ SevEsProtocolFailure ( @retval FALSE SEV-SNP is not enabled =20 **/ -STATIC BOOLEAN SevSnpIsEnabled ( VOID @@ -277,3 +276,24 @@ SevEsIsEnabled ( =20 return (SevEsWorkArea->SevEsEnabled !=3D 0); } + +/** + Validate System RAM used for decompressing the PEI and DXE firmware volum= es + when SEV-SNP is active. The PCDs SecValidatedStart and SecValidatedEnd are + set in OvmfPkg/FvmainCompactScratchEnd.fdf.inc. + +**/ +VOID +SecValidateSystemRam ( + VOID + ) +{ + PHYSICAL_ADDRESS Start, End; + + if (IsSevGuest () && SevSnpIsEnabled ()) { + Start =3D (EFI_PHYSICAL_ADDRESS) (UINTN) PcdGet32 (PcdOvmfSecValidated= Start); + End =3D (EFI_PHYSICAL_ADDRESS) (UINTN) PcdGet32 (PcdOvmfSecValidatedEn= d); + + MemEncryptSevSnpPreValidateSystemRam (Start, EFI_SIZE_TO_PAGES (End - = Start)); + } +} diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 406e3a25d0cd..b173ff976073 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -847,6 +847,11 @@ SecCoreStartupWithStack ( SecCoreData.BootFirmwareVolumeBase =3D BootFv; SecCoreData.BootFirmwareVolumeSize =3D (UINTN) BootFv->FvLength; =20 + // + // Validate the System RAM used in the SEC Phase + // + SecValidateSystemRam (); + // // Make sure the 8259 is masked before initializing the Debug Agent and = the debug timer is enabled // diff --git a/OvmfPkg/FvmainCompactScratchEnd.fdf.inc b/OvmfPkg/FvmainCompac= tScratchEnd.fdf.inc index 46f52583297c..d8d45fc9aa6d 100644 --- a/OvmfPkg/FvmainCompactScratchEnd.fdf.inc +++ b/OvmfPkg/FvmainCompactScratchEnd.fdf.inc @@ -63,3 +63,8 @@ DEFINE DECOMP_SCRATCH_BASE =3D (($(DECOMP_SCRATCH_BASE_UNALIGNED= ) + $(DECOMP_SCRATCH_BASE_ALIGNMENT)) & $(DECOMP_SCRATCH_BASE_MASK)) =20 SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd =3D $(DECOMP= _SCRATCH_BASE) + $(DECOMP_SCRATCH_SIZE) + +# +# The range of pages that should be pre-validated during the SEC phase whe= n SEV-SNP is active in the guest VM. +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart =3D $(MEMFD_BASE_A= DDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd =3D $(DECOMP_SCRATCH= _BASE) + $(DECOMP_SCRATCH_SIZE) --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82379): https://edk2.groups.io/g/devel/message/82379 Mute This Topic: https://groups.io/mt/86448814/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-