From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.63]) by mx.groups.io with SMTP id smtpd.web08.5394.1625057668594210863 for ; Wed, 30 Jun 2021 05:54:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=dYXwaNiO; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.223.63, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dHjFCLZHC25TkXM5C44hPWvochItk3r+Yk+CfjD/FedYTjAXrHCnUwEiJV8zxy1hseEnwzaTxN6yAKuwHJiRaKbyfaRWbBPUZLCiP/qIbdvWwHoxbIjyilmEjEJBiD/0n2J27KrXdYKW1JhSycap55LRaHRjDuvtL1LPFb+lhrtvR8aDf3pjFtjr5R9NXG4hYtAaH6eSSH/64FNu/nkJFfTftS8Z0zu8bHRPgq8sXmx0qx72xB/1KTl9bZxy9TjGN6Kz197IMKqeYfjNA2mn6iHsMnCIm/ixcxrzdoXKbSMrG/C1+52QbmSY3D7owPUupCdm0pVJAZTD8zRe/laHNw== 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-SenderADCheck; bh=mrktsuZR9NLJoc0+A+8C6Zq8mLrEDd31HpfENKOZcZU=; b=ezHG8pxySjObO4y0T4aT3/2uoMBCBIkDEeVAk61MIIpeJMM2bV0ExBNeW02g+UaWb4GAkomEKnGPCkhZd9uvsMipSf/OFW74Z3IJYcJVTDSqlkzf8mfoLMnfM6hx+E26GYgLPrRPphPN4KQwFX3DwDNPCz1iNpBIIoAZ9iViqL8LTwRKNCJvg9aPusj4nLqadwDoNKbYd9WDEuLidmZRHuKvov0guDCTUSIzhKkIfPaHd4Aypp35P+OCBEXDSzU/hlIPkG9AWKj1mIpHHQKy0EBF5C4JbuQIF9rhqPgawD46f3swxDC1YCwD0yc8Uvw33yjD7OKnFpckAvOEjl/eqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mrktsuZR9NLJoc0+A+8C6Zq8mLrEDd31HpfENKOZcZU=; b=dYXwaNiOGoSIJ8uHh3ZMJXO5uMXVZPMkkElgR0f60w0Rwov5l+jXvsMt1amsVACqE47BwwyJHY1zjgRlf7KX05FR4tNZN1cOJhDWoMdfAteHovEZJC1/DPXIiJ4qgPvtkGB/kmlS+XwigrzVl8ThooJKSVJKiXm2JZ5FsMDNVgw= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM5PR1201MB0076.namprd12.prod.outlook.com (2603:10b6:4:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 12:54:27 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 12:54:27 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v5 18/28] OvmfPkg/SecMain: pre-validate the memory used for decompressing Fv Date: Wed, 30 Jun 2021 07:53:11 -0500 Message-ID: <20210630125321.30278-19-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210630125321.30278-1-brijesh.singh@amd.com> References: <20210630125321.30278-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.14 via Frontend Transport; Wed, 30 Jun 2021 12:54:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3dc3f145-a2f0-4551-6c5c-08d93bc63179 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0076: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 891PfFtdZf1X9/XcblFwH10cUHg8M2Cq0cI1kv7kgGQRMFGuz+lO7OPFMXJ7+vOkwnlkEWm4O3In4vbirumSF6c2iLllkrvjMu3/i2FFne/UI4UCPl52Z2yiSzdZcY48Ge178ibGrpZpVf3BoLL4NiVeYvMBLR0ZbHx2m6Lw/6HCus/Q5aj1EOL5P9qp7THtZKXGjIIGsPN9nD5PdiKvMDw1toP8/NPRDh4a6f1XTqjcJe2nKXwN5Ybb/RRrtTltgx9xe5TcsDcd1jYeMVGu/v554Te8ZM0koQGZixDuTpHbcYKHxcAABZcMvby7Txcm0SkUkPsVTc2Nzdtd/FucPZlbdeRBAlyWkRXwpSS9m3gm2QY872lDPWC6BvY5XN+utGo5+JW/dPiEVsM/8WyKqlI7jNuwbfi/eYWDG82pslS9EcaRHYnuiQcnVGMYHLZmTHZnJ2cV0/YOXVNSHYAN+WjILUL/HUpkkt65fATbxruy+9mgH9sPyNjZto8b7IllX4YOONsQFFzshibD+61BUx4XXZQ6ppg4LZAQXmir5NuCWbhTI52eMn8fRqVF52hvnhd/4Od9GP+BsEqXH0VnyUKdzpNpugG/Htm+rpAjfrz9h57p3lBHHLvn29Z0e2L+cxIp4g/0DAv/BpsY/UUGPmdyCpxtOFSMcaHUgBc7ZhVXbX4nFzr5t1cdmSyy1fIq+2okULc6db3aJDVGbrLwdbHHAC3cOZxioM4Q6OeQDN97q6TKBXD4fMbJ8um5gGbyRtcirOWEk5rFW9hXPgZqumvnup/zmsIwobf9J8SkLw7xjIAR8asBjh/tR1Tldwhn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(346002)(39860400002)(396003)(7696005)(1076003)(8676002)(16526019)(15650500001)(8936002)(6666004)(2616005)(4326008)(956004)(38350700002)(38100700002)(478600001)(186003)(6486002)(19627235002)(66556008)(66476007)(26005)(7416002)(316002)(966005)(86362001)(66946007)(52116002)(36756003)(54906003)(5660300002)(2906002)(6916009)(44832011)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/VUbAqifsGgX1G0krMBk/Q23z5dc2/Of/hv3zjekEpzBHOPghhUqQE1Fu1bh?= =?us-ascii?Q?m+HDKjxCn44q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F?= =?us-ascii?Q?9R6RMoftQU11y5/WWs5GjNjs+d+rkwOF0hCoXSr/gcORQ8XvnY2DGAIi2fko?= =?us-ascii?Q?uBJdzTkq6/FinhUZ7JCas98yIX0auNdq2Eql/9E8vea1tVq+lX2ubRKjbCH2?= =?us-ascii?Q?kxmQD+PfK+21oGVwS+3/WtHS0ALIAloVBB/qHRrEQUPz05fINUbHX9i81Epf?= =?us-ascii?Q?eWHzNEXdnGCIBF/fmaMs3iiqfCu5xKv7I6RaCWCx3N0h6hnOlfq0VZODeB8R?= =?us-ascii?Q?v5zN2az74qr9o+kiScEviogY/e3TZU8L1JCv4Z5olAoqz5tKoLMYaC7Rf8Qx?= =?us-ascii?Q?XaoXgI57cElQ5wVDPx5FnKWP9upQWAQQhyLY1E/ZnmbvHzGJPXlf1Ib7vrdc?= =?us-ascii?Q?TcGiOYX8O1bavUafNNr2JoMv?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dc3f145-a2f0-4551-6c5c-08d93bc63179 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 12:54:27.0179 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YhsEq7xk6ZR4ACVzS2oPjHA/fJSWQBgRhoKOxr0TLKlIrceYqtQcCsLtlhHvn4zeyD7SMJvnlTe0CnDtoLx8Bw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0076 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 5 ++++ .../PeiMemEncryptSevLib.inf | 2 ++ OvmfPkg/Sec/SecMain.inf | 3 +++ .../X64/PeiSnpSystemRamValidate.c | 5 ++++ OvmfPkg/Sec/SecMain.c | 27 +++++++++++++++++++ OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 ++++ 6 files changed, 47 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index d0ec14ca2318..afc559d74335 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -339,6 +339,11 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart|0x0|UIN= T32|0x51 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd|0x0|UINT3= 2|0x52 =20 + ## The range of memory that need to be pre-validated in the SEC phase + # when SEV-SNP is active in the guest VM. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedStart|0|UINT32|0x53 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedEnd|0|UINT32|0x54 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x1= 0 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index f4058911e7b6..2b60920f4b25 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -58,5 +58,7 @@ [FeaturePcd] =20 [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedEnd + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedStart gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 7f78dcee2772..8144b1d115cf 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -50,6 +50,7 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + MemEncryptSevLib CpuExceptionHandlerLib =20 [Ppis] @@ -70,6 +71,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedStart + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedEnd =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index 69ffb79633c4..253d42073907 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -27,6 +27,11 @@ STATIC SNP_PRE_VALIDATED_RANGE mPreValidatedRange[] =3D = { { FixedPcdGet32 (PcdOvmfSnpHypervisorPreValidatedStart), FixedPcdGet32 (PcdOvmfSnpHypervisorPreValidatedEnd) + }, + // This range is pre-validated by the Sec/SecMain.c + { + FixedPcdGet32 (PcdOvmfSnpSecPreValidatedStart), + FixedPcdGet32 (PcdOvmfSnpSecPreValidatedEnd) } }; =20 diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index c10441ddf472..f949a9b0349e 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -915,6 +915,26 @@ SevEsIsEnabled ( return ((SevEsWorkArea !=3D NULL) && (SevEsWorkArea->SevEsEnabled !=3D 0= )); } =20 +/** + Pre-validate System RAM used for decompressing the PEI and DXE firmware v= olumes + when SEV-SNP is active. The PCDs SecPreValidatedStart and SecPreValidated= End are + set in OvmfPkg/FvmainCompactScratchEnd.fdf.inc. + +**/ +STATIC +VOID +SevSnpSecPreValidateSystemRam ( + VOID + ) +{ + PHYSICAL_ADDRESS Start, End; + + Start =3D (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdOvmfSnpSecPreValidatedStar= t); + End =3D (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdOvmfSnpSecPreValidatedEnd); + + MemEncryptSevSnpPreValidateSystemRam (Start, EFI_SIZE_TO_PAGES (End - St= art)); +} + VOID EFIAPI SecCoreStartupWithStack ( @@ -1046,6 +1066,13 @@ SecCoreStartupWithStack ( SecCoreData.BootFirmwareVolumeBase =3D BootFv; SecCoreData.BootFirmwareVolumeSize =3D (UINTN) BootFv->FvLength; =20 + if (SevSnpIsEnabled ()) { + // + // Pre-validate the System RAM used in the SEC Phase + // + SevSnpSecPreValidateSystemRam (); + } + // // 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..b560fb0b8e4f 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.PcdOvmfSnpSecPreValidatedStart =3D $(MEMFD_= BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedEnd =3D $(DECOMP_S= CRATCH_BASE) + $(DECOMP_SCRATCH_SIZE) --=20 2.17.1