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 E90CE740034 for ; Mon, 9 Oct 2023 00:08:09 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=yYaQyn7g0mhs7ZnSAnmfzKb9yVTPRDX3KOOXMMd87Cc=; 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=1696810088; v=1; b=r9QU/Hw7sLJCjHOrTpythf4nshTLt4ZcGq24DxxGYrOVOkWsaZIZfJ9/g6unU02oNkPPPhHD B/d2PLuFBaN3X9wIPcNeOd0eNgItrcmM3BEFwxC200a3iKQ4UXJg0/qYrILjPvHrXvU8wj4vFB2 sSQkoHf1bkAQ2/JVKh9mGuUY= X-Received: by 127.0.0.2 with SMTP id SKpbYY7687511xX8BY4rvNSW; Sun, 08 Oct 2023 17:08:08 -0700 X-Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by mx.groups.io with SMTP id smtpd.web11.50040.1696810083040844663 for ; Sun, 08 Oct 2023 17:08:03 -0700 X-Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1dd1714b9b6so2865428fac.0 for ; Sun, 08 Oct 2023 17:08:02 -0700 (PDT) X-Gm-Message-State: I7glDji5zF7HlpZHHVpX9soIx7686176AA= X-Google-Smtp-Source: AGHT+IFir124ibFLNv3SUBgz/Zow3plW5brOCHdA3zwebVq0mAe/zVygt02EeX5OxLqENu42L87mIQ== X-Received: by 2002:a05:6870:ac29:b0:1dc:8191:8a7 with SMTP id kw41-20020a056870ac2900b001dc819108a7mr17805960oab.36.1696810082207; Sun, 08 Oct 2023 17:08:02 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id t20-20020a62ea14000000b0068fcc7f6b00sm5048320pfh.74.2023.10.08.17.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 17:08:01 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v5 12/28] OvmfPkg: Update PeilessStartupLib to use SetMemoryProtectionsLib Date: Sun, 8 Oct 2023 17:07:24 -0700 Message-ID: <20231009000742.1792-13-taylor.d.beebe@gmail.com> In-Reply-To: <20231009000742.1792-1-taylor.d.beebe@gmail.com> References: <20231009000742.1792-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="r9QU/Hw7"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 (#109417): https://edk2.groups.io/g/devel/message/109417 Mute This Topic: https://groups.io/mt/101843354/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-