From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 0BE5ED80287 for ; Wed, 20 Sep 2023 00:58:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=IaAS9yI9z75CjWv7aWUX9PEnc2bzJMUpmpP73x2W0hY=; 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=1695171497; v=1; b=RnhKBUlsK3OyXQKW4bjeU+nLYF1OXJ6egdvRmBeW1sjXbYWuWkWqQTeihLpVkUDv4g4te5m0 BF79vmNYaYzshJctr9LarmCQozyRRPLB8KkU6dTKMAEoW0qrP4EsBzhBwkQm/TrgtgXxKi9/1Rf t4bZj/YSKR1fjryjFRSwYz/s= X-Received: by 127.0.0.2 with SMTP id Fk1SYY7687511xTCwPX4mtfv; Tue, 19 Sep 2023 17:58:17 -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: vJ6U3Duy53xeQrTXSENuWHyYx7686176AA= 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: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=RnhKBUls; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) 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 #define STACK_SIZE 0x20000 -extern EFI_GUID gEfiNonCcFvGuid; +extern EFI_GUID gEfiNonCcFvGuid; +MEMORY_PROTECTION_SETTINGS mMps = { 0 }; /** Transfers control to DxeCore. @@ -42,6 +44,8 @@ HandOffToDxeCore ( VOID *TopOfStack; UINTN PageTables; + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is enabled. // diff --git a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c b/OvmfPkg/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] = { SIZE_512GB }; +extern MEMORY_PROTECTION_SETTINGS mMps; + BOOLEAN IsSetNxForStack ( VOID @@ -142,7 +145,7 @@ IsNullDetectionEnabled ( VOID ) { - return ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) != 0); + return mMps.Dxe.NullPointerDetection.Enabled; } /** @@ -197,8 +200,8 @@ IsEnableNonExecNeeded ( // Features controlled by Following PCDs need this feature to be enabled. // return (IsSetNxForStack () || - FixedPcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0 || - PcdGet32 (PcdImageProtectionPolicy) != 0); + !IsZeroBuffer (&mMps.Dxe.ExecutionProtection.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE) || + (mMps.Dxe.ImageProtection.ProtectImageFromFv || mMps.Dxe.ImageProtection.ProtectImageFromUnknown)); } /** @@ -241,7 +244,7 @@ ToSplitPageTable ( return TRUE; } - if (FixedPcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { if ((StackBase >= Address) && (StackBase < (Address + Size))) { return TRUE; } @@ -427,7 +430,7 @@ Split2MPageTo4K ( PageTableEntry->Bits.ReadWrite = 1; if ((IsNullDetectionEnabled () && (PhysicalAddress4K == 0)) || - (FixedPcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K == StackBase))) + (mMps.Dxe.CpuStackGuardEnabled && (PhysicalAddress4K == StackBase))) { PageTableEntry->Bits.Present = 0; } else { diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/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 ## SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize -- 2.42.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-