From nobody Sun Feb 8 19:38:13 2026 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+108885+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+108885+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695171502; cv=none; d=zohomail.com; s=zohoarc; b=Xo/DfQLalRbS4FoTWs1dHqio+2gSjAhDJMZQ8MVxo1iblZMBXHTZZgXYevcTV5KeVaUG4M2+9kKWFhGkhyjJyhU/wqGXEYl/NmBSdPj2v7TCSd0ONY+8JA9opv1yZbVN1Ttb8acWMrFCRgBqbK/UMGhUlQi6Wbl0Agi/Xmqn2Ug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695171502; h=Content-Type: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=+qEn/2jBWUUq7uo2sTW659ZcnA8ckgjFjB3yHoTGyM4=; b=U7Ty5CfYb4uCg/OffvwvA4GQV6F5HYQF8jKZhKN2tLaZ3hfQOuA3Powekdlv2seYLtNZl4K7DTtrOCHd4Al1tcuN05sX8kE3h/ngQO9Y5qLFbvpaOaF28X9d462n7xa68gy1R9TSnR64M4sBJQR8CpbxrM7qc4NBdYMty2JOA20= 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+108885+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 1695171502109339.64080602431864; Tue, 19 Sep 2023 17:58:22 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=zcLqPpf8mrNvXEG8tSge3+UfOw1u+7/XwAQuqD+Am78=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1695171501; v=1; b=lGqQHwwTNnE1zmMtT0g9qnQqbnX6XEM7IaCcdFEq95kbfLiilUTaaqD5NyQK5PsiiNyrarkl OFz462Nzbh2GMOtoAy2iCCtPlErCNRp8LUkHI6xjat4zNQemUC5X/eDAJm+5D6jAhNZPVJuWz7M d1p8v1irHromtWoeNtkYCg/c= X-Received: by 127.0.0.2 with SMTP id yQIKYY1788612xqag46F4WZY; Tue, 19 Sep 2023 17:58:21 -0700 X-Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mx.groups.io with SMTP id smtpd.web10.26796.1695171501187767335 for ; Tue, 19 Sep 2023 17:58:21 -0700 X-Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1bf55a81eeaso47479735ad.0 for ; Tue, 19 Sep 2023 17:58:21 -0700 (PDT) X-Gm-Message-State: cOH6lbUtMCmEHCMaZzGn5WEix1787277AA= X-Google-Smtp-Source: AGHT+IGpfdXugHHvI9uix/D15k399k7tW9UFynyQxuc4IGSl7XE1icH0O8gwn+040SIR0bBf0NzWZg== X-Received: by 2002:a17:902:bd8a:b0:1b9:c68f:91a5 with SMTP id q10-20020a170902bd8a00b001b9c68f91a5mr947938pls.6.1695171500424; Tue, 19 Sep 2023 17:58:20 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id 13-20020a170902c24d00b001bb988ac243sm10563576plg.297.2023.09.19.17.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 17:58:20 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Rebecca Cran , Peter Grehan , =?UTF-8?q?Corvin=20K=C3=B6hne?= Subject: [edk2-devel] [PATCH v4 23/28] OvmfPkg: Enable Choosing Memory Protection Profile via QemuCfg Date: Tue, 19 Sep 2023 17:57:46 -0700 Message-ID: <20230920005752.2041-24-taylor.d.beebe@gmail.com> In-Reply-To: <20230920005752.2041-1-taylor.d.beebe@gmail.com> References: <20230920005752.2041-1-taylor.d.beebe@gmail.com> MIME-Version: 1.0 Precedence: Bulk 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,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695171504174100097 Now that the EDK2 tree uses GetMemoryProtectionsLib to query the platform memory protection settings, OvmfPkg can be updated to use QemuCfg to set the entire memory protection profile instead of just SetNxForStack. For example, the following will set the DXE memory protection to the RELEASE preset. -fw_cfg name=3Dopt/org.tianocore/DxeMemoryProtectionProfile,string=3Drelease The following will set the MM memory protection to the RELEASE preset. -fw_cfg name=3Dopt/org.tianocore/MmMemoryProtectionProfile,string=3Drelease For users of Stuart, DXE_MEMORY_PROTECTION_PROFILE=3Drelease and MM_MEMORY_PROTECTION_PROFILE=3Drelease are equivalent to the above examples. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Rebecca Cran Cc: Peter Grehan Cc: Corvin K=C3=B6hne --- OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c | 21 +++++++----- OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c | 13 +------- OvmfPkg/Library/PlatformInitLib/Platform.c | 15 --------- OvmfPkg/PlatformPei/IntelTdx.c | 2 -- OvmfPkg/PlatformPei/Platform.c | 35 ++++++++-----= ------- OvmfPkg/TdxDxe/TdxDxe.c | 7 ++-- OvmfPkg/Include/Library/PlatformInitLib.h | 13 -------- OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf | 2 +- OvmfPkg/PlatformCI/PlatformBuildLib.py | 8 +++++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 10 files changed, 39 insertions(+), 78 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index cf645aad3246..2f8fd51f3fc5 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -109,18 +109,23 @@ InitializePlatform ( =20 PlatformMemMapInitialization (PlatformInfoHob); =20 - DxeSettings =3D DxeMemoryProtectionProfi= les[DxeMemoryProtectionSettingsPcd].Settings; - MmSettings =3D MmMemoryProtectionProfil= es[MmMemoryProtectionSettingsPcd].Settings; - DxeSettings.StackExecutionProtectionEnabled =3D PcdGetBool (PcdSetNxForS= tack); - QemuFwCfgParseBool ("opt/ovmf/PcdSetNxForStack", &DxeSettings.StackExecu= tionProtectionEnabled); + if (EFI_ERROR (ParseFwCfgDxeMemoryProtectionSettings (&DxeSettings))) { + DxeSettings =3D DxeMemoryProtectionProfiles[DxeMemoryProtectionSetting= sRelease].Settings; + } =20 - SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); - SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); + if (EFI_ERROR (ParseFwCfgMmMemoryProtectionSettings (&MmSettings))) { + MmSettings =3D MmMemoryProtectionProfiles[MmMemoryProtectionSettingsOf= f].Settings; + } + + // Always disable NullPointerDetection in EndOfDxe phase for shim compat= ability + DxeSettings.NullPointerDetection.DisableEndOfDxe =3D TRUE; + + SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sRelease); + SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsOf= f); =20 if (TdIsEnabled ()) { PlatformInfoHob->PcdConfidentialComputingGuestAttr =3D CCAttrIntelTdx; PlatformInfoHob->PcdTdxSharedBitMask =3D TdSharedPageMas= k (); - PlatformInfoHob->PcdSetNxForStack =3D TRUE; } =20 PlatformMiscInitialization (PlatformInfoHob); diff --git a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c b/OvmfPk= g/Library/PeilessStartupLib/X64/VirtualMemory.c index 41521e3d3d71..7ae9b5743810 100644 --- a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c @@ -53,18 +53,7 @@ IsSetNxForStack ( VOID ) { - EFI_HOB_GUID_TYPE *GuidHob; - EFI_HOB_PLATFORM_INFO *PlatformInfo; - - GuidHob =3D GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid); - if (GuidHob =3D=3D NULL) { - ASSERT (FALSE); - return FALSE; - } - - PlatformInfo =3D (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob); - - return PlatformInfo->PcdSetNxForStack; + return mMps.Dxe.StackExecutionProtectionEnabled; } =20 /** diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index f48bf16ae300..bc9becc4016e 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -249,21 +249,6 @@ PlatformMemMapInitialization ( PlatformInfoHob->PcdPciIoSize =3D PciIoSize; } =20 -/** - * Fetch "opt/ovmf/PcdSetNxForStack" from QEMU - * - * @param Setting The pointer to the setting of "/opt/ovmf/PcdSetNxFor= Stack". - * @return EFI_SUCCESS Successfully fetch the settings. - */ -EFI_STATUS -EFIAPI -PlatformNoexecDxeInitialization ( - IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob - ) -{ - return QemuFwCfgParseBool ("opt/ovmf/PcdSetNxForStack", &PlatformInfoHob= ->PcdSetNxForStack); -} - VOID PciExBarInitialization ( VOID diff --git a/OvmfPkg/PlatformPei/IntelTdx.c b/OvmfPkg/PlatformPei/IntelTdx.c index 3d625cabd844..1cb6729e56e6 100644 --- a/OvmfPkg/PlatformPei/IntelTdx.c +++ b/OvmfPkg/PlatformPei/IntelTdx.c @@ -48,7 +48,5 @@ IntelTdxInitialize ( PcdStatus =3D PcdSet64S (PcdTdxSharedBitMask, TdSharedPageMask ()); ASSERT_RETURN_ERROR (PcdStatus); =20 - PcdStatus =3D PcdSetBoolS (PcdSetNxForStack, TRUE); - ASSERT_RETURN_ERROR (PcdStatus); #endif } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index bcd8d3a1be14..0df1277f34c4 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -39,6 +39,7 @@ #include #include #include +#include =20 #include "Platform.h" =20 @@ -74,21 +75,6 @@ MemMapInitialization ( ASSERT_RETURN_ERROR (PcdStatus); } =20 -STATIC -VOID -NoexecDxeInitialization ( - IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob - ) -{ - RETURN_STATUS Status; - - Status =3D PlatformNoexecDxeInitialization (PlatformInfoHob); - if (!RETURN_ERROR (Status)) { - Status =3D PcdSetBoolS (PcdSetNxForStack, PlatformInfoHob->PcdSetNxFor= Stack); - ASSERT_RETURN_ERROR (Status); - } -} - static const UINT8 EmptyFdt[] =3D { 0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x48, @@ -345,13 +331,19 @@ InitializePlatform ( =20 PublishPeiMemory (PlatformInfoHob); =20 - DxeSettings =3D DxeMemoryProtectionProfi= les[DxeMemoryProtectionSettingsPcd].Settings; - MmSettings =3D MmMemoryProtectionProfil= es[MmMemoryProtectionSettingsPcd].Settings; - DxeSettings.StackExecutionProtectionEnabled =3D PcdGetBool (PcdSetNxForS= tack); - QemuFwCfgParseBool ("opt/ovmf/PcdSetNxForStack", &DxeSettings.StackExecu= tionProtectionEnabled); + if (EFI_ERROR (ParseFwCfgDxeMemoryProtectionSettings (&DxeSettings))) { + DxeSettings =3D DxeMemoryProtectionProfiles[DxeMemoryProtectionSetting= sRelease].Settings; + } =20 - SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); - SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); + if (EFI_ERROR (ParseFwCfgMmMemoryProtectionSettings (&MmSettings))) { + MmSettings =3D MmMemoryProtectionProfiles[MmMemoryProtectionSettingsOf= f].Settings; + } + + // Always disable NullPointerDetection in EndOfDxe phase for shim compat= ability + DxeSettings.NullPointerDetection.DisableEndOfDxe =3D TRUE; + + SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sRelease); + SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsOf= f); =20 PlatformQemuUc32BaseInitialization (PlatformInfoHob); =20 @@ -365,7 +357,6 @@ InitializePlatform ( PeiFvInitialization (PlatformInfoHob); MemTypeInfoInitialization (PlatformInfoHob); MemMapInitialization (PlatformInfoHob); - NoexecDxeInitialization (PlatformInfoHob); } =20 InstallClearCacheCallback (); diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c index 30732f421bb6..5e497ba66227 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.c +++ b/OvmfPkg/TdxDxe/TdxDxe.c @@ -131,15 +131,12 @@ SetPcdSettings ( =20 PcdStatus =3D PcdSet64S (PcdConfidentialComputingGuestAttr, PlatformInfo= Hob->PcdConfidentialComputingGuestAttr); ASSERT_RETURN_ERROR (PcdStatus); - PcdStatus =3D PcdSetBoolS (PcdSetNxForStack, PlatformInfoHob->PcdSetNxFo= rStack); - ASSERT_RETURN_ERROR (PcdStatus); =20 DEBUG (( DEBUG_INFO, - "HostBridgeDevId=3D0x%x, CCAttr=3D0x%x, SetNxForStack=3D%x\n", + "HostBridgeDevId=3D0x%x, CCAttr=3D0x%x\n", PlatformInfoHob->HostBridgeDevId, - PlatformInfoHob->PcdConfidentialComputingGuestAttr, - PlatformInfoHob->PcdSetNxForStack + PlatformInfoHob->PcdConfidentialComputingGuestAttr )); =20 PcdStatus =3D PcdSet32S (PcdCpuBootLogicalProcessorNumber, PlatformInfoH= ob->PcdCpuBootLogicalProcessorNumber); diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index 57b18b94d9b8..b2468f206321 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -32,7 +32,6 @@ typedef struct { UINT32 Uc32Base; UINT32 Uc32Size; =20 - BOOLEAN PcdSetNxForStack; UINT64 PcdTdxSharedBitMask; =20 UINT64 PcdPciMmio64Base; @@ -182,18 +181,6 @@ PlatformMemMapInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); =20 -/** - * Fetch "opt/ovmf/PcdSetNxForStack" from QEMU - * - * @param Setting The pointer to the setting of "/opt/ovmf/PcdSetNxFor= Stack". - * @return EFI_SUCCESS Successfully fetch the settings. - */ -EFI_STATUS -EFIAPI -PlatformNoexecDxeInitialization ( - IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob - ); - VOID EFIAPI PlatformMiscInitialization ( diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index 47bd42d23d11..a6d7b53f52cf 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -57,7 +57,7 @@ [LibraryClasses] QemuFwCfgLib PlatformInitLib SetMemoryProtectionsLib - QemuFwCfgSimpleParserLib + MemoryProtectionConfigLib =20 [Guids] gEfiHobMemoryAllocModuleGuid diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/Pl= atformBuildLib.py index f829738cdda4..0d5d39c078d0 100644 --- a/OvmfPkg/PlatformCI/PlatformBuildLib.py +++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py @@ -183,6 +183,8 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManage= r): VirtualDrive =3D os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE= "), "VirtualDrive") os.makedirs(VirtualDrive, exist_ok=3DTrue) OutputPath_FV =3D os.path.join(self.env.GetValue("BUILD_OUTPUT_BAS= E"), "FV") + DxeMemoryProtection =3D self.env.GetValue("DXE_MEMORY_PROTECTION_P= ROFILE", "") + MmMemoryProtection =3D self.env.GetValue("MM_MEMORY_PROTECTION_PRO= FILE", "") =20 if (self.env.GetValue("QEMU_SKIP") and self.env.GetValue("QEMU_SKIP").upper() =3D=3D "TRUE"): @@ -199,6 +201,12 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManag= er): args +=3D " -smp 4" args +=3D f" -drive file=3Dfat:rw:{VirtualDrive},format=3Draw,medi= a=3Ddisk" # Mount disk with startup.nsh =20 + if (DxeMemoryProtection.lower() !=3D ""): + args +=3D " -fw_cfg name=3Dopt/org.tianocore/DxeMemoryProtecti= onProfile,string=3D" + DxeMemoryProtection.lower() + + if (MmMemoryProtection.lower() !=3D ""): + args +=3D " -fw_cfg name=3Dopt/org.tianocore/MmMemoryProtectio= nProfile,string=3D" + MmMemoryProtection.lower() + if (self.env.GetValue("QEMU_HEADLESS").upper() =3D=3D "TRUE"): args +=3D " -display none" # no graphics =20 diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 6b8442d12b2c..fbaa6bdc8ee5 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -66,6 +66,7 @@ [LibraryClasses] CcExitLib PlatformInitLib SetMemoryProtectionsLib + MemoryProtectionConfigLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase --=20 2.42.0.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 (#108885): https://edk2.groups.io/g/devel/message/108885 Mute This Topic: https://groups.io/mt/101469963/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-