From nobody Sun Feb 8 19:38:14 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+108874+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+108874+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695171495; cv=none; d=zohomail.com; s=zohoarc; b=Ipaca78rkpLO6AgWeHZLsbqVPxIiVFqx1E5w/7aMm3HXUI8IPklh7w41SD+i7SeYERySeVTUtr6ysbTG9Qa+CwuM26EP4o5jKwkbavfKeSD9nhJ7MRcWQi+8azRMrm4u1srSXTHe0UUmSMXY/yTCw1hWUJAPB9jCnY6GucTCkXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695171495; 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=B2JJieSbPJXvZHPDpgNj+mQ5TzQLHtIxB8y0z0Nl2PE=; b=Lhved79cKdgupVAFPlSfUTuNyBOe+RHVprwqiJw2dcSnayYe3kUYSJdugQWEXDXET88OX4GUVq284xYe2r0JHKJJdP1vO7SiGFBGXHcvl1WDzq6L7AHXdM1MKPOzXYK69xq8JX8kDTQsy02kmDhY06qgKpMwGyzI76t2fe2nEKY= 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+108874+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 1695171495284377.53694173530573; Tue, 19 Sep 2023 17:58:15 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=8NZ9i/oY7YWNTncqp8JV9GZMJBq2RpNpAE3MVYyFhrA=; 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-Transfer-Encoding; s=20140610; t=1695171495; v=1; b=qC5I9A85UaepF2AqGXOVE6z9EI8ddkIueiGbQ0WqmP7McxOjHTwf5pUFxOUTl4/Ehg5YVPce D9tdUhYMOwEE62J9GS3u0piGS9Tq5CUgiMMmPPqQ8wK9gEAMm6P2he+AztXODpTGXW9Ap0+2doR kG/0mzlM8tlKNeoW5B5d7bBc= X-Received: by 127.0.0.2 with SMTP id DWntYY1788612xZuXMYaBJYt; Tue, 19 Sep 2023 17:58:15 -0700 X-Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mx.groups.io with SMTP id smtpd.web10.26784.1695171494219632644 for ; Tue, 19 Sep 2023 17:58:14 -0700 X-Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-578a44dfa88so1412403a12.0 for ; Tue, 19 Sep 2023 17:58:14 -0700 (PDT) X-Gm-Message-State: p200dpvIk22yA2uWzh5MDxJPx1787277AA= X-Google-Smtp-Source: AGHT+IFaVdLcCbubNxUgvl0tM0FytTmkeqYjNtduabEefONgdWA6e9UBFjxwD5UIuIhLOK2vqqt1qw== X-Received: by 2002:a05:6a21:3e05:b0:14b:ecab:a6ba with SMTP id bk5-20020a056a213e0500b0014becaba6bamr1082286pzc.28.1695171493325; Tue, 19 Sep 2023 17:58:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 17:58:12 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v4 12/28] OvmfPkg: Update PeilessStartupLib to use SetMemoryProtectionsLib Date: Tue, 19 Sep 2023 17:57:35 -0700 Message-ID: <20230920005752.2041-13-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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695171496062100050 Content-Type: text/plain; charset="utf-8" This patch updates the DXE Handoff in PEI-less Startup to use SetMemoryProtectionsLib to get the platform memory protection settings and build the page tables based on the applied protections. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann --- OvmfPkg/Library/PeilessStartupLib/DxeLoad.c | 6 +++++- OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c | 13 ++++++++----- OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf | 4 ---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c b/OvmfPkg/Library/= PeilessStartupLib/DxeLoad.c index d34690eb8a0b..f8ff53876369 100644 --- a/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c +++ b/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c @@ -20,9 +20,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include "X64/PageTables.h" #include +#include =20 #define STACK_SIZE 0x20000 -extern EFI_GUID gEfiNonCcFvGuid; +extern EFI_GUID gEfiNonCcFvGuid; +MEMORY_PROTECTION_SETTINGS mMps =3D { 0 }; =20 /** Transfers control to DxeCore. @@ -42,6 +44,8 @@ HandOffToDxeCore ( VOID *TopOfStack; UINTN PageTables; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // diff --git a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c b/OvmfPk= g/Library/PeilessStartupLib/X64/VirtualMemory.c index e2c1bac5e059..41521e3d3d71 100644 --- a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c @@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include "PageTables.h" @@ -45,6 +46,8 @@ UINT64 mLevelSize[5] =3D { SIZE_512GB }; =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + BOOLEAN IsSetNxForStack ( VOID @@ -142,7 +145,7 @@ IsNullDetectionEnabled ( VOID ) { - return ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) !=3D 0); + return mMps.Dxe.NullPointerDetection.Enabled; } =20 /** @@ -197,8 +200,8 @@ IsEnableNonExecNeeded ( // Features controlled by Following PCDs need this feature to be enabled. // return (IsSetNxForStack () || - FixedPcdGet64 (PcdDxeNxMemoryProtectionPolicy) !=3D 0 || - PcdGet32 (PcdImageProtectionPolicy) !=3D 0); + !IsZeroBuffer (&mMps.Dxe.ExecutionProtection.EnabledForType, MPS= _MEMORY_TYPE_BUFFER_SIZE) || + (mMps.Dxe.ImageProtection.ProtectImageFromFv || mMps.Dxe.ImagePr= otection.ProtectImageFromUnknown)); } =20 /** @@ -241,7 +244,7 @@ ToSplitPageTable ( return TRUE; } =20 - if (FixedPcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { if ((StackBase >=3D Address) && (StackBase < (Address + Size))) { return TRUE; } @@ -427,7 +430,7 @@ Split2MPageTo4K ( PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && (PhysicalAddress4K =3D=3D 0)) || - (FixedPcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K =3D=3D S= tackBase))) + (mMps.Dxe.CpuStackGuardEnabled && (PhysicalAddress4K =3D=3D StackB= ase))) { PageTableEntry->Bits.Present =3D 0; } else { diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index f0a8a5a56df4..47bd42d23d11 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -77,12 +77,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ##= CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize --=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 (#108874): https://edk2.groups.io/g/devel/message/108874 Mute This Topic: https://groups.io/mt/101469950/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-