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.64]) by mx.groups.io with SMTP id smtpd.web09.43.1622070714444189231 for ; Wed, 26 May 2021 16:11:54 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=49x3irSV; 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.64, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aQnzrL8t/JUhUX5xzmBv4rcKYQsBHIUluhqLdSW55VeClgsmnftfiCS0oYzkfcsM6vYh022+DoR8hSLfXPAfTE48IjUsXJ68bOSvT7w3AVmH+4heASf+9Ldn3V1MmByQGv5KvT5SZOqVd32wyDUJqnl6QyOsP/vXLNYUIfSxZyvdGDAx73HQfjYXxXr7CT8mCx+8GqYU5jF36vC05XgBIq9kUPuiceoenQTtYMFz47eJV13c9Lhvmwhx5hPjsqsOMsdLJ5Xxt6Yespan94Hnt/MsWsvOpl8rPr0iP0e3slF4nnt5L/KmVZyUAtTzU70Pe2R/y2jgFLKKY5FiornxmA== 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=F8BEfoyDZu5Kwxxt9LS1aYA3Ivg85ehfJKOzeYsHNx4=; b=MdaUSfK/U72Nbl1WIK9+PlLafk/OzWB5kgAYQNBFa0UtYUdO//O6zLtFAmI46GQdQpMir8IcgEe1w9iUX9MFhXdqSeNXf6RNDcNk8wXG2ZjRgShi7b4PnqVm4ENZlE6JwfTHz44Ujk4n7Tv16+AI1jpsUaonZ3PH1XKhS2aHUvph6KvUuZJB5I3IQXEABjbkvFiu6SMHUeZmSIqwwXQl7OlYeqz2pL53Ti2JSR8HH4GjFbEk2lHLjLTAeB75/D0o809MHz0OujSSZwObhe9rbiont2v4dUEPdEgbOzPtb2Zbbcly87KTjQLZoPq8HfE7zoopxbKhBe12Ku1EucgD0g== 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=F8BEfoyDZu5Kwxxt9LS1aYA3Ivg85ehfJKOzeYsHNx4=; b=49x3irSVaEAJ6KJr4uj4ir6qHdcSrl3XDXBRGTHn3CQw1Vh7sRLCIQ0jmO0WSmt1pNAkFrvLdZdAEmbzpHfNyDHEKtUl57L/vMdjy9zKR5BC4VH9Bw3rAVoIULzZixr0vB4LJVodHfjx0g+GD4HNx8IPxvjaFDE+ZVOuhmJiT2M= Authentication-Results: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2782.namprd12.prod.outlook.com (2603:10b6:805:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 26 May 2021 23:11:51 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4150.023; Wed, 26 May 2021 23:11:50 +0000 From: "Brijesh Singh" To: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel Subject: [PATCH RFC v3 16/22] OvmfPkg/SecMain: pre-validate the memory used for decompressing Fv Date: Wed, 26 May 2021 18:11:12 -0500 Message-ID: <20210526231118.12946-17-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526231118.12946-1-brijesh.singh@amd.com> References: <20210526231118.12946-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) 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 SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Wed, 26 May 2021 23:11:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f2b86cc9-b7dd-4e12-d7c9-08d9209ba49b X-MS-TrafficTypeDiagnostic: SN6PR12MB2782: 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: 6E2IXUdVAUgLmZiWdjoTaHkpB7fUxImO+8+Vd5IOC0452IoX0Zxm9C/vFbS4TWNbLn1Bz1Ki3RkGwiCuzAZwuVeU707bd2HURX08riM7D9MReCnGjl629cteRCHYOBqv7fpZkSiH5+aHxPaDiQF2gtZwlvpJihiKqk7ghhC4ZragOIrq4CqVVJWIIFBkC3R93afScqN53PW63LMEk69csVJUEbGhN74Yuf/vzufe1AHBdZ3ie8/QxlNGJOculUnLHlm6czkHZaXv3ZAi/2SIuD3sacwFf5dZfW9H6XgJ94xP6IpWxa3WUYzxwOtb+0AKLn1PzCFBMqGNaP2IA8fk752XJ7qvHji80JPlUHCt2JChzNQLRhLVN3N5P8xCPkUaVEBHhcht4NoW/VOOMJ/QmAeCn3F8JFvk9Bq5rrpbZKOCITRF5+kAm7952/cupn0/YtLH94mQTcereMfVQHlDvE4Kh57M57OxxT7gwfZi91LpnqgTehk1YU81apAHrRmj5ihpWQEpZ96/yrK24/V1m1RuSj/qRJSf7nnZyVLEb3sjNg356BYZ3Pnh/Z0RSiI1+8W/fcPG4s0DAiLJW9PA3aH9MOAA3XTg/jMhlAOdOhperztiYteMMYFOB7irj9xM9Nsag6gzeDgsem2Atgt5UHPWst85m+iu99mPSRftklqGldoI26TPIfKgWFUVMO0hFuhdXYl+WLqj/gU4ZfT017pkqdY3YldS1QvztyhP4wv2kXX8gqeiwmDdwUY/JCZwARiKa3j+EZml5ccU7U6+7SGg4Ba3qZ3XCYk45lzkkjg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(396003)(376002)(136003)(26005)(316002)(5660300002)(8676002)(83380400001)(186003)(38350700002)(16526019)(478600001)(54906003)(36756003)(4326008)(86362001)(6666004)(7416002)(15650500001)(2616005)(110136005)(44832011)(2906002)(52116002)(66476007)(66556008)(7696005)(921005)(19627235002)(6486002)(8936002)(38100700002)(66946007)(1076003)(956004)(966005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?t/a9IPW1AMqEwQtyoYw3b3hapH6ZqpYktkrtSXl+366Zq2H79fNLO9qzXXFf?= =?us-ascii?Q?t9ULe+DW/F2jlsaNUahTl4gJnW3Vv9S629ElX7+ZxvNg6vMV0fujftyxe6rT?= =?us-ascii?Q?Q8U1smFsjoJhknZF6TQboW38ucTlHQy5XnQkMVc6KKHS132G1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b81My1JJ/GrlArEmSKd7fA6ccSJ9j46b?= =?us-ascii?Q?2m3bbmtM+xMs65qzwVGsIhMJrd4tlKPbsyNB9pW8s6BP2OW7nEL19RqJgjOj?= =?us-ascii?Q?r/dbhyh0dzbFVM2rMNnJOOk1TzXbkyp3Iwuym+xikkSX/x+j6QGK1oTPZazw?= =?us-ascii?Q?a5AR5Kw3slf+plxCZlFIIR+6Fxsnw22p6yQbaDQGMyF5vPSZ1nqXoM1sn1hQ?= =?us-ascii?Q?UpTzURt12NHFm7e2AR8Ed80pydN7Z96uv1vnmBSfwAebIAai6g5pmeVXZp0E?= =?us-ascii?Q?esLsOzTk+X6vuC0XhR2atucM?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2b86cc9-b7dd-4e12-d7c9-08d9209ba49b X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 23:11:50.6290 (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: ehKC/sgzFv294GtWOj0eC96wLQ0XZxkkZ8pl6/cl5UaYcMPtwY3zlTdArTJUYIaEsoB+TGJY2qDRcgHB7Nzclw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2782 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 3886d43bd3de..4da2d2de9df0 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -336,6 +336,11 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart|0x0|UIN= T32|0x49 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd|0x0|UINT3= 2|0x50 =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|0x51 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecPreValidatedEnd|0|UINT32|0x52 + [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 faa6891cca79..532574fa3095 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -910,6 +910,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 ( @@ -1041,6 +1061,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