From nobody Sat May 11 07:38:29 2024 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+108155+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+108155+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437545; cv=none; d=zohomail.com; s=zohoarc; b=jZ1zLbak09YQPyGLTF89IPFKHNPQGpqi/Mqeqs6o3MF11NMZuFFyKucoS8KVDt1tSP8URrrv0tUZCmZ7wirYShAnhPyibMw8lOsb7824QxOignbbuTelsrydDOh6WZLWaQZ7AENBMNrxKGhYySgcqfiyAe5UUHLmUcn4Igc1VRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437545; 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=EfK8k+qWad5HEuewt0/djWfnjvqtSNAQWybC9bA/SEk=; b=jMrE3uRd45hAcbNHPFZKlGxS8LhsXxQ0PFyYWzqRqTdQWtR/fWpBwTX1GiL5TOesMnPCTsPt7j6QDB8Vwvq0HN6p24Oc+lcD3evVGr6jrT3j8mOs406tX4t0Kdl3HyX9XGI5zwHXMNB+rX24how8cPFjbXp6AuRqw61tXW4YrqQ= 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+108155+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 1693437545290844.4551374083615; Wed, 30 Aug 2023 16:19:05 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=3jUk7kVmA/UjTz2DRupyXKr1Y4XMkEpu+97qTKiUMxY=; 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=1693437544; v=1; b=dv/ou2k/I/gwKUtbP2AQtB9Qy8Rh9pHJCeaLjaaP2gY2xKYD3Lbp3mVKQzhkw/y7lXhlEY+S 7If72M2Tzns+rmiSEV4xjBmTvrSuAfxEaA1lUevPgC3xrhlYBhQSGEdqDiZXu9F576s0Ug+dPrE FLwz0orwfrEUi91IFT3WIEZE= X-Received: by 127.0.0.2 with SMTP id boFrYY1788612xW9pbflU5L6; Wed, 30 Aug 2023 16:19:04 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web11.4941.1693437544377454769 for ; Wed, 30 Aug 2023 16:19:04 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a42d06d02so173395b3a.0 for ; Wed, 30 Aug 2023 16:19:04 -0700 (PDT) X-Gm-Message-State: lFHhcxKmWLcdFB8V5h1JNUIBx1787277AA= X-Google-Smtp-Source: AGHT+IFqKIG98THMHtNBBxcanQEcE67PNVekiAqpOhltS5SmmU4EXDJspOtKm2WXew4LSN1sW4QgGg== X-Received: by 2002:a05:6a00:1949:b0:68b:eaad:6c3b with SMTP id s9-20020a056a00194900b0068beaad6c3bmr4281966pfk.23.1693437543499; Wed, 30 Aug 2023 16:19:03 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:03 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 01/26] MdeModulePkg: Add DXE and MM Memory Protection Settings Definitions Date: Wed, 30 Aug 2023 16:18:09 -0700 Message-ID: <20230830231851.779-2-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437545789100003 Content-Type: text/plain; charset="utf-8" These headers provide settings definitions for memory protections, settings profiles for easily enabling memory protections, and the GUIDs used for producing the memory protection HOB entry. The settings options are functionally 1:1 with the existing PCD bitfield definitions. Instead of setting a fixed at build PCD, memory protections will be set via a HOB at runtime. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Include/Guid/MemoryProtectionSettings.h | 216 +++++++++++++++= +++++ MdeModulePkg/MdeModulePkg.dec | 5 + 2 files changed, 221 insertions(+) diff --git a/MdeModulePkg/Include/Guid/MemoryProtectionSettings.h b/MdeModu= lePkg/Include/Guid/MemoryProtectionSettings.h new file mode 100644 index 000000000000..889e87011fbf --- /dev/null +++ b/MdeModulePkg/Include/Guid/MemoryProtectionSettings.h @@ -0,0 +1,216 @@ +/** @file +Defines memory protection settings guid and struct for DXE and MM. + +Copyright (C) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MEMORY_PROTECTION_SETTINGS_H_ +#define MEMORY_PROTECTION_SETTINGS_H_ + +#define OEM_RESERVED_MPS_MEMORY_TYPE EfiMaxMemoryType +#define OS_RESERVED_MPS_MEMORY_TYPE (EfiMaxMemoryType + 1) +#define MAX_MPS_MEMORY_TYPE (EfiMaxMemoryType + 2) +#define MPS_MEMORY_TYPE_BUFFER_SIZE (MAX_MPS_MEMORY_TYPE * sizeof (BOOLE= AN)) + +// Current DXE iteration of MEMORY_PROTECTION_SETTINGS +#define DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION 1 + +// Current MM iteration of MEMORY_PROTECTION_SETTINGS +#define MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION 1 + +#define DXE_MEMORY_PROTECTION_SIGNATURE SIGNATURE_32('D', 'M', 'P', 'S') +#define MM_MEMORY_PROTECTION_SIGNATURE SIGNATURE_32('M', 'M', 'P', 'S') + +typedef UINT8 MEMORY_PROTECTION_SETTINGS_VERSION; +typedef UINT32 MEMORY_PROTECTION_SETTINGS_SIGNATURE; + +typedef struct { + BOOLEAN Enabled : 1; + BOOLEAN DisableEndOfDxe : 1; + BOOLEAN NonstopModeEnabled : 1; +} DXE_NULL_DETECTION_POLICY; + +typedef struct { + BOOLEAN ProtectImageFromUnknown : 1; + BOOLEAN ProtectImageFromFv : 1; +} DXE_IMAGE_PROTECTION_POLICY; + +typedef struct { + BOOLEAN PageGuardEnabled : 1; + BOOLEAN PoolGuardEnabled : 1; + BOOLEAN FreedMemoryGuardEnabled : 1; + BOOLEAN NonstopModeEnabled : 1; + BOOLEAN GuardAlignedToTail : 1; +} DXE_HEAP_GUARD_POLICY; + +typedef struct { + BOOLEAN Enabled : 1; + BOOLEAN NonstopModeEnabled : 1; +} MM_NULL_DETECTION_POLICY; + +typedef struct { + BOOLEAN PageGuardEnabled : 1; + BOOLEAN PoolGuardEnabled : 1; + BOOLEAN NonstopModeEnabled : 1; + BOOLEAN GuardAlignedToTail : 1; +} MM_HEAP_GUARD_POLICY; + +typedef struct { + BOOLEAN EnabledForType[MAX_MPS_MEMORY_TYPE]; +} MPS_MEMORY_TYPES; + +// +// Memory Protection Settings struct +// +typedef struct { + // This signature is used to identify the memory protection settings str= ucture. + MEMORY_PROTECTION_SETTINGS_SIGNATURE Signature; + + // The current version of the structure definition. This is used to ensu= re there isn't a + // definition mismatch if modules have differing iterations of this head= er. When creating + // this struct, use the DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION m= acro. + MEMORY_PROTECTION_SETTINGS_VERSION StructVersion; + + // If enabled, the page at the top of the stack will be invalidated to c= atch stack overflow. + BOOLEAN CpuStackGuardEnabled; + + // If enabled, the stack will be marked non-executable. + BOOLEAN StackExecutionProtectionEnabled; + + // If enabled, accessing the NULL address in UEFI will be caught by mark= ing + // the NULL page as not present. + // .NullDetectionEnabled : Enable NULL pointer detection. + // .DisableEndOfDxe : Disable NULL pointer detection just afte= r EndOfDxe. + // This is a workaround for those unsolvabl= e NULL access issues in + // OptionROM, boot loader, etc. It can also= help to avoid unnecessary + // exception caused by legacy memory (0-409= 5) access after EndOfDxe, + // such as Windows 7 boot on Qemu. + // .NonstopModeEnabled : If enabled the debug flag will be raised= when a fault occurs + // to break into debugger. + DXE_NULL_DETECTION_POLICY NullPointerDetection; + + // Set image protection policy. + // + // .ProtectImageFromUnknown : If set, images from unknown devi= ces will be protected by + // DxeCore if they are aligned. The= code section becomes + // read-only, and the data section = becomes non-executable. + // .ProtectImageFromFv : If set, images from firmware vol= umes will be protected by + // DxeCore if they are aligned. The= code section becomes + // read-only, and the data section = becomes non-executable. + DXE_IMAGE_PROTECTION_POLICY ImageProtection; + + // If a bit is set, memory regions of the associated type will be mapped= non-executable. + // + // The execution protection setting for EfiBootServicesData and EfiConve= ntionalMemory must + // be the same. + MPS_MEMORY_TYPES ExecutionProtection; + + // Configures general heap guard behavior. + // + // .PageGuardEnabled : Enable page guard. + // .PoolGuardEnabled : Enable pool guard. + // .FreedMemoryGuardEnabled : Enable freed-memory guard (Use-After-Fre= e memory detection). + // .NonstopModeEnabled : If enabled the debug flag will be raised= when a fault occurs + // to break into debugger. + // .GuardAlignedToTail : TRUE if the pool is aligned to tail guar= d page. If FALSE, the + // pool is aligned to head guard page. + // + // Note: + // a) Due to the limit of pool memory implementation and the alignment + // requirement of UEFI spec, HeapGuard.GuardAlignedToTail is a try-b= est + // setting which cannot guarantee that the returned pool is exactly + // adjacent to head or tail guard page. + // b) Freed-memory guard and pool/page guard cannot be enabled + // at the same time. + DXE_HEAP_GUARD_POLICY HeapGuard; + + // Indicates which type allocation need guard page. + // + // If bit is set, a head guard page and a tail guard page will be added = just + // before and after corresponding type of pages which the allocated pool= occupies, + // if there's enough free memory for all of them. + // + // These settings are only valid if HeapGuard.PoolGuardEnabled is TRUE. + MPS_MEMORY_TYPES PoolGuard; + + // Indicates which type allocation need guard page. + // + // If a bit is set, a head guard page and a tail guard page will be adde= d just + // before and after corresponding type of pages allocated if there's eno= ugh + // free pages for all of them. + // + // These settings are only valid if HeapGuard.PageGuardEnabled is TRUE. + MPS_MEMORY_TYPES PageGuard; +} DXE_MEMORY_PROTECTION_SETTINGS; + +// +// Memory Protection Settings struct +// +typedef struct { + // This signature is used to identify the memory protection settings str= ucture. + MEMORY_PROTECTION_SETTINGS_SIGNATURE Signature; + + // The current version of the structure definition. This is used to ensu= re there isn't a + // definition mismatch if modules have differing iterations of this head= er. When creating + // this struct, use the MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION ma= cro. + MEMORY_PROTECTION_SETTINGS_VERSION StructVersion; + + // If enabled, accessing the NULL address in MM will be caught by marking + // the NULL page as not present. + // .NullDetectionEnabled : Enable NULL pointer detection. + // .NonstopModeEnabled : If enabled the debug flag will be raised= when a fault occurs + // to break into debugger. + MM_NULL_DETECTION_POLICY NullPointerDetection; + + // Configures general heap guard behavior. + // + // Note: + // a) Due to the limit of pool memory implementation and the alignment + // requirement of UEFI spec, HeapGuard.GuardAlignedToTail is a try-b= est + // setting which cannot guarantee that the returned pool is exactly + // adjacent to head or tail guard page. + // + // .PageGuardEnabled : Enable page guard. + // .PoolGuardEnabled : Enable pool guard. + // .NonstopModeEnabled : If enabled the debug flag will be raise= d when a fault occurs + // to break into debugger. + // .GuardAlignedToTail : TRUE if the pool is aligned to tail gua= rd page. If FALSE, the + // pool is aligned to head guard page. + MM_HEAP_GUARD_POLICY HeapGuard; + + // Indicates which type allocation need guard page. + // + // If bit is set, a head guard page and a tail guard page will be added = just + // before and after corresponding type of pages which the allocated pool= occupies, + // if there's enough free memory for all of them. + // + // These settings are only valid if PoolGuardEnabled is TRUE in HeapGuar= d. + MPS_MEMORY_TYPES PoolGuard; + + // Indicates which type allocation need guard page. + // + // If a bit is set, a head guard page and a tail guard page will be adde= d just + // before and after corresponding type of pages allocated if there's eno= ugh + // free pages for all of them. + // + // This bitfield is only valid if PageGuardEnabled is TRUE in HeapGuard. + MPS_MEMORY_TYPES PageGuard; +} MM_MEMORY_PROTECTION_SETTINGS; + +typedef struct { + // The memory protection settings in the SMM and Standalone MM environme= nt + MM_MEMORY_PROTECTION_SETTINGS Mm; + // The memory protection settings in the DXE environment + DXE_MEMORY_PROTECTION_SETTINGS Dxe; +} MEMORY_PROTECTION_SETTINGS; + +#define MEMORY_PROTECTION_SETTINGS_GUID \ + { \ + { 0x9ABFD639, 0xD1D0, 0x4EFF, { 0xBD, 0xB6, 0x7E, 0xC4, 0x19, 0x0D, 0x= 17, 0xD5 } } \ + } + +extern GUID gMemoryProtectionSettingsGuid; + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 0ff058b0a9da..624720c7bb40 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -399,6 +399,11 @@ [Guids] ## Include/Guid/EndofS3Resume.h gEdkiiEndOfS3ResumeGuid =3D { 0x96f5296d, 0x05f7, 0x4f3c, {0x84, 0x67, 0= xe4, 0x56, 0x89, 0x0e, 0x0c, 0xb5 } } =20 + ## Memory Protection Settings Guid. Used to create and fetch the memory = protection settings HOB entry. + # + # Include/Guid/MemoryProtectionSettings + gMemoryProtectionSettingsGuid =3D { 0x9ABFD639, 0xD1D0, 0x4EFF, { 0xBD, = 0xB6, 0x7E, 0xC4, 0x19, 0x0D, 0x17, 0xD5 }} + ## Used (similar to Variable Services) to communicate policies to the en= forcement engine. # {DA1B0D11-D1A7-46C4-9DC9-F3714875C6EB} gVarCheckPolicyLibMmiHandlerGuid =3D { 0xda1b0d11, 0xd1a7, 0x46c4, { 0x9= d, 0xc9, 0xf3, 0x71, 0x48, 0x75, 0xc6, 0xeb }} --=20 2.42.0.windows.1 -=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 (#108155): https://edk2.groups.io/g/devel/message/108155 Mute This Topic: https://groups.io/mt/101064072/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- From nobody Sat May 11 07:38:29 2024 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+108156+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+108156+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437546; cv=none; d=zohomail.com; s=zohoarc; b=EDYAH/I5B5tK7SpGtq4Dz6Dw2HH629AXJ4Ttn1wyjrHO3YFVe2Ck6tjjpEVxTQ3KfQEPgEnlRLC6ddMwzA3dorCPPHQ8M9K3kk6uFvA1n6MXbN+fMGUd5r9Ws6n4Pqs5F5csInfSmwDx77O7v0H4r+4evXhUetrN/NzTaS+12ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437546; 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=dAybhmY0flYVrtodWPIV92C727rVaF9La4QVp31jmZs=; b=FIW+Vi115/ZWanf2oM6LI6Cyxm5vfeovMXWftPyiH1ZTabE7iSyitcdIjEkfwWlGxHeb6R7gXHikxrK37q5CF7JOuibZmafv4nNHq9zPS4AJzHAoRsZQZ1m8rO2T3jWeLu0MYxY8SaGV6oc1XkGM5hFkA3i8LAwtS+0vE0CkHH0= 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+108156+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 1693437546281562.9581772441552; Wed, 30 Aug 2023 16:19:06 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=6AdV9u2LWOieGs3dcqG64UQp/TIBETJk7e1vnmkku2s=; 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=1693437545; v=1; b=rpedEnvo11JcViuSwv8UVuTUT2sKh777U3hMLeRIGRRErFtsSMFByCQyBRrHnBIHQN211Lfj weRJD5eHsjpeVFgNQrqlvhzCa7vmrmwQ03yKOuzLnyTwsx8THSDZ3UzdmIR49jvbRziQ3PYdTA/ JUYMUzkqP5aIXwdFuVpDZEvM= X-Received: by 127.0.0.2 with SMTP id AID4YY1788612xN2stewEw5y; Wed, 30 Aug 2023 16:19:05 -0700 X-Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mx.groups.io with SMTP id smtpd.web11.4942.1693437545443788579 for ; Wed, 30 Aug 2023 16:19:05 -0700 X-Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-68a3082c771so125162b3a.0 for ; Wed, 30 Aug 2023 16:19:05 -0700 (PDT) X-Gm-Message-State: P1vOTklewsRnLev2of0kbkFfx1787277AA= X-Google-Smtp-Source: AGHT+IEze8nOLcmSEFfpjhVMAwI+UVtt3/ISbf2XUAAbw0bgLf31v19WB7h8IfTFtHmtKi8+ejD9rg== X-Received: by 2002:a05:6a00:2d16:b0:688:47d5:ede with SMTP id fa22-20020a056a002d1600b0068847d50edemr1543795pfb.6.1693437544513; Wed, 30 Aug 2023 16:19:04 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:03 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 02/26] MdeModulePkg: Define SetMemoryProtectionsLib and GetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:10 -0700 Message-ID: <20230830231851.779-3-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437547830100010 Content-Type: text/plain; charset="utf-8" SetMemoryProtectionsLib is a PEIM which allows platforms to apply memory protection settings to the current boot. GetMemoryProtectionsLib has DXE and MM implementations to allow platforms to query the current memory protection settings via a global variable populated by the library Implementations. The global variable is a union of the MM and DXE settings. the DXE struct is only valid in a DXE module and the MM struct is only valid in an SMM or Stanalone MM module. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Include/Library/GetMemoryProtectionsLib.h | 83 +++++++++++ MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h | 152 +++++++++++++= +++++++ MdeModulePkg/MdeModulePkg.dec | 8 ++ 3 files changed, 243 insertions(+) diff --git a/MdeModulePkg/Include/Library/GetMemoryProtectionsLib.h b/MdeMo= dulePkg/Include/Library/GetMemoryProtectionsLib.h new file mode 100644 index 000000000000..c8f7084e9c80 --- /dev/null +++ b/MdeModulePkg/Include/Library/GetMemoryProtectionsLib.h @@ -0,0 +1,83 @@ +/** @file +Library for accessing the platform memory protection settings. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef GET_MEMORY_PROTECTION_SETTINGS_LIB_H_ +#define GET_MEMORY_PROTECTION_SETTINGS_LIB_H_ + +#include +#include + +#pragma pack(1) + +typedef union { + DXE_MEMORY_PROTECTION_SETTINGS Dxe; + MM_MEMORY_PROTECTION_SETTINGS Mm; +} MEMORY_PROTECTION_SETTINGS_UNION; + +#pragma pack() + +// The global used to access current Memory Protection Settings +extern MEMORY_PROTECTION_SETTINGS_UNION gMps; + +#define MPS_IS_DXE_SIGNATURE_VALID (gMps.Dxe.Signature =3D=3D DXE_MEMORY_= PROTECTION_SIGNATURE) +#define MPS_IS_MM_SIGNATURE_VALID (gMps.Mm.Signature =3D=3D MM_MEMORY_PR= OTECTION_SIGNATURE) + +#define IS_DXE_PAGE_GUARD_ACTIVE (MPS_IS_DXE_SIGNATURE_VALID = && \ + !IsZeroBuffer (&gMps.Dxe.PageGuard.Enabl= edForType, MPS_MEMORY_TYPE_BUFFER_SIZE) && \ + gMps.Dxe.HeapGuard.PageGuardEnabled) + +#define IS_DXE_POOL_GUARD_ACTIVE (MPS_IS_DXE_SIGNATURE_VALID = && \ + !IsZeroBuffer (&gMps.Dxe.PoolGuard.Enabl= edForType, MPS_MEMORY_TYPE_BUFFER_SIZE) && \ + gMps.Dxe.HeapGuard.PoolGuardEnabled) + +#define IS_DXE_EXECUTION_PROTECTION_ACTIVE (MPS_IS_DXE_SIGNATURE_VALID = && \ + !IsZeroBuffer (&gMps.Dxe.Execu= tionProtection.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE)) + +#define IS_DXE_IMAGE_PROTECTION_ACTIVE (MPS_IS_DXE_SIGNATURE_VALID = && \ + (gMps.Dxe.ImageProtection.ProtectI= mageFromFv || \ + gMps.Dxe.ImageProtection.ProtectI= mageFromUnknown)) + +#define IS_DXE_MEMORY_PROTECTION_ACTIVE (MPS_IS_DXE_SIGNATURE_VALID = && \ + (IS_DXE_PAGE_GUARD_ACTIVE = || \ + IS_DXE_POOL_GUARD_ACTIVE = || \ + IS_DXE_EXECUTION_PROTECTION_ACTI= VE || \ + IS_DXE_IMAGE_PROTECTION_ACTIVE = || \ + gMps.Dxe.CpuStackGuardEnabled = || \ + gMps.Dxe.StackExecutionProtectio= nEnabled || \ + gMps.Dxe.NullPointerDetection.En= abled || \ + gMps.Dxe.HeapGuard.FreedMemoryGu= ardEnabled)) + +#define IS_MM_PAGE_GUARD_ACTIVE (MPS_IS_MM_SIGNATURE_VALID = && \ + gMps.Mm.HeapGuard.PageGuardEnabled = && \ + !IsZeroBuffer (&gMps.Mm.PageGuard.Enabl= edForType, MPS_MEMORY_TYPE_BUFFER_SIZE)) + +#define IS_MM_POOL_GUARD_ACTIVE (MPS_IS_MM_SIGNATURE_VALID = && \ + gMps.Mm.HeapGuard.PoolGuardEnabled = && \ + !IsZeroBuffer (&gMps.Mm.PoolGuard.Enable= dForType, MPS_MEMORY_TYPE_BUFFER_SIZE)) + +#define IS_MM_MEMORY_PROTECTION_ACTIVE (MPS_IS_MM_SIGNATURE_VALID = && \ + (IS_MM_PAGE_GUARD_ACTIVE = || \ + IS_MM_POOL_GUARD_ACTIVE = || \ + gMps.Mm.NullPointerDetection.Enab= led)); + +/** + Populates gMps global. This function is invoked by the library construct= or and only needs to be + called if library contructors have not yet been invoked. + + @retval EFI_SUCCESS gMps global was populated. + @retval EFI_NOT_FOUND The gMemoryProtectionSettingsGuid HOB was not = found. + @retval EFI_ABORTED The version number of the DXE or MM memory pro= tection settings was invalid. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +PopulateMpsGlobal ( + VOID + ); + +#endif diff --git a/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h b/MdeMo= dulePkg/Include/Library/SetMemoryProtectionsLib.h new file mode 100644 index 000000000000..023c987c3c7e --- /dev/null +++ b/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h @@ -0,0 +1,152 @@ +/** @file +Library for creating the MM and DXE memory protection HOB entries. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef SET_MEMORY_PROTECTION_SETTINGS_LIB_H_ +#define SET_MEMORY_PROTECTION_SETTINGS_LIB_H_ + +#include + +typedef struct { + CHAR8 *Name; + CHAR8 *Description; + DXE_MEMORY_PROTECTION_SETTINGS Settings; +} DXE_MEMORY_PROTECTION_PROFILES; + +typedef enum { + DxeMemoryProtectionSettingsPcd, + DxeMemoryProtectionSettingsMax +} DXE_MEMORY_PROTECTION_PROFILE_INDEX; + +typedef struct { + CHAR8 *Name; + CHAR8 *Description; + MM_MEMORY_PROTECTION_SETTINGS Settings; +} MM_MEMORY_PROTECTION_PROFILES; + +typedef enum { + MmMemoryProtectionSettingsPcd, + MmMemoryProtectionSettingsMax +} MM_MEMORY_PROTECTION_PROFILE_INDEX; + +extern DXE_MEMORY_PROTECTION_PROFILES DxeMemoryProtectionProfiles[DxeMemo= ryProtectionSettingsMax]; +extern MM_MEMORY_PROTECTION_PROFILES MmMemoryProtectionProfiles[MmMemory= ProtectionSettingsMax]; + +/** + Prevent further changes to the memory protection settings via this + library API. + + @retval EFI_SUCCESS The memory protection settings are locked. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +LockMemoryProtectionSettings ( + VOID + ); + +/** + Sets the DXE memory protection settings. If DxeMps is NULL, the settings= will be set based + on ProfileIndex. + + @param[in] DxeMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if DxeMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input DxeMps was not equal to the version = currently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetDxeMemoryProtectionSettings ( + IN DXE_MEMORY_PROTECTION_SETTINGS *DxeMps OPTIONAL, + IN DXE_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ); + +/** + Sets the MM memory protection HOB entry. If MmMps is NULL, the settings = will be set based + on ProfileIndex. + + @param[in] MmMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if MmMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_OUT_OF_RESOURCES There was insufficient memory to create th= e HOB. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input MmMps was not equal to the version c= urrently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetMmMemoryProtectionSettings ( + IN MM_MEMORY_PROTECTION_SETTINGS *MmMps OPTIONAL, + IN MM_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ); + +/** + Copies the current memory protection settings into the input buffer. + + NOTE: The returned settings may not be the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @param[out] Mps The memory protection settings pointer to populate. + + @retval EFI_SUCCESS The memory protection settings were copied + into the input buffer. + @retval EFI_INVALID_PARAMETER Mps was NULL. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +GetCurrentMemoryProtectionSettings ( + OUT MEMORY_PROTECTION_SETTINGS *Mps + ); + +/** + Returns TRUE any form of DXE memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE DXE Memory protection is active. + @retval FALSE DXE Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsDxeMemoryProtectionActive ( + VOID + ); + +/** + Returns TRUE any form of MM memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE MM Memory protection is active. + @retval FALSE MM Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsMmMemoryProtectionActive ( + VOID + ); + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 624720c7bb40..50c26fedaf6f 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -164,6 +164,14 @@ [LibraryClasses] # VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h =20 + ## @libraryclass Provides a global for consuming memory protection setti= ngs + # + GetMemoryProtectionsLib|Include/Library/GetMemoryProtectionsLib.h + + ## @libraryclass Library for creating the memory protection settings HOB + # + SetMemoryProtectionsLib|Include/Library/SetMemoryProtectionsLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h --=20 2.42.0.windows.1 -=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 (#108156): https://edk2.groups.io/g/devel/message/108156 Mute This Topic: https://groups.io/mt/101064073/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- From nobody Sat May 11 07:38:29 2024 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+108157+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+108157+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437546; cv=none; d=zohomail.com; s=zohoarc; b=hQIoloiCCtlnA/NkffkgKPqzIT8NSWX6nrZ+TBiwHn0/A2KfqQfzVtjfkH4G80idN4OyDZkpwzHaB1VWk8bAoXrmSd1pkebRguq3EJWBl5OEvg7h5UrVg3/tkbqJZ5Zp2K/8v+YkrvNzjaYktcaB6rbl9EWBjLkLEyqaq0QaCkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437546; 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=VAzdnCU9Hvl3G8dTzTADYrxv+mPAC0usZARMphLP24M=; b=QGfLNEGtsv1z0JG2uv4UA6GML310nhSQTTL4m2Bdcr6UBZZk49u9osU+ZNvXC8pEOCCNb2Q+IjHk+KWEGV09DYvsnTGJyqRzQqV3RSH7Fp9DPNpZqzUFxqL9SJn8wG9BWVBRY9PkXYZfvVdw521bt/ya3eyg4E5Ul2J3Ff1Nnbk= 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+108157+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 16934375467940.28193337938876084; Wed, 30 Aug 2023 16:19:06 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=exgQwnJNvsIaBFNaEYcxPlEpnJQWIJuPx2fTSs13LxM=; 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=1693437546; v=1; b=gGAMMyxm7U7i07MreSuVzKe8kUV4Zkk5WSC1pdTvrszPnxOLkp38pSML1QwTvckKTVrd/urQ r4S+eT9seRZ/L8cCoHaN032DB4H2n7h30zPuiNhyr2dpA1m3HQw2Phf1YsrW7GFxUS0kn3Qe1Wg Q4a8bdBqaOhAFdMpO9Tqfs0I= X-Received: by 127.0.0.2 with SMTP id oTGPYY1788612xVLsxp4pVn7; Wed, 30 Aug 2023 16:19:06 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web11.4943.1693437545926988821 for ; Wed, 30 Aug 2023 16:19:06 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-68a1af910e0so150014b3a.2 for ; Wed, 30 Aug 2023 16:19:05 -0700 (PDT) X-Gm-Message-State: Crb4rMbnRSkefdA8bck2wOZDx1787277AA= X-Google-Smtp-Source: AGHT+IFPs9iz2SNtHKFDinVOouA60E6qVLb3+D1cXpsRdRLaBlLz54Ksi36WCrpIV+F941r/Etn9+Q== X-Received: by 2002:a05:6a00:17a6:b0:68a:4dfa:ea63 with SMTP id s38-20020a056a0017a600b0068a4dfaea63mr3919171pfg.19.1693437545043; Wed, 30 Aug 2023 16:19:05 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:04 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 03/26] MdeModulePkg: Add NULL Instances for Get/SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:11 -0700 Message-ID: <20230830231851.779-4-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437547856100011 Content-Type: text/plain; charset="utf-8" The NULL instances for GetMemoryProtectionsLib and SetMemoryProtectionsLib just zero out the memory protections structure effectively disabling memory protections. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibNull.c= | 29 ++++ MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibNull.c= | 144 ++++++++++++++++++++ MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibNull.i= nf | 25 ++++ MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibNull.i= nf | 25 ++++ MdeModulePkg/MdeModulePkg.dsc = | 4 + 5 files changed, 227 insertions(+) diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtecti= onsLibNull.c b/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtec= tionsLibNull.c new file mode 100644 index 000000000000..af341c2c893d --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibN= ull.c @@ -0,0 +1,29 @@ +/** @file +NULL implementation for GetMemoryProtectionsLib + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +MEMORY_PROTECTION_SETTINGS_UNION gMps =3D { 0 }; + +/** + Populates gMps global. This function is invoked by the library construct= or and only needs to be + called if library contructors have not yet been invoked. + + @retval EFI_SUCCESS gMps global was populated. + @retval EFI_NOT_FOUND The gMemoryProtectionSettingsGuid HOB was not = found. + @retval EFI_ABORTED The version number of the DXE or MM memory pro= tection settings was invalid. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +PopulateMpsGlobal ( + VOID + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLibNull.c b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtec= tionsLibNull.c new file mode 100644 index 000000000000..0d3a32d70209 --- /dev/null +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibN= ull.c @@ -0,0 +1,144 @@ +/** @file +Library for setting the memory protection settings for DXE. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +DXE_MEMORY_PROTECTION_PROFILES DxeMemoryProtectionProfiles[DxeMemoryProte= ctionSettingsMax] =3D { 0 }; +MM_MEMORY_PROTECTION_PROFILES MmMemoryProtectionProfiles[MmMemoryProtect= ionSettingsMax] =3D { 0 }; + +/** + Prevent further changes to the memory protection settings via this + library API. + + @retval EFI_SUCCESS The memory protection settings are locked. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +LockMemoryProtectionSettings ( + VOID + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Sets the DXE memory protection settings. If DxeMps is NULL, the settings= will be set based + on ProfileIndex. + + @param[in] DxeMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if DxeMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input DxeMps was not equal to the version = currently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetDxeMemoryProtectionSettings ( + IN DXE_MEMORY_PROTECTION_SETTINGS *DxeMps OPTIONAL, + IN DXE_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Sets the MM memory protection HOB entry. If MmMps is NULL, the settings = will be set based + on ProfileIndex. + + @param[in] MmMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if MmMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_OUT_OF_RESOURCES There was insufficient memory to create th= e HOB. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input MmMps was not equal to the version c= urrently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetMmMemoryProtectionSettings ( + IN MM_MEMORY_PROTECTION_SETTINGS *MmMps OPTIONAL, + IN MM_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Copies the current memory protection settings into the input buffer. + + NOTE: The returned settings may not be the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @param[out] Mps The memory protection settings pointer to populate. + + @retval EFI_SUCCESS The memory protection settings were copied + into the input buffer. + @retval EFI_INVALID_PARAMETER Mps was NULL. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +GetCurrentMemoryProtectionSettings ( + OUT MEMORY_PROTECTION_SETTINGS *Mps + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Returns TRUE any form of DXE memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE DXE Memory protection is active. + @retval FALSE DXE Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsDxeMemoryProtectionActive ( + VOID + ) +{ + return FALSE; +} + +/** + Returns TRUE any form of MM memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE MM Memory protection is active. + @retval FALSE MM Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsMmMemoryProtectionActive ( + VOID + ) +{ + return FALSE; +} diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtecti= onsLibNull.inf b/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProt= ectionsLibNull.inf new file mode 100644 index 000000000000..e7161412d9dc --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibN= ull.inf @@ -0,0 +1,25 @@ +## @file +# NULL implementation for GetMemoryProtectionsLib +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D GetMemoryProtectionsLibNull + FILE_GUID =3D C21A27EE-37DD-4024-8EDA-8BF5088C8CB1 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D GetMemoryProtectionsLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + GetMemoryProtectionsLibNull.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLibNull.inf b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProt= ectionsLibNull.inf new file mode 100644 index 000000000000..fa660abe3b64 --- /dev/null +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibN= ull.inf @@ -0,0 +1,25 @@ +## @file +# Library for setting the memory protection settings for DXE. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SetMemoryProtectionsLibNull + FILE_GUID =3D CBD02C10-1F4B-4374-A7B2-BB2547C08433 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SetMemoryProtectionsLib|SEC PEI_CORE = PEIM + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + SetMemoryProtectionsLibNull.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index db3b5af53795..4932a05079ae 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -106,6 +106,8 @@ [LibraryClasses] MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiComma= ndLibNull.inf + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Get= MemoryProtectionsLibNull.inf + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLibNull.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -231,6 +233,8 @@ [Components] MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf + MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibNull= .inf + MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibNull= .inf MdeModulePkg/Library/PciHostBridgeLibNull/PciHostBridgeLibNull.inf MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTa= bleLib.inf MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf --=20 2.42.0.windows.1 -=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 (#108157): https://edk2.groups.io/g/devel/message/108157 Mute This Topic: https://groups.io/mt/101064075/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- From nobody Sat May 11 07:38:29 2024 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+108158+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+108158+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437548; cv=none; d=zohomail.com; s=zohoarc; b=k5fTPgRIMVKKQaJbHBck2SnsdQsSWwjPNCZQPBxdKp8m2Z1mEHhhmHd+6IuNaQCPcl9PntWMabwJkl9F5tOcNVNGomK7kbabLqNu+EWKNYdSMhNgtHmYyfzRRlOYughu3oLp1SkOaPpa5Rt0uZy3g3fIAzJ9lcfTVcLH492EZQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437548; 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=9NDAFNx5oriv9RQEjdOccDJpxxRkXkWTXsIfcrx+Aus=; b=PLzWdUfEPzoN8887hy+7XpasN+bGRC7Bp+ei0q4eqkex+LWpH7+WRPWbaWaXJZsNaZwx+WP0EMKkq/z0MSc7nDgmOkKdz23qYWe0LFE9sWNM8ErDF9X3hrxe4ngMraMbvpHyy/FzaLhKL7jisAtenerIvrlgN7SZbqlWJAFz4Lc= 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+108158+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 1693437548064661.9402479350424; Wed, 30 Aug 2023 16:19:08 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=RDkR9yDNq6ZTeT8JjLM7aSzxKE7ErcCRhoYWue3KNEc=; 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=1693437547; v=1; b=NeusteWJ2kbB1EeWAReV4Cd7+pzBhbAl9q6SliS6hG8vC7ZtF7F4Zq3SH/iPZvaKgafmy9wU 4T1xZcApZ6DYWsDYBp9OvrbkNFxcH4j/oafxJ6JkZVYlCTA4AsWJNWOCFKjR0AGm8jkJK7MeDUL LAm3mjVHk32D9DtMV59zssIM= X-Received: by 127.0.0.2 with SMTP id 3C4aYY1788612xGDcJJnmZjA; Wed, 30 Aug 2023 16:19:07 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web10.4861.1693437547000658524 for ; Wed, 30 Aug 2023 16:19:07 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68c0d4cc3a4so165275b3a.1 for ; Wed, 30 Aug 2023 16:19:06 -0700 (PDT) X-Gm-Message-State: KWyJtPXLSlXWGpaD3V459Y58x1787277AA= X-Google-Smtp-Source: AGHT+IGvRadp1PB7XIOtBzzc8/Ybx0fngvMm1+VsN5+5PbU2UKJ+3K6ukOIY2KSGBajAHJyiN6nkrQ== X-Received: by 2002:a05:6a00:2302:b0:68b:eb60:c0a4 with SMTP id h2-20020a056a00230200b0068beb60c0a4mr3862840pfh.6.1693437545778; Wed, 30 Aug 2023 16:19:05 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:05 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 04/26] MdeModulePkg: Implement SetMemoryProtectionsLib and GetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:12 -0700 Message-ID: <20230830231851.779-5-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437549750100024 Content-Type: text/plain; charset="utf-8" The SetMemoryProtectionsLib implementation has functionality for setting protections based on a preset profile or a custom DXE/MM profile passed in by the caller. The implementation also supports locking the protections (tracked via an extra boolean stored in the HOB entry) which prevents the protections from being changed by any other SetMemoryProtectionsLib calls. The GetMemoryProtectionsLib implementation populates the gMps global in the library consructor. For cases where the global needs to be accessed before the constructor is called, PopulateMpsGlobal() will manually fill out the gMps global. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProtectionsLib.c = | 158 ++++++ MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtectionsLib.c = | 124 +++++ MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c = | 534 ++++++++++++++++++++ MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProtectionsLib.in= f | 34 ++ MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtectionsLib.inf= | 34 ++ MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.inf = | 48 ++ MdeModulePkg/MdeModulePkg.dsc = | 3 + 7 files changed, 935 insertions(+) diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProte= ctionsLib.c b/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProt= ectionsLib.c new file mode 100644 index 000000000000..c622a7b99f42 --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProtectionsL= ib.c @@ -0,0 +1,158 @@ +/** @file +Library fills out gMps global for accessing the platform memory protection= settings + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include + +MEMORY_PROTECTION_SETTINGS_UNION gMps =3D { 0 }; + +/** + This function checks the memory protection settings for conflicts. + + @param[in] Mps Pointer to the memory protection settings to check. + + @retval EFI_SUCCESS The memory protection settings are consist= ent. + @retval EFI_INVALID_PARAMETER The memory protection settings are not con= sistent. +**/ +STATIC +EFI_STATUS +DxeMemoryProtectionSettingsConsistencyCheck ( + IN MEMORY_PROTECTION_SETTINGS *Mps + ) +{ + if ((Mps->Dxe.HeapGuard.PoolGuardEnabled || Mps->Dxe.HeapGuard.PageGuard= Enabled) && + Mps->Dxe.HeapGuard.FreedMemoryGuardEnabled) + { + DEBUG (( + DEBUG_WARN, + "%a: - HeapGuard.FreedMemoryGuardEnabled and " + "UEFI HeapGuard.PoolGuardEnabled/HeapGuard.PageGuardEnabled " + "cannot be active at the same time. Setting all three to ZERO in " + "the memory protection settings global.\n", + __func__ + )); + ASSERT ( + !(Mps->Dxe.HeapGuard.FreedMemoryGuardEnabled && + (Mps->Dxe.HeapGuard.PoolGuardEnabled || Mps->Dxe.HeapGuard.PageGua= rdEnabled)) + ); + return EFI_INVALID_PARAMETER; + } + + if (!IsZeroBuffer (&Mps->Dxe.PoolGuard, MPS_MEMORY_TYPE_BUFFER_SIZE) && + (!(Mps->Dxe.HeapGuard.PoolGuardEnabled))) + { + DEBUG (( + DEBUG_WARN, + "%a: - PoolGuard protections are active " + "but HeapGuard.PoolGuardEnabled is inactive.\n", + __func__ + )); + } + + if (!IsZeroBuffer (&Mps->Dxe.PageGuard, MPS_MEMORY_TYPE_BUFFER_SIZE) && + (!(Mps->Dxe.HeapGuard.PageGuardEnabled))) + { + DEBUG (( + DEBUG_WARN, + "%a: - PageGuard protections are active " + "but HeapGuard.PageGuardEnabled is inactive\n", + __func__ + )); + } + + if (Mps->Dxe.ExecutionProtection.EnabledForType[EfiBootServicesData] != =3D + Mps->Dxe.ExecutionProtection.EnabledForType[EfiConventionalMemory]) + { + DEBUG (( + DEBUG_WARN, + "%a: - EfiBootServicesData and EfiConventionalMemory must have the s= ame " + "ExecutionProtection value. Setting both to ZERO in the memory prote= ction " + "settings global.\n", + __func__ + )); + ASSERT ( + Mps->Dxe.ExecutionProtection.EnabledForType[EfiBootServicesData] =3D= =3D + Mps->Dxe.ExecutionProtection.EnabledForType[EfiConventionalMemory] + ); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + Populates gMps global. This function is invoked by the library construct= or and only needs to be + called if library contructors have not yet been invoked. + + @retval EFI_SUCCESS gMps global was populated. + @retval EFI_NOT_FOUND The gMemoryProtectionSettingsGuid HOB was not = found. + @retval EFI_ABORTED The version number of the DXE or MM memory pro= tection settings was invalid. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +PopulateMpsGlobal ( + VOID + ) +{ + VOID *Ptr; + MEMORY_PROTECTION_SETTINGS *Mps; + + Ptr =3D GetFirstGuidHob (&gMemoryProtectionSettingsGuid); + + if (Ptr !=3D NULL) { + Mps =3D (MEMORY_PROTECTION_SETTINGS *)GET_GUID_HOB_DATA (Ptr); + if (Mps->Dxe.StructVersion !=3D DXE_MEMORY_PROTECTION_SETTINGS_CURRENT= _VERSION) { + DEBUG (( + DEBUG_ERROR, + "%a: - Version number of the DXE Memory Protection Settings is inv= alid!\n", + __func__ + )); + ASSERT (Mps->Dxe.StructVersion =3D=3D DXE_MEMORY_PROTECTION_SETTINGS= _CURRENT_VERSION); + return EFI_ABORTED; + } else if (Mps->Dxe.Signature !=3D DXE_MEMORY_PROTECTION_SIGNATURE) { + DEBUG (( + DEBUG_ERROR, + "%a: - Signature of the DXE Memory Protection Settings is invalid!= \n", + __func__ + )); + ASSERT (Mps->Dxe.Signature =3D=3D DXE_MEMORY_PROTECTION_SIGNATURE); + return EFI_ABORTED; + } + + if (!EFI_ERROR (DxeMemoryProtectionSettingsConsistencyCheck (Mps))) { + CopyMem (&gMps.Dxe, &Mps->Dxe, sizeof (DXE_MEMORY_PROTECTION_SETTING= S)); + } + } else { + DEBUG (( + DEBUG_WARN, + "%a: - Memory Protection Settings not found!\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** + Library constructor used to populate gMps global. + + @retval EFI_SUCCESS Constructor always returns success; +**/ +EFI_STATUS +EFIAPI +GetDxeMemoryProtectionSettingsConstructor ( + VOID + ) +{ + PopulateMpsGlobal (); + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtec= tionsLib.c b/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtec= tionsLib.c new file mode 100644 index 000000000000..09c289dd8d15 --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtectionsLi= b.c @@ -0,0 +1,124 @@ +/** @file +Library fills out gMps global for accessing the platform memory protection= settings + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include + +MEMORY_PROTECTION_SETTINGS_UNION gMps =3D { 0 }; + +/** + This function checks the memory protection settings for conflicts. + + @param[in] Mps Pointer to the memory protection settings to check. + + @retval EFI_SUCCESS The memory protection settings are consist= ent. + @retval EFI_INVALID_PARAMETER The memory protection settings are not con= sistent. +**/ +STATIC +EFI_STATUS +MmMemoryProtectionSettingsConsistencyCheck ( + IN MEMORY_PROTECTION_SETTINGS *Mps + ) +{ + if (!IsZeroBuffer (&Mps->Mm.PoolGuard, MPS_MEMORY_TYPE_BUFFER_SIZE) && + (!Mps->Mm.HeapGuard.PoolGuardEnabled)) + { + DEBUG (( + DEBUG_WARN, + "%a: - PoolGuard protections are active " + "but HeapGuard.PoolGuardEnabled is inactive.\n", + __func__ + )); + } + + if (!IsZeroBuffer (&Mps->Mm.PageGuard, MPS_MEMORY_TYPE_BUFFER_SIZE) && + (!Mps->Mm.HeapGuard.PageGuardEnabled)) + { + DEBUG (( + DEBUG_WARN, + "%a: - PageGuard protections are active " + "but HeapGuard.PageGuardEnabled is inactive\n", + __func__ + )); + } + + return EFI_SUCCESS; +} + +/** + Populates gMps global. This function is invoked by the library construct= or and only needs to be + called if library contructors have not yet been invoked. + + @retval EFI_SUCCESS gMps global was populated. + @retval EFI_NOT_FOUND The gMemoryProtectionSettingsGuid HOB was not = found. + @retval EFI_ABORTED The version number of the DXE or MM memory pro= tection settings was invalid. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +PopulateMpsGlobal ( + VOID + ) +{ + VOID *Ptr; + MEMORY_PROTECTION_SETTINGS *Mps; + + Ptr =3D GetFirstGuidHob (&gMemoryProtectionSettingsGuid); + + if (Ptr !=3D NULL) { + Mps =3D (MEMORY_PROTECTION_SETTINGS *)GET_GUID_HOB_DATA (Ptr); + + if (Mps->Mm.StructVersion !=3D MM_MEMORY_PROTECTION_SETTINGS_CURRENT_V= ERSION) { + DEBUG (( + DEBUG_ERROR, + "%a: - Version number of the MM Memory Protection Settings is inva= lid!\n", + __func__ + )); + ASSERT (Mps->Mm.StructVersion =3D=3D MM_MEMORY_PROTECTION_SETTINGS_C= URRENT_VERSION); + return EFI_ABORTED; + } else if (Mps->Mm.Signature !=3D MM_MEMORY_PROTECTION_SIGNATURE) { + DEBUG (( + DEBUG_ERROR, + "%a: - Signature of the MM Memory Protection Settings is invalid!\= n", + __func__ + )); + ASSERT (Mps->Mm.Signature =3D=3D MM_MEMORY_PROTECTION_SIGNATURE); + return EFI_ABORTED; + } + + if (!EFI_ERROR (MmMemoryProtectionSettingsConsistencyCheck (Mps))) { + CopyMem (&gMps.Mm, &Mps->Mm, sizeof (MM_MEMORY_PROTECTION_SETTINGS)); + } + } else { + DEBUG (( + DEBUG_WARN, + "%a: - Memory Protection Settings not found!\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** + Library constructor used to populate gMps global. + + @retval EFI_SUCCESS Constructor always returns success; +**/ +EFI_STATUS +EFIAPI +GetMmMemoryProtectionSettingsConstructor ( + VOID + ) +{ + PopulateMpsGlobal (); + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.c b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtection= sLib.c new file mode 100644 index 000000000000..13032ec80fbf --- /dev/null +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c @@ -0,0 +1,534 @@ +/** @file +Library for setting the memory protection settings for DXE. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include + +#pragma pack(1) + +typedef struct { + // Protection settings + MEMORY_PROTECTION_SETTINGS Mps; + // Extra byte for tracking if protection settings have been locked + BOOLEAN MemoryProtectionSettingsLocked; +} MEMORY_PROTECTION_SETTINGS_PRIVATE; + +#pragma pack() + +///////////////////////////// +// DXE PROFILE DEFINITIONS // +///////////////////////////// + +// +// A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec +// +#define DXE_MEMORY_PROTECTION_SETTINGS_PCD = \ +{ = \ + DXE_MEMORY_PROTECTION_SIGNATURE, = \ + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, = \ + FixedPcdGetBool (PcdCpuStackGuard), /* Stack Guard */ = \ + TRUE, /* Stack Execution Protection (MUST = BE POPULATED) */ \ + { /* NULL Pointer Detection */ = \ + .Enabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT0) !=3D 0), \ + .DisableEndOfDxe =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT7) !=3D 0), \ + .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT6) !=3D 0) \ + }, = \ + { /* Image Protection */ = \ + .ProtectImageFromUnknown =3D ((FixedPcdGet32 (PcdImageProtectionPolicy= ) & BIT0) !=3D 0), \ + .ProtectImageFromFv =3D ((FixedPcdGet32 (PcdImageProtectionPolicy= ) & BIT1) !=3D 0) \ + }, = \ + { /* Execution Protection */ = \ + .EnabledForType =3D { = \ + [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiReservedMemoryType) !=3D 0), \ + [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiLoaderCode) !=3D 0), \ + [EfiLoaderData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiLoaderData) !=3D 0), \ + [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiBootServicesCode) !=3D 0), \ + [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiBootServicesData) !=3D 0), \ + [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiRuntimeServicesCode) !=3D 0), \ + [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiRuntimeServicesData) !=3D 0), \ + [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiConventionalMemory) !=3D 0), \ + [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiUnusableMemory) !=3D 0), \ + [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiACPIReclaimMemory) !=3D 0), \ + [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiACPIMemoryNVS) !=3D 0), \ + [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiMemoryMappedIO) !=3D 0), \ + [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiMemoryMappedIOPortSpace) !=3D 0), \ + [EfiPalCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiPalCode) !=3D 0), \ + [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiPersistentMemory) !=3D 0), \ + [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiUnacceptedMemoryType) !=3D 0), \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & BIT62) !=3D 0), \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & BIT63) !=3D 0) \ + } = \ + }, = \ + { /* Heap Guard */ = \ + .PageGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT0) !=3D 0), \ + .PoolGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT1) !=3D 0), \ + .FreedMemoryGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT4) !=3D 0), \ + .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT6) !=3D 0), \ + .GuardAlignedToTail =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT7) =3D=3D 0) \ + }, = \ + { /* Pool Guard */ = \ + .EnabledForType =3D { = \ + [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiReservedMemoryType) !=3D 0), \ + [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderCode) !=3D 0), \ + [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderData) !=3D 0), \ + [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesCode) !=3D 0), \ + [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesData) !=3D 0), \ + [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesCode) !=3D 0), \ + [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesData) !=3D 0), \ + [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiConventionalMemory) !=3D 0), \ + [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnusableMemory) !=3D 0), \ + [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIReclaimMemory) !=3D 0), \ + [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIMemoryNVS) !=3D 0), \ + [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIO) !=3D 0), \ + [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ + [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPalCode) !=3D 0), \ + [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPersistentMemory) !=3D 0), \ + [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnacceptedMemoryType) !=3D 0), \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT62) !=3D 0), \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT63) !=3D 0) \ + } = \ + }, = \ + { /* Page Guard */ = \ + .EnabledForType =3D { = \ + [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiReservedMemoryType) !=3D 0), \ + [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderCode) !=3D 0), \ + [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderData) !=3D 0), \ + [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesCode) !=3D 0), \ + [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesData) !=3D 0), \ + [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesCode) !=3D 0), \ + [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesData) !=3D 0), \ + [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiConventionalMemory) !=3D 0), \ + [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnusableMemory) !=3D 0), \ + [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIReclaimMemory) !=3D 0), \ + [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIMemoryNVS) !=3D 0), \ + [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIO) !=3D 0), \ + [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ + [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPalCode) !=3D 0), \ + [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPersistentMemory) !=3D 0), \ + [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnacceptedMemoryType) !=3D 0), \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT62) !=3D 0), \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT63) !=3D 0) \ + } = \ + } = \ +} + +//////////////////////////// +// MM PROFILE DEFINITIONS // +//////////////////////////// + +// +// A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec +// +#define MM_MEMORY_PROTECTION_SETTINGS_PCD = \ +{ = \ + MM_MEMORY_PROTECTION_SIGNATURE, = \ + MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, = \ + { /* NULL Pointer Detection */ = \ + .Enabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT1) !=3D 0), \ + .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT6) !=3D 0) \ + }, = \ + { /* Heap Guard */ = \ + .PageGuardEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT2) !=3D 0), \ + .PoolGuardEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT3) !=3D 0), \ + .NonstopModeEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT6) !=3D 0), \ + .GuardAlignedToTail =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT7) =3D=3D 0) \ + }, = \ + { /* Pool Guard */ = \ + .EnabledForType =3D { = \ + [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiReservedMemoryType) !=3D 0), \ + [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderCode) !=3D 0), \ + [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderData) !=3D 0), \ + [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesCode) !=3D 0), \ + [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesData) !=3D 0), \ + [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesCode) !=3D 0), \ + [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesData) !=3D 0), \ + [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiConventionalMemory) !=3D 0), \ + [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnusableMemory) !=3D 0), \ + [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIReclaimMemory) !=3D 0), \ + [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIMemoryNVS) !=3D 0), \ + [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIO) !=3D 0), \ + [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ + [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPalCode) !=3D 0), \ + [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPersistentMemory) !=3D 0), \ + [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnacceptedMemoryType) !=3D 0), \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT62) !=3D 0), \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT63) !=3D 0) \ + } = \ + }, = \ + { /* Page Guard */ = \ + .EnabledForType =3D { = \ + [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiReservedMemoryType) !=3D 0), \ + [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderCode) !=3D 0), \ + [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderData) !=3D 0), \ + [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesCode) !=3D 0), \ + [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesData) !=3D 0), \ + [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesCode) !=3D 0), \ + [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesData) !=3D 0), \ + [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiConventionalMemory) !=3D 0), \ + [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnusableMemory) !=3D 0), \ + [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIReclaimMemory) !=3D 0), \ + [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIMemoryNVS) !=3D 0), \ + [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIO) !=3D 0), \ + [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ + [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPalCode) !=3D 0), \ + [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPersistentMemory) !=3D 0), \ + [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnacceptedMemoryType) !=3D 0), \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT62) !=3D 0), \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT63) !=3D 0) \ + } = \ + } = \ +} + +//////////////////////////// +// PROFILE CONFIGURATIONS // +//////////////////////////// + +DXE_MEMORY_PROTECTION_PROFILES DxeMemoryProtectionProfiles[DxeMemoryProte= ctionSettingsMax] =3D { + [DxeMemoryProtectionSettingsPcd] =3D { + .Name =3D "Pcd", + .Description =3D "Memory protection settings from PCDs", + .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PCD + }, +}; + +MM_MEMORY_PROTECTION_PROFILES MmMemoryProtectionProfiles[MmMemoryProtecti= onSettingsMax] =3D { + [MmMemoryProtectionSettingsPcd] =3D { + .Name =3D "Pcd", + .Description =3D "Memory protection settings from PCDs", + .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_PCD + }, +}; + +///////////////////////////////////// +// GET/SET SUPPORT FUNCTIONS // +///////////////////////////////////// + +/** + Gets the memory protection HOB entry. This function will create the entry + if it is not found. + + @retval NULL Unable to create the memory protection HOB entry. + @retval Other Pointer to the memory protection HOB entry. +**/ +STATIC +MEMORY_PROTECTION_SETTINGS_PRIVATE * +GetOrCreateMemoryProtectionSettings ( + VOID + ) +{ + VOID *Ptr; + MEMORY_PROTECTION_SETTINGS_PRIVATE Mpsp; + + Ptr =3D GetFirstGuidHob (&gMemoryProtectionSettingsGuid); + + if (Ptr !=3D NULL) { + return (MEMORY_PROTECTION_SETTINGS_PRIVATE *)GET_GUID_HOB_DATA (Ptr); + } + + ZeroMem (&Mpsp, sizeof (Mpsp)); + Mpsp.Mps.Dxe =3D DxeMemoryProtectionProf= iles[DxeMemoryProtectionSettingsPcd].Settings; + Mpsp.Mps.Mm =3D MmMemoryProtectionProfi= les[MmMemoryProtectionSettingsPcd].Settings; + Mpsp.Mps.Dxe.StackExecutionProtectionEnabled =3D PcdGetBool (PcdSetNxFor= Stack); + + Ptr =3D BuildGuidDataHob ( + &gMemoryProtectionSettingsGuid, + &Mpsp, + sizeof (Mpsp) + ); + + return (MEMORY_PROTECTION_SETTINGS_PRIVATE *)Ptr; +} + +/** + Gets the memory protection HOB entry and checks the version number + to ensure it is compatible with this module. + + @retval NULL Unable to create the memory protection HOB entry. + @retval Other Pointer to the memory protection HOB entry. +**/ +STATIC +MEMORY_PROTECTION_SETTINGS_PRIVATE * +FetchAndCheckMpsp ( + VOID + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D GetOrCreateMemoryProtectionSettings (); + + if (Mpsp =3D=3D NULL) { + return NULL; + } + + if (Mpsp->Mps.Dxe.StructVersion !=3D DXE_MEMORY_PROTECTION_SETTINGS_CURR= ENT_VERSION) { + DEBUG (( + DEBUG_ERROR, + "%a: - Version number of the DXE Memory Protection Settings is inval= id!\n" + "This module was compiled with version %d but the current version is= %d.\n", + __func__, + Mpsp->Mps.Dxe.StructVersion, + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION + )); + ASSERT (Mpsp->Mps.Dxe.StructVersion =3D=3D DXE_MEMORY_PROTECTION_SETTI= NGS_CURRENT_VERSION); + return NULL; + } + + if (Mpsp->Mps.Mm.StructVersion !=3D MM_MEMORY_PROTECTION_SETTINGS_CURREN= T_VERSION) { + DEBUG (( + DEBUG_ERROR, + "%a: - Version number of the MM Memory Protection Settings is invali= d!\n" + "This module was compiled with version %d but the current version is= %d.\n", + __func__, + Mpsp->Mps.Mm.StructVersion, + MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION + )); + ASSERT (Mpsp->Mps.Mm.StructVersion =3D=3D MM_MEMORY_PROTECTION_SETTING= S_CURRENT_VERSION); + return NULL; + } + + return Mpsp; +} + +/** + Prevent further changes to the memory protection settings via this + library API. + + @retval EFI_SUCCESS The memory protection settings are locked. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +LockMemoryProtectionSettings ( + VOID + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return EFI_ABORTED; + } + + Mpsp->MemoryProtectionSettingsLocked =3D TRUE; + + return EFI_SUCCESS; +} + +/** + Sets the DXE memory protection settings. If DxeMps is NULL, the settings= will be set based + on ProfileIndex. + + @param[in] DxeMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if DxeMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input DxeMps was not equal to the version = currently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetDxeMemoryProtectionSettings ( + IN DXE_MEMORY_PROTECTION_SETTINGS *DxeMps OPTIONAL, + IN DXE_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return EFI_ABORTED; + } + + if (Mpsp->MemoryProtectionSettingsLocked) { + return EFI_ACCESS_DENIED; + } + + if (DxeMps =3D=3D NULL) { + if (ProfileIndex >=3D DxeMemoryProtectionSettingsMax) { + return EFI_INVALID_PARAMETER; + } + + DxeMps =3D &DxeMemoryProtectionProfiles[ProfileIndex].Settings; + } else if (DxeMps->StructVersion !=3D Mpsp->Mps.Dxe.StructVersion) { + ASSERT (DxeMps->StructVersion =3D=3D Mpsp->Mps.Dxe.StructVersion); + return EFI_INVALID_PARAMETER; + } + + CopyMem (&Mpsp->Mps.Dxe, DxeMps, sizeof (DXE_MEMORY_PROTECTION_SETTINGS)= ); + return EFI_SUCCESS; +} + +/** + Sets the MM memory protection HOB entry. If MmMps is NULL, the settings = will be set based + on ProfileIndex. + + @param[in] MmMps Pointer to the memory protection settings to pu= blish. If NULL, the + settings will be created based on ProfileIndex. + @param[in] ProfileIndex The index of the memory protection profile to u= se if MmMps is NULL. + + @retval EFI_SUCCESS The memory protection HOB was successfully= created. + @retval EFI_OUT_OF_RESOURCES There was insufficient memory to create th= e HOB. + @retval EFI_INVALID_PARAMETER The ProfileIndex was invalid or the versio= n number of the + input MmMps was not equal to the version c= urrently present + in the settings. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_ACCESS_DENIED The memory protection settings are locked. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +SetMmMemoryProtectionSettings ( + IN MM_MEMORY_PROTECTION_SETTINGS *MmMps OPTIONAL, + IN MM_MEMORY_PROTECTION_PROFILE_INDEX ProfileIndex + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return EFI_ABORTED; + } + + if (Mpsp->MemoryProtectionSettingsLocked) { + return EFI_ACCESS_DENIED; + } + + if (MmMps =3D=3D NULL) { + if (ProfileIndex >=3D MmMemoryProtectionSettingsMax) { + return EFI_INVALID_PARAMETER; + } + + MmMps =3D &MmMemoryProtectionProfiles[ProfileIndex].Settings; + } else if (MmMps->StructVersion !=3D Mpsp->Mps.Mm.StructVersion) { + ASSERT (MmMps->StructVersion =3D=3D Mpsp->Mps.Mm.StructVersion); + return EFI_INVALID_PARAMETER; + } + + CopyMem (&Mpsp->Mps.Mm, MmMps, sizeof (MM_MEMORY_PROTECTION_SETTINGS)); + return EFI_SUCCESS; +} + +/** + Copies the current memory protection settings into the input buffer. + + NOTE: The returned settings may not be the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @param[out] Mps The memory protection settings pointer to populate. + + @retval EFI_SUCCESS The memory protection settings were copied + into the input buffer. + @retval EFI_INVALID_PARAMETER Mps was NULL. + @retval EFI_ABORTED Unable to get/create the memory protection= settings. + @retval EFI_UNSUPPORTED NULL implementation called. +**/ +EFI_STATUS +EFIAPI +GetCurrentMemoryProtectionSettings ( + OUT MEMORY_PROTECTION_SETTINGS *Mps + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + if (Mps =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return EFI_ABORTED; + } + + CopyMem (Mps, &Mpsp->Mps, sizeof (MEMORY_PROTECTION_SETTINGS)); + return EFI_SUCCESS; +} + +/** + Returns TRUE any form of DXE memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE DXE Memory protection is active. + @retval FALSE DXE Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsDxeMemoryProtectionActive ( + VOID + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return FALSE; + } + + return Mpsp->Mps.Dxe.CpuStackGuardEnabled = || + Mpsp->Mps.Dxe.StackExecutionProtectionEnabled = || + Mpsp->Mps.Dxe.NullPointerDetection.Enabled = || + Mpsp->Mps.Dxe.HeapGuard.FreedMemoryGuardEnabled = || + Mpsp->Mps.Dxe.ImageProtection.ProtectImageFromFv = || + Mpsp->Mps.Dxe.ImageProtection.ProtectImageFromUnknown = || + !IsZeroBuffer (&Mpsp->Mps.Dxe.ExecutionProtection.EnabledForType,= MPS_MEMORY_TYPE_BUFFER_SIZE) || + (Mpsp->Mps.Dxe.HeapGuard.PageGuardEnabled && !IsZeroBuffer (&Mpsp= ->Mps.Dxe.PageGuard.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE)) || + (Mpsp->Mps.Dxe.HeapGuard.PoolGuardEnabled && !IsZeroBuffer (&Mpsp= ->Mps.Dxe.PoolGuard.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE)); +} + +/** + Returns TRUE any form of MM memory protection is currently active. + + NOTE: The returned value may reflect the final settings used by the + platform on this boot. Unless LockMemoryProtectionSettings() has + been called, settings may be modified by drivers until DXE handoff. + + @retval TRUE MM Memory protection is active. + @retval FALSE MM Memory protection is not active. +**/ +BOOLEAN +EFIAPI +IsMmMemoryProtectionActive ( + VOID + ) +{ + MEMORY_PROTECTION_SETTINGS_PRIVATE *Mpsp; + + Mpsp =3D FetchAndCheckMpsp (); + + if (Mpsp =3D=3D NULL) { + ASSERT (Mpsp !=3D NULL); + return FALSE; + } + + return Mpsp->Mps.Mm.NullPointerDetection.Enabled = || + (Mpsp->Mps.Mm.HeapGuard.PageGuardEnabled && !IsZeroBuffer (&Mpsp-= >Mps.Mm.PageGuard.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE)) || + (Mpsp->Mps.Dxe.HeapGuard.PoolGuardEnabled && !IsZeroBuffer (&Mpsp= ->Mps.Mm.PoolGuard.EnabledForType, MPS_MEMORY_TYPE_BUFFER_SIZE)); +} diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProte= ctionsLib.inf b/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryPr= otectionsLib.inf new file mode 100644 index 000000000000..b2949a8a5b0b --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProtectionsL= ib.inf @@ -0,0 +1,34 @@ +## @file +# Library fills out gMps global for accessing the platform memory protecti= on settings +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeGetMemoryProtectionsLib + FILE_GUID =3D 723A3FA5-1B77-4E83-8978-C768829F7BE4 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D GetMemoryProtectionsLib|DXE_CORE DXE_= DRIVER UEFI_APPLICATION UEFI_DRIVER + CONSTRUCTOR =3D GetDxeMemoryProtectionSettingsConstru= ctor + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + DxeGetMemoryProtectionsLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + HobLib + DebugLib + BaseMemoryLib + +[Guids] + gMemoryProtectionSettingsGuid diff --git a/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtec= tionsLib.inf b/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProt= ectionsLib.inf new file mode 100644 index 000000000000..328eb4c78139 --- /dev/null +++ b/MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtectionsLi= b.inf @@ -0,0 +1,34 @@ +## @file +# Library fills out gMps global for accessing the platform memory protecti= on settings +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MmGetMemoryProtectionsLib + FILE_GUID =3D 719D6FAE-7EF1-429B-9A00-D5C50E4BB15A + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D GetMemoryProtectionsLib|SMM_CORE DXE_= SMM_DRIVER MM_CORE_STANDALONE MM_STANDALONE + CONSTRUCTOR =3D GetMmMemoryProtectionSettingsConstruc= tor + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + MmGetMemoryProtectionsLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + HobLib + DebugLib + BaseMemoryLib + +[Guids] + gMemoryProtectionSettingsGuid diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.inf b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.inf new file mode 100644 index 000000000000..2e4a9a66ac68 --- /dev/null +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.= inf @@ -0,0 +1,48 @@ +## @file +# Library for setting the memory protection settings for DXE. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SetMemoryProtectionsLib + FILE_GUID =3D DDA7DD34-0D3E-48FC-B4AE-A25581A40317 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SetMemoryProtectionsLib|SEC PEI_CORE = PEIM + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + SetMemoryProtectionsLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseMemoryLib + BaseLib + HobLib + DebugLib + PcdLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask + gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType + gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType + gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy + gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack + gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy + +[Guids] + gMemoryProtectionSettingsGuid + +[BuildOptions] + GCC:*_*_*_CC_FLAGS =3D -Wno-missing-braces diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 4932a05079ae..10340583f119 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -233,7 +233,10 @@ [Components] MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf + MdeModulePkg/Library/GetMemoryProtectionsLib/DxeGetMemoryProtectionsLib.= inf + MdeModulePkg/Library/GetMemoryProtectionsLib/MmGetMemoryProtectionsLib.i= nf MdeModulePkg/Library/GetMemoryProtectionsLib/GetMemoryProtectionsLibNull= .inf + MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.inf MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLibNull= .inf MdeModulePkg/Library/PciHostBridgeLibNull/PciHostBridgeLibNull.inf MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTa= bleLib.inf --=20 2.42.0.windows.1 -=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 (#108158): https://edk2.groups.io/g/devel/message/108158 Mute This Topic: https://groups.io/mt/101064076/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- From nobody Sat May 11 07:38:29 2024 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+108159+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+108159+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437553; cv=none; d=zohomail.com; s=zohoarc; b=HCSs0uYVbj9oRPg1Wq8g/7533Hmjtdj/LdPhwK+OVlmWcRjJYV2U4CC5z4w4PU+aKX/Z/6bPFJ/I4zr02zzmIsTo4iWtqMOPvEH5f8XuT0UcZ53A7r6hKUFWQbx9GB6bZUmjeczN2Cd9+E1XBDKZjfpM07INZY5cXXEskAIf1ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437553; 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=8w8Y+vQhOa+cW+/TYSJgrrbg3qihMoO46c3lcFpDXk0=; b=bmnxe7rzC4YMJ4YUjcOIIxw5kbt+BLHdx2Z6hdbNGwVxDUZBge69AgaNNQwU3MZtjlizA7JGOprIyyK3z0hC0qJR8uU0dihPtJYem7kpRUpnuYIDn8cX+5lizLTt/I6rUXFmAj5KwSC6ep3t8LB7n9ODyJq1LvsHMTX27qUKocc= 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+108159+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 1693437553518116.74030889513551; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=HyN2pgdMNobHWXyV/vk0rzLbLDzWXLWA2OWxrPkXqFA=; 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=1693437553; v=1; b=hfUbBJfR5KcqSNfipCxTbh/vDuM2OjYiCGwH7Ew87gsQTY1iaygK2ROet5fpo+1lp1KtIFwk lL1984BaIsCCl1wc09HBmyY0YykbFluEBrpvSYvg+NnV86FWlpU6s1GvhOdo4t3ZokznxUg2KdQ vwno7IMGfb1w2myk96Swg3X0= X-Received: by 127.0.0.2 with SMTP id 20XTYY1788612xhJD8iW9qTI; Wed, 30 Aug 2023 16:19:13 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web11.4944.1693437547132133643 for ; Wed, 30 Aug 2023 16:19:07 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-686be3cbea0so976893b3a.0 for ; Wed, 30 Aug 2023 16:19:07 -0700 (PDT) X-Gm-Message-State: ca1ymFnqNiiLQIXTMXSbJICUx1787277AA= X-Google-Smtp-Source: AGHT+IHQjgW+ErqFT63U8gp7q8EMK+4vM+YehDjpNPr/zgOioX+py5t5xf4ENqSQa+mbPXSp/ja6Tg== X-Received: by 2002:a05:6a20:3d8b:b0:149:729c:d065 with SMTP id s11-20020a056a203d8b00b00149729cd065mr1453895pzi.14.1693437546390; Wed, 30 Aug 2023 16:19:06 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:06 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 05/26] MdeModulePkg: Copy PEI PCD Database Into New Buffer Date: Wed, 30 Aug 2023 16:18:13 -0700 Message-ID: <20230830231851.779-6-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437554937100049 Content-Type: text/plain; charset="utf-8" HOB memory should not be written to in DXE phase. This patch copies the PCD database from PEI into a new buffer so updates to dynamic PCDs don't write to HOB memory. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Universal/PCD/Dxe/Service.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Univer= sal/PCD/Dxe/Service.c index 1ae06a639c43..0feb11142545 100644 --- a/MdeModulePkg/Universal/PCD/Dxe/Service.c +++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c @@ -885,15 +885,17 @@ BuildPcdDxeDataBase ( // be NULL. If it is NULL, we just copy over the DXE Default // Value to PCD Database. // - PeiDatabase =3D (PEI_PCD_DATABASE *)GET_GUID_HOB_DATA (GuidHob); + PeiDatabase =3D AllocateCopyPool ((UINTN)GET_GUID_HOB_DATA_SIZE (GuidH= ob), GET_GUID_HOB_DATA (GuidHob)); + ASSERT (PeiDatabase !=3D NULL); =20 // // Get next one that stores full PEI data // GuidHob =3D GetNextGuidHob (&gPcdDataBaseHobGuid, GET_NEXT_HOB (GuidHo= b)); if (GuidHob !=3D NULL) { - mPeiPcdDbBinary =3D (PEI_PCD_DATABASE *)GET_GUID_HOB_DATA (GuidHob); mPeiPcdDbSize =3D (UINTN)GET_GUID_HOB_DATA_SIZE (GuidHob); + mPeiPcdDbBinary =3D (PEI_PCD_DATABASE *)AllocateCopyPool (mPeiPcdDbS= ize, GET_GUID_HOB_DATA (GuidHob)); + ASSERT (mPeiPcdDbBinary !=3D NULL); } =20 // --=20 2.42.0.windows.1 -=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 (#108159): https://edk2.groups.io/g/devel/message/108159 Mute This Topic: https://groups.io/mt/101064077/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- From nobody Sat May 11 07:38:29 2024 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+108160+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+108160+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437548; cv=none; d=zohomail.com; s=zohoarc; b=l96Q4c9rr2kvy/Lz6AnFA7UKXger8MEHu0i8x8dbGb04CNaqAzKFSC8F+tlCFmswoVecK66RA/APLRq916Pz9wJnw7zKZyqsxxj0112WuoKQtLIJp3nxORwmFrX5AcgH0p/dcBlU33bwhOlE2Z4EFE/7vNvdt7JoUE4E3CUfmxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437548; 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=2FQ8oBPocbQcyao32PE25BdXDeEw5An+CfU43IE/Bn0=; b=VB6U5WHpiw7Pr/N/K6C6h6x2qR59mjXGDpKsyu417cntDl9G7IQ+mZAMg6UCYAmbxSbQoh/nY/uv//g0zKrhU1Fn3rq+3SwyoqhmY71nWQ4VTJ2v131uYi9tTbY0keKkfR/lxTA90zEpOYJRA57dgeN/VgEt1xTN7OPKPqYhkoE= 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+108160+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 1693437548731857.9247107354507; Wed, 30 Aug 2023 16:19:08 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=HmRsxmKQ8C2Nn06unzFycJ2hyQk/91VGZEaXttmGRkM=; 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=1693437548; v=1; b=nBdQpM1X/eFJ8mGbFM7tHCVH+eq/SrEYwCik4SOGv2pcJciEJPEvii3+zWNrQtRZ7kDvriwt ACijvCy4oHCgmbUIJLVkErkVmsLWctnttY358dq1cPbkaTQqNQ0juub5X8bZ8Uz9iwjlDUy5SGm 5781KBjHV8CfXlf9Spza2zDk= X-Received: by 127.0.0.2 with SMTP id FKKCYY1788612xVy6Bb2udzW; Wed, 30 Aug 2023 16:19:08 -0700 X-Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web11.4948.1693437547918477928 for ; Wed, 30 Aug 2023 16:19:07 -0700 X-Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-68a56401b9aso164473b3a.1 for ; Wed, 30 Aug 2023 16:19:07 -0700 (PDT) X-Gm-Message-State: 7z52QCigwxMMYmrrKC9IE0B7x1787277AA= X-Google-Smtp-Source: AGHT+IH1Rh2OQ36TBGhqvYxw+jgjU5mdkoKQH6mockYKIoe+pBojcZCd0olWKHrxBUA3geFPwYA8yw== X-Received: by 2002:a05:6a21:8188:b0:13d:a903:88e6 with SMTP id pd8-20020a056a21818800b0013da90388e6mr3307669pzb.48.1693437547196; Wed, 30 Aug 2023 16:19:07 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:06 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 06/26] MdeModulePkg: Apply Protections to the HOB List Date: Wed, 30 Aug 2023 16:18:14 -0700 Message-ID: <20230830231851.779-7-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437549602100017 Content-Type: text/plain; charset="utf-8" Because the platform memory protection settings will be stored in the HOB, the HOB list should be marked read-only and non-executable as soon as possible in boot. This patch page-aligns the allocated HOB list in DXE and marks it RO/NX during memory protection initialization. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 18 ++++++------ MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 29 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gc= d.c index 792cd2e0af23..72bd036eab1e 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2764,21 +2764,21 @@ CoreInitializeGcdServices ( } =20 // - // Relocate HOB List to an allocated pool buffer. + // Relocate HOB List to allocated pages. // The relocation should be at after all the tested memory resources add= ed // (except the memory space that covers HOB List) to the memory services, // because the memory resource found in CoreInitializeMemoryServices() // may have not enough remaining resource for HOB List. // - NewHobList =3D AllocateCopyPool ( - (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart), - *HobStart - ); - ASSERT (NewHobList !=3D NULL); - - *HobStart =3D NewHobList; - gHobList =3D NewHobList; + NewHobList =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PhitHob->EfiFree= MemoryBottom - (UINTN)(*HobStart))); + if (NewHobList !=3D NULL) { + CopyMem (NewHobList, *HobStart, (UINTN)PhitHob->EfiFreeMemoryBottom - = (UINTN)(*HobStart)); + *HobStart =3D NewHobList; + } else { + ASSERT (NewHobList !=3D NULL); + } =20 + gHobList =3D *HobStart; if (MemorySpaceMapHobList !=3D NULL) { // // Add and allocate the memory space that covers HOB List to the memor= y services diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 7cc829b17402..94ed3111688b 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -967,6 +967,32 @@ InitializeDxeNxMemoryProtectionPolicy ( } } =20 +/** + Mark the HOB list as read-only and non-executable. +**/ +STATIC +VOID +ProtectHobList ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + + Hob.Raw =3D GetHobList (); + + // Find the end of the HOB list. + while (!END_OF_HOB_LIST (Hob)) { + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + + // Protect the HOB list. + SetUefiImageMemoryAttributes ( + (UINTN)gHobList, + ALIGN_VALUE (((UINTN)Hob.Raw + GET_HOB_LENGTH (Hob)) - (UINTN)GetHobLi= st (), EFI_PAGE_SIZE), + EFI_MEMORY_XP | EFI_MEMORY_RO + ); +} + /** A notification for CPU_ARCH protocol. =20 @@ -1007,6 +1033,9 @@ MemoryProtectionCpuArchProtocolNotify ( // HeapGuardCpuArchProtocolNotify (); =20 + // Mark the HOB list XP and RO. + ProtectHobList (); + if (mImageProtectionPolicy =3D=3D 0) { goto Done; } --=20 2.42.0.windows.1 -=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 (#108160): https://edk2.groups.io/g/devel/message/108160 Mute This Topic: https://groups.io/mt/101064078/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- From nobody Sat May 11 07:38:29 2024 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+108161+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+108161+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437549; cv=none; d=zohomail.com; s=zohoarc; b=S8hh1dALLb0807QoWOvaIfUTW4kXyA9o+WGJRiIV1/+V8eRnmh7e13IMInNKiWc7gKgB7X0WA933Iu6kS3MC8JpFHkScf12ZZot7o/99jDNBhCL+u4NquLyp8bbi4BmcONkMhnCu0LV7+EkOCN3xRH1ETvqpzVy8yInKtUeFQPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437549; 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=Q3xTFUAu7kpNu1a4Y+S6u1P3RMQUxL1SsKAC5GCmc7g=; b=hMeFWGhKvxTd0TmbO7P8j9JMQflAQaJa4mU47F/sUtIgEhymHEqnYMXwikRfDGJYnuCa5dwC+Ht3HNQhWOGWPt1rgmX8UhKRQ7u6e+2ivyEXHkInEo4BvOj91eJ9FjwEHMhRVGISK1nGs7I9uhznICvXxPGmi3LOTheJv48wxto= 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+108161+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 1693437549384947.0271894258652; Wed, 30 Aug 2023 16:19:09 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=KhPVHENpdRn9D13KkbnMZenKzZZF9IguuNtLQzBoKik=; 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=1693437549; v=1; b=EiTUCcu2XtysAPkK8B1Zbqy89aOSNVr2v4TsOlK0DKC0IyIqOjxPiSLZj5G5Wbm9XnsTp6HP cN4ARuorg4Ij0/wee8jts8/EBeZJ0QaQjXpuvQX48XLNn8CJBdDagFGstfvm4mqJHc4wsU50w0g d9Fa4UhS2mQAYo6hPBO3yXbg= X-Received: by 127.0.0.2 with SMTP id MvwnYY1788612xIgfAjZB08L; Wed, 30 Aug 2023 16:19:09 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web10.4862.1693437548558150291 for ; Wed, 30 Aug 2023 16:19:08 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68bed8de5b9so155896b3a.3 for ; Wed, 30 Aug 2023 16:19:08 -0700 (PDT) X-Gm-Message-State: 4ipJiZ4NUTWPdiWd3twALERZx1787277AA= X-Google-Smtp-Source: AGHT+IEM8UnR7LBN7nDUrdB5XXu2513T+ZYe6jX+drv06UdR3Uh8roaopjGhAtPyFP1cwsqcjmYkwQ== X-Received: by 2002:a05:6a00:2193:b0:68a:33fc:a085 with SMTP id h19-20020a056a00219300b0068a33fca085mr3944229pfi.7.1693437547878; Wed, 30 Aug 2023 16:19:07 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:07 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 07/26] MdeModulePkg: Check Print Level Before Dumping GCD Memory Map Date: Wed, 30 Aug 2023 16:18:15 -0700 Message-ID: <20230830231851.779-8-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437549604100018 Content-Type: text/plain; charset="utf-8" When page/pool protections are active, the GCD sync process takes quite a bit longer than normal. This behavior is primarily due to a function which dumps the GCD memory map to the console. This dump function runs only on DEBUG builds but will iterate through the GCD memory map dozens of times even when the print level doesn't include DEBUG_GCD. This patch adds a check for the DEBUG_GCD print level before dumping the GCD memory map which saves several seconds during boot when page/pool protections are active. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 4 ++++ MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + 2 files changed, 5 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gc= d.c index 72bd036eab1e..392586d5b17c 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -150,6 +150,10 @@ CoreDumpGcdMemorySpaceMap ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; UINTN Index; =20 + if ((PcdGet32 (PcdDebugPrintErrorLevel) & DEBUG_GCD) =3D=3D 0) { + return; + } + Status =3D CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap); ASSERT (Status =3D=3D EFI_SUCCESS && MemorySpaceMap !=3D NULL); =20 diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeM= ain.inf index 35d5bf0dee6f..6c896a0e7f0f 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -187,6 +187,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdFwVolDxeMaxEncapsulationDepth = ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel = ## CONSUMES =20 # [Hob] # RESOURCE_DESCRIPTOR ## CONSUMES --=20 2.42.0.windows.1 -=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 (#108161): https://edk2.groups.io/g/devel/message/108161 Mute This Topic: https://groups.io/mt/101064079/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- From nobody Sat May 11 07:38:29 2024 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+108162+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+108162+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437550; cv=none; d=zohomail.com; s=zohoarc; b=TiU6qyL4jDkKt4dmwOlY4s+vpsGawEA6A63zWguvUKXK2R5mk69qGOrmQynu2SEDi2UTNxxuIxioATFLo3jxjafFtx7MWQhTC6+f3WG1nrtxFF2P+BwThCT7TLaTeUHxO1IcUc8xQ3XHDGafOqDCpEMzwzG9PMHIWkYInwElaN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437550; 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=WnBm8CfJ3VarDANy2XzKaL0210BON6OdnvoFZq+LaJE=; b=dvqhtds0jE9+FfpEMF+9Z1F8ikhXchFPNEFEdTT5wDzZdOwvu1qAshlR2JQU1UfmooR6v1eUll+ulszsLObC0wrsvgcfuiucWl+w6rQ1xvAksw3EwTIGzj8RmUiymbtsresSr+gzdQ7z4CjtEFoitoLEElbCNAT5hIZh/fTbgHo= 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+108162+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 1693437550276597.4910794119647; Wed, 30 Aug 2023 16:19:10 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=UjXpcFetN5dDTgEzUmUkSdpC4EXEqi+q+vz4T6kyYzw=; 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=1693437549; v=1; b=t26iCGsQRAhsYroYVE7DPoKwPX3+M7x/SClAqDKOFljDEPj1iNLhfyLCwZXCbfo8t5Yfm5b3 FCduVsuYfVORu8mGKmJdh6xVR8pB/c1mcZtTWzQCmO2FQbiYz5KGRfhpM7RxSJW4hSwsLN5P/XP QVA4F2ID61M6kMI87XMILqsE= X-Received: by 127.0.0.2 with SMTP id 4BQfYY1788612xz1h0YfGnnh; Wed, 30 Aug 2023 16:19:09 -0700 X-Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web10.4863.1693437549399587903 for ; Wed, 30 Aug 2023 16:19:09 -0700 X-Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-68becf931d0so156755b3a.3 for ; Wed, 30 Aug 2023 16:19:09 -0700 (PDT) X-Gm-Message-State: E6AkYZ60C6jKdmThxBprP8Eix1787277AA= X-Google-Smtp-Source: AGHT+IFUYZy9B1BC/5iRxOn66kBtqGRMY1brjnVdEwnzjK8rqeILmXEcj5qK8M6dBTOUWWXfFap07w== X-Received: by 2002:a05:6a21:3d89:b0:14d:396e:6e1c with SMTP id bj9-20020a056a213d8900b0014d396e6e1cmr3440654pzc.28.1693437548621; Wed, 30 Aug 2023 16:19:08 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:08 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 08/26] UefiCpuPkg: Always Set Stack Guard in MpPei Init Date: Wed, 30 Aug 2023 16:18:16 -0700 Message-ID: <20230830231851.779-9-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437551732100031 Content-Type: text/plain; charset="utf-8" Memory protection is not set in PEI and ingested during and after DXE handoff. This paradigm means that the platform cannot reliably query the stack guard setting during MpInit. Because the execution path of PEI consistent and no third party code is executed, setting the stack guard in MpInit on every boot should be fine. Signed-off-by: Taylor Beebe Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar =20 Cc: Gerd Hoffmann --- UefiCpuPkg/CpuMpPei/CpuMpPei.c | 8 +++----- UefiCpuPkg/CpuMpPei/CpuPaging.c | 16 ++++++++-------- UefiCpuPkg/CpuMpPei/CpuMpPei.h | 3 ++- UefiCpuPkg/CpuMpPei/CpuMpPei.inf | 1 - 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c index b504bea3cfeb..ca0c6bdb4b21 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c @@ -469,10 +469,6 @@ InitializeMpExceptionStackSwitchHandlers ( EFI_STATUS Status; UINT8 *Buffer; =20 - if (!PcdGetBool (PcdCpuStackGuard)) { - return; - } - Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); ASSERT_EFI_ERROR (Status); =20 @@ -589,7 +585,9 @@ InitializeCpuMpWorker ( // // Special initialization for the sake of Stack Guard // - InitializeMpExceptionStackSwitchHandlers (); + if (mInitStackGuard) { + InitializeMpExceptionStackSwitchHandlers (); + } =20 // // Update and publish CPU BIST information diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPagin= g.c index b7ddb0005b6f..0ab8ceeee8a6 100644 --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c @@ -68,6 +68,8 @@ EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList[] =3D { } }; =20 +BOOLEAN mInitStackGuard =3D FALSE; + /** The function will check if IA32 PAE is supported. =20 @@ -532,7 +534,7 @@ SetupStackGuardPage ( } =20 /** - Enable/setup stack guard for each processor if PcdCpuStackGuard is set t= o TRUE. + Enable/setup stack guard for each processor. =20 Doing this in the memory-discovered callback is to make sure the Stack G= uard feature to cover as most PEI code as possible. @@ -553,7 +555,6 @@ MemoryDiscoveredPpiNotifyCallback ( ) { EFI_STATUS Status; - BOOLEAN InitStackGuard; EDKII_MIGRATED_FV_INFO *MigratedFvInfo; EFI_PEI_HOB_POINTERS Hob; IA32_CR0 Cr0; @@ -563,11 +564,10 @@ MemoryDiscoveredPpiNotifyCallback ( // initialization later will not contain paging information and then fail // the task switch (for the sake of stack switch). // - InitStackGuard =3D FALSE; - Hob.Raw =3D NULL; + Hob.Raw =3D NULL; if (IsIa32PaeSupported ()) { - Hob.Raw =3D GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid); - InitStackGuard =3D PcdGetBool (PcdCpuStackGuard); + Hob.Raw =3D GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid); + mInitStackGuard =3D TRUE; } =20 // @@ -575,7 +575,7 @@ MemoryDiscoveredPpiNotifyCallback ( // is to enable paging if it is not enabled (only in 32bit mode). // Cr0.UintN =3D AsmReadCr0 (); - if ((Cr0.Bits.PG =3D=3D 0) && (InitStackGuard || (Hob.Raw !=3D NULL))) { + if ((Cr0.Bits.PG =3D=3D 0) && (mInitStackGuard || (Hob.Raw !=3D NULL))) { ASSERT (sizeof (UINTN) =3D=3D sizeof (UINT32)); =20 Status =3D EnablePaePageTable (); @@ -588,7 +588,7 @@ MemoryDiscoveredPpiNotifyCallback ( Status =3D InitializeCpuMpWorker ((CONST EFI_PEI_SERVICES **)PeiServices= ); ASSERT_EFI_ERROR (Status); =20 - if (InitStackGuard) { + if (mInitStackGuard) { SetupStackGuardPage (); } =20 diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h index 1b9a94e18fdf..d0db4e480e13 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h @@ -31,6 +31,7 @@ #include =20 extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc; +extern BOOLEAN mInitStackGuard; =20 /** This service retrieves the number of logical processor in the platform @@ -426,7 +427,7 @@ InitializeCpuMpWorker ( ); =20 /** - Enable/setup stack guard for each processor if PcdCpuStackGuard is set t= o TRUE. + Enable/setup stack guard for each processor. =20 Doing this in the memory-discovered callback is to make sure the Stack G= uard feature to cover as most PEI code as possible. diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPe= i.inf index 865be5627e85..6a987754120a 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf @@ -64,7 +64,6 @@ [Ppis] =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ##= SOMETIMES_CONSUMES --=20 2.42.0.windows.1 -=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 (#108162): https://edk2.groups.io/g/devel/message/108162 Mute This Topic: https://groups.io/mt/101064080/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- From nobody Sat May 11 07:38:29 2024 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+108163+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+108163+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437551; cv=none; d=zohomail.com; s=zohoarc; b=SjXSAESBsC6Z59RuRa9H+itn2FgervPTxMCc/ooNQExUgz1+TEXA8sA4oZg4tQ0TULiTGJbv0z259cd6WrceyUPNp2cPGdfhOwYnBx269bxLTvjT0HkB+mFVd39qd5qewaT+rPWQV6EY6TFDjNsW9XPTGvuLBO4z6vOg8V9Rhck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437551; 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=ZU167evLprsLzwrcjhpjdIm1YBSh7RbRuLaNrEsgzZ8=; b=ZXSioXBZncmzpScZfHGGVzRT1ZWTmoriGy1scuSCN4gSDgSuGQveE4E5MIA6ulGoKjza3m8XwBX0+NS9JF1/0RgS+MsgPbF/YXQ5z/faZdDz3kvmMTdiar+3RSjZ47WzkV6FE1iyUQqDE3fZw8If9zv0CLlZcXMzSu/DguA+8ig= 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+108163+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 1693437551087740.247284287229; Wed, 30 Aug 2023 16:19:11 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Z592GIFQsHLmslLxKfTVsy9Qd9s/RF7qlAjEXaHoJCU=; 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=1693437550; v=1; b=DUeqe4OsVUkKmDxVlWyHtjHr75I9RGI3UFf44XlO5tDQ+O7wvfQcywndxbxq2iNEhdTrPWWX oehTS7lIjFaHmhifZ0RB8FBmoqCpNuJNIDJFpZeYzXvmlcORHk+y6g9v9tTpb7UB1go7n2BtDG5 BhdUJk0cPdekToFmsn2ZxZWc= X-Received: by 127.0.0.2 with SMTP id v6IYYY1788612xkyLKJPbjYY; Wed, 30 Aug 2023 16:19:10 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web11.4950.1693437550243768179 for ; Wed, 30 Aug 2023 16:19:10 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a41035828so157833b3a.1 for ; Wed, 30 Aug 2023 16:19:10 -0700 (PDT) X-Gm-Message-State: 1dKwvke81UJI4hWvaQmBh7WQx1787277AA= X-Google-Smtp-Source: AGHT+IG2tnSX00vmqLbJ92+skDHK3G8gnk5O5nz5oInYP3Dt2zC9xtr1LQpX/gxbGvgF9dodkd7lXg== X-Received: by 2002:a05:6a00:1914:b0:68c:3f2:5ffd with SMTP id y20-20020a056a00191400b0068c03f25ffdmr3164346pfi.2.1693437549509; Wed, 30 Aug 2023 16:19:09 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:09 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Julien Grall Subject: [edk2-devel] [PATCH v3 09/26] ArmVirtPkg: Add Memory Protection Library Definitions to Platforms Date: Wed, 30 Aug 2023 16:18:17 -0700 Message-ID: <20230830231851.779-10-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437551747100032 Content-Type: text/plain; charset="utf-8" Add library classes for SetMemoryProtectionsLib and GetMemoryProtectionsLib to ArmVirtPkg. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Julien Grall --- ArmVirtPkg/ArmVirt.dsc.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 2443e8351c99..6de28d0e0d4e 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -156,6 +156,12 @@ [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 + # + # Memory Protection Libraries for setting and getting memory protection = settings + # + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLib.inf + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Dxe= GetMemoryProtectionsLib.inf + # # Secure Boot dependencies # --=20 2.42.0.windows.1 -=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 (#108163): https://edk2.groups.io/g/devel/message/108163 Mute This Topic: https://groups.io/mt/101064081/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- From nobody Sat May 11 07:38:29 2024 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+108164+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+108164+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437551; cv=none; d=zohomail.com; s=zohoarc; b=K7kZ/BvuOycvNN5513fOhLem9vbUlVuUsiFptQpcNKsCY/86jIYuhrsfwGmiy+dlMKXbwY8vi/CzYhbmk7j7xRlfFrOOwUz0ZAb+/PLfXfSREShuJ0yAZRydbn17AATqWJUBzjpE3FjqNaS0lBU0qQFIkJiz9zG4FV1PNIHz3qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437551; 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=wlnefGUN7Tryq3f+lZ4Ac2Zmw+xAf8hkhXOpz3DuNmA=; b=eweuY9bby4XWPA16ZZ6apC23DMtmqgohe2u0hZD95LH/9h1ajRAd2Y067OF+q1+0OeqEf5ecguQBkEAx2vU7T8KksX6xNNUE3997UzT73Uzbw/TKJxFct7uHHIwP+7Mh+swQsZd1rHDpDpaJ2PyDdVNY8V6gAba1vzhdFJ+DvrI= 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+108164+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 1693437551835424.0440613651376; Wed, 30 Aug 2023 16:19:11 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qiPkXFvtU1rb/ijj4iKWc/1du+Z2MqRIAI9H4f7VNKA=; 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=1693437551; v=1; b=skuqGzUzq0y/dnQwe3GB1cHMbIeIF9gMuamymA7IGeH4avA3stZ7O/0UH4cErgRVaFlufE7h mJTpM5L23zfCWw67uHGKcZfvH0/G53alZois0rwdQjyvo/Vt7Zf/m/4/7lTyPEcMxJy0oyKzDgd Il0CO8zTUXT5Y2St+J2rRCF4= X-Received: by 127.0.0.2 with SMTP id tj9RYY1788612x6JLdbkv9bJ; Wed, 30 Aug 2023 16:19:11 -0700 X-Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mx.groups.io with SMTP id smtpd.web10.4864.1693437550999255147 for ; Wed, 30 Aug 2023 16:19:11 -0700 X-Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-68c0d886ea0so172597b3a.2 for ; Wed, 30 Aug 2023 16:19:10 -0700 (PDT) X-Gm-Message-State: oE3MwUbiZY77c0U8zea1iRAWx1787277AA= X-Google-Smtp-Source: AGHT+IESb1GZG1Jgc6/2Jjld7iAsXgnXK1kHZN0hC5g0hnzzqd8bXJ5QSaLm0Fv4BEPS7IL0weavrQ== X-Received: by 2002:a05:6a00:3909:b0:68a:5773:6319 with SMTP id fh9-20020a056a00390900b0068a57736319mr3680587pfb.11.1693437550219; Wed, 30 Aug 2023 16:19:10 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:09 -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?= , Jianyong Wu , Anatol Belski , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v3 10/26] OvmfPkg: Add Memory Protection Library Definitions to Platforms Date: Wed, 30 Aug 2023 16:18:18 -0700 Message-ID: <20230830231851.779-11-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437553716100042 Content-Type: text/plain; charset="utf-8" Add library classes for SetMemoryProtectionsLib and GetMemoryProtectionsLib to OvmfPkg platfomrs. 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\ufffd\ufffdhne Cc: Jianyong Wu Cc: Anatol Belski Cc: Anthony Perard Cc: Julien Grall --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc | 15 +++++++++++++++ OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 ++ OvmfPkg/Microvm/MicrovmX64.dsc | 2 ++ OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 2 ++ OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 2 ++ 11 files changed, 29 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 2c6ed7c9745f..0913aa734114 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -202,6 +202,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 82c60ace1bbd..c2a3b9bf3960 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -229,6 +229,7 @@ [LibraryClasses] XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index e000deed9e4d..20d609156e7d 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -239,6 +239,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc b/OvmfPk= g/Include/Dsc/MemoryProtectionLibraries.dsc.inc new file mode 100644 index 000000000000..049fdef3f0c1 --- /dev/null +++ b/OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc @@ -0,0 +1,15 @@ +## +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +# +# Memory Protection Libraries +# +[LibraryClasses.common] + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLib.inf + +[LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER, Lib= raryClasses.common.MM_CORE_STANDALONE, LibraryClasses.common.MM_STANDALONE] + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/MmG= etMemoryProtectionsLib.inf + +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, Library= Classes.common.UEFI_APPLICATION, LibraryClasses.common.UEFI_DRIVER] + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Dxe= GetMemoryProtectionsLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 80b0558c3f77..7d589d887732 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -211,6 +211,8 @@ [LibraryClasses] Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeT= cg2PhysicalPresenceLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf =20 +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index d2ef1e00a5c2..1c9b0532599c 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -238,6 +238,8 @@ [LibraryClasses] Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeT= cg2PhysicalPresenceLib.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf =20 +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 80d8e370095d..8267cf20e4a9 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -246,6 +246,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d9757149e359..583033fe3d93 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -251,6 +251,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index b12d874daa0a..bbe825d5f50d 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -267,6 +267,7 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf =20 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index dcb99d1f0bce..7f99f8dd4783 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -231,6 +231,8 @@ [LibraryClasses] DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.i= nf !endif =20 +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVV= irtQemu.dsc index 34b2037824f1..dd25a34796e5 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -112,6 +112,8 @@ [LibraryClasses.common] TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLi= bNull/PeiDxeTpmPlatformHierarchyLib.inf !endif =20 +!include OvmfPkg/Include/Dsc/MemoryProtectionLibraries.dsc.inc + [LibraryClasses.common.DXE_DRIVER] AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf --=20 2.42.0.windows.1 -=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 (#108164): https://edk2.groups.io/g/devel/message/108164 Mute This Topic: https://groups.io/mt/101064082/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- From nobody Sat May 11 07:38:29 2024 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+108165+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+108165+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437552; cv=none; d=zohomail.com; s=zohoarc; b=LbAp/yFjRm0rL+FbaCW4ZTJ5VPbcBncLW/ExSJaPJDoGRC7UXjC2h/Jv0uR+NLWHLjxYaECqTQrSXz5UUOGU6ddgrNyubD1l44g9cTWqCkUNM72P0kQ3JiqPKDLHpPedmzIE1lDvEDsZMAm5L6/APwOi5m1f5Gkx6UVJHC91/bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437552; 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=uFCk0usPNNiSKhOdGSRXsVfsuYm6dz/NPe61s2dkYKE=; b=ieiq4LgQnNI5DExBWg71qDQK2CiJd/VeHsVky7mwCf76Rmhyp36g65iseLMEw9ij3D/KvIXQVaY4IM5D8TYnzpFYbWgC9GC2PKU3wbMH6M3w+ose+L15vL8R8QelMGfb9G2WB1mw/JbdOImuzVUNY5AfCqcXg9FKmBLnFmsXGxY= 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+108165+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 1693437552524722.4266493936466; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=uUZVGv7nDkNFff67+mkZFwm3vxZpbQSgnOkumXm3vcM=; 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=1693437552; v=1; b=ZtJUOoyfn0xk5OHnHRqkKggKn/046Q6kelZSC+nTyriewZzBoc5qb1RzLce//Yh25HCmeoQV k7fvxnGPmC0W1rrZ6pJ7wDaVaVQTmPs8pJIrIQfBZSiefyJm0x0k4FIVmzZyMZaATdbi0uWF7U4 BfxWXnxLUb6OdECBxgWCRgds= X-Received: by 127.0.0.2 with SMTP id XUjIYY1788612xbf1tSpPsZY; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web11.4953.1693437551612791262 for ; Wed, 30 Aug 2023 16:19:11 -0700 X-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68a529e1974so149856b3a.3 for ; Wed, 30 Aug 2023 16:19:11 -0700 (PDT) X-Gm-Message-State: XtSL0j7UmO2ja65hOtGHJSoKx1787277AA= X-Google-Smtp-Source: AGHT+IHwbZz66e9vqB/e51zlFpbii/BcXqwlDMjcfqjONFe04qG5mGWbCJsciCrKmaTXh9b94ZDaZw== X-Received: by 2002:a05:6a21:6811:b0:14c:4dfc:9766 with SMTP id wr17-20020a056a21681100b0014c4dfc9766mr3291657pzb.46.1693437550759; Wed, 30 Aug 2023 16:19:10 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:10 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 11/26] OvmfPkg: Apply Memory Protections via SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:19 -0700 Message-ID: <20230830231851.779-12-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437552886100037 Content-Type: text/plain; charset="utf-8" Use SetMemoryProtectionsLib to set the memory protections for the platform in both normal and PEI-less boot. The protections set are equivalent to the PCD settings and the ability to set NxForStack via QemuCfg is preserved. Once the transition to use SetMemoryProtectionsLib and GetMemoryProtectionsLib is complete in the rest of EDK2, the mechanics of setting protections in OvmfPkg will be updated and the memory protection PCDs will be deleted. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann --- OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c | 15 +++++++++++++= -- OvmfPkg/PlatformPei/Platform.c | 15 +++++++++++++= -- OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf | 3 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index 1632a2317718..cf645aad3246 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -14,10 +14,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include #include @@ -42,7 +45,9 @@ InitializePlatform ( EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - VOID *VariableStore; + VOID *VariableStore; + DXE_MEMORY_PROTECTION_SETTINGS DxeSettings; + MM_MEMORY_PROTECTION_SETTINGS MmSettings; =20 DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n")); PlatformDebugDumpCmos (); @@ -104,7 +109,13 @@ InitializePlatform ( =20 PlatformMemMapInitialization (PlatformInfoHob); =20 - PlatformNoexecDxeInitialization (PlatformInfoHob); + 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); + + SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); + SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); =20 if (TdIsEnabled ()) { PlatformInfoHob->PcdConfidentialComputingGuestAttr =3D CCAttrIntelTdx; diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8c4..bcd8d3a1be14 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -38,6 +38,7 @@ #include #include #include +#include =20 #include "Platform.h" =20 @@ -304,8 +305,10 @@ InitializePlatform ( IN CONST EFI_PEI_SERVICES **PeiServices ) { - EFI_HOB_PLATFORM_INFO *PlatformInfoHob; - EFI_STATUS Status; + EFI_HOB_PLATFORM_INFO *PlatformInfoHob; + EFI_STATUS Status; + DXE_MEMORY_PROTECTION_SETTINGS DxeSettings; + MM_MEMORY_PROTECTION_SETTINGS MmSettings; =20 DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); PlatformInfoHob =3D BuildPlatformInfoHob (); @@ -342,6 +345,14 @@ 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); + + SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); + SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); + PlatformQemuUc32BaseInitialization (PlatformInfoHob); =20 InitializeRamRegions (PlatformInfoHob); diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index 585d50463748..f0a8a5a56df4 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -56,6 +56,8 @@ [LibraryClasses] PrePiLib QemuFwCfgLib PlatformInitLib + SetMemoryProtectionsLib + QemuFwCfgSimpleParserLib =20 [Guids] gEfiHobMemoryAllocModuleGuid @@ -81,6 +83,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ##= CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 3934aeed9514..6b8442d12b2c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -65,6 +65,7 @@ [LibraryClasses] PcdLib CcExitLib PlatformInitLib + SetMemoryProtectionsLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase --=20 2.42.0.windows.1 -=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 (#108165): https://edk2.groups.io/g/devel/message/108165 Mute This Topic: https://groups.io/mt/101064083/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- From nobody Sat May 11 07:38:29 2024 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+108166+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+108166+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437553; cv=none; d=zohomail.com; s=zohoarc; b=n8kOXV3e0J3GNP12lic0aGV9d49H/98gUZf5qtPDtdMCK1jUgj1uROWVjgrb08QklX+mZ/LVU9pF2+/k+hamxPNc+Yf0s9X/L6E0XgMVeEKpfsxmJ6DXeraXg1qHygSpoHTaFVBxrIJTYR81zOlTVlg7brm+N2xufOxYsjU8aHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437553; 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=ufs2sFicpo4dhXwBPG0uReY2KRQiuz1cVg8zcJmmWfE=; b=Ny6l4PeNz5BLQJGPjH7wYvGxWdNjEv0L8ec06NABxe+H0WD1tjkbKn+ZTlk2/ptBFklW6t2IhZ4B1J/D66gUEGOqO7n0qK1iw1rb+Y3k56mxuHoYVOTc5sj7WvHkHpwucTjsIQ6f4MbKcRcV5SYCTovqRXk6sa3/2pXZWGsvFoY= 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+108166+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 1693437553100799.5035979078291; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wmLRqBrWJtH65GdbaXgdP2AjEbZ5c9vv+jMW55kgmSs=; 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=1693437552; v=1; b=rKjtEU5m8sUN49SP2jlotnkb+IoTG/oSLnQYCKKNgjgXQ12ZAmdcF6MsE3dc7LM06QowbIBL GtqlaWWDnpBuigDFt81+5DN9U1E0caPotlf5ek1j0o6cpt2G9izbrT4B/F7QhvxmkA7IRpQ1/Ur PN1czIt8Wx4KH4VcszVXH4Nc= X-Received: by 127.0.0.2 with SMTP id 7t90YY1788612xAkPMDD7uv4; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web10.4866.1693437552256788388 for ; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68bec3a9bdbso137070b3a.3 for ; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) X-Gm-Message-State: a2fKBvkRbyGj1dSOsfhW17q9x1787277AA= X-Google-Smtp-Source: AGHT+IGHvvQJw9iuSx1k6XObgNf+wIdvGu9AqYf8pt0vuaKU0FBLvTvGlA7xpFHkxghGLUE4Pt6Jbg== X-Received: by 2002:a05:6a00:1a8f:b0:68b:dbbc:dcea with SMTP id e15-20020a056a001a8f00b0068bdbbcdceamr3485909pfv.9.1693437551492; Wed, 30 Aug 2023 16:19:11 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:11 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 12/26] OvmfPkg: Update PeilessStartupLib to use SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:20 -0700 Message-ID: <20230830231851.779-13-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437554952100050 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.1 -=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 (#108166): https://edk2.groups.io/g/devel/message/108166 Mute This Topic: https://groups.io/mt/101064084/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- From nobody Sat May 11 07:38:29 2024 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+108167+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+108167+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437553; cv=none; d=zohomail.com; s=zohoarc; b=U77rVyRPZYvl6/kHtUHz31q72nxpcZ1L5bMuDLlumkvzCHN4k6A2F17ONhZNgcg5zLZks+dXE5Fw5gojlxk3DU0nS/Nz2vEpM3EWlO1PsetmifSbKJb2nvVqvH80tdyQ9ygci66QKg2Pa+FaAdIelTVaSY38nxgf3eMojDJzkhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437553; 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=SWLTynymZMfU2PZX5XWVEo/3ZE5OKID/UWHn+wYKlas=; b=kZb/Hc2+EDBykxfPRlhShUnpSKRceth/mJ2X9rCpcmMb2LzKUfMP86iVTYcV0x89AZhRZmiXJ1OXqu/SluIDPyh4HZX/auYHp6tYXWCeMTF0Excim01fNHqgbNoIoJKCE7+Kk/E2Pxs5wrr6dXo+PaBZzMvgoBwkryhjCOgZvmM= 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+108167+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 1693437553958348.3544431418326; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=K8F0X9J91L61vBZtgkE7t8wUDCJdg/91EeMvoHJqA5E=; 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=1693437553; v=1; b=fDtCFek0ZHIeia/dWr+M3WNSkynMuXfXETZte88gLQp93gcpRK1jSbum5ARBP8nMOnlOm2n0 rlMRkHbleI4bs9fgJkGSc9y8QKKjvfRdL1Uv2/6oOD9zO1hJurRZ7ph8YSJvtQBbk7NMGHNylnH CwaWR0U+6ekgb8J0sG2zqBpk= X-Received: by 127.0.0.2 with SMTP id cPQxYY1788612xd4d9jIOl8m; Wed, 30 Aug 2023 16:19:13 -0700 X-Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web10.4869.1693437552925275693 for ; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68a3cae6d94so181020b3a.0 for ; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) X-Gm-Message-State: vWKJ635pqDZjBkXHVb6W5FOix1787277AA= X-Google-Smtp-Source: AGHT+IF0mZH2Sh1aQtpUj8KaZjiM47GAADAbJ9Y9Y1cbueUCUzfTWzfZXIA+mNWTFwvgSOPiaVyUMg== X-Received: by 2002:a05:6a21:6da0:b0:11d:4c79:90ee with SMTP id wl32-20020a056a216da000b0011d4c7990eemr4424679pzb.25.1693437552154; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:11 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Guo Dong , Sean Rhodes , James Lu , Gua Guo Subject: [edk2-devel] [PATCH v3 13/26] UefiPayloadPkg: Update DXE Handoff to use SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:21 -0700 Message-ID: <20230830231851.779-14-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437555801100058 Content-Type: text/plain; charset="utf-8" Update the DXE handoff logic in UefiPayloadPkg to use SetMemoryProtectionsLib to fetch the platform memory protection settings and reference them when creating the page tables. Because the protection profile is equivalent to the PCD settings even when the platform does not explicitly set a profile, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo --- UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c | 11 +++++++++-- UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c | 2 ++ UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c | 8 ++++++-- UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 15 +++++++++--= ---- UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 1 + UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 9 +-------- UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 9 +-------- UefiPayloadPkg/UefiPayloadPkg.dsc | 12 ++++++++++++ 8 files changed, 41 insertions(+), 26 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c b/UefiPaylo= adPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c index 61a9f01ec9e7..4ede962e6544 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c @@ -78,6 +78,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDesc= riptor =3D { 0 }; =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + /** Allocates and fills in the Page Directory and Page Table Entries to establish a 4G page table. @@ -227,11 +229,14 @@ ToBuildPageTable ( return TRUE; } =20 - if (PcdGet8 (PcdHeapGuardPropertyMask) !=3D 0) { + if (mMps.Dxe.HeapGuard.PageGuardEnabled || + mMps.Dxe.HeapGuard.PageGuardEnabled || + mMps.Dxe.HeapGuard.FreedMemoryGuardEnabled) + { return TRUE; } =20 - if (PcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { return TRUE; } =20 @@ -268,6 +273,8 @@ HandOffToDxeCore ( UINT32 Index; X64_IDT_TABLE *IdtTableForX64; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // diff --git a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c b/UefiPayloadPkg= /UefiPayloadEntry/LoadDxeCore.c index 898d610951fa..a4074346c059 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c +++ b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c @@ -8,6 +8,8 @@ =20 #include "UefiPayloadEntry.h" =20 +MEMORY_PROTECTION_SETTINGS mMps =3D { 0 }; + /** Allocate pages for code. =20 diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c b/UefiPayloa= dPkg/UefiPayloadEntry/X64/DxeLoadFunc.c index 346e3feb0459..002ae6e5ab97 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c @@ -17,6 +17,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "UefiPayloadEntry.h" #define STACK_SIZE 0x20000 =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + /** Transfers control to DxeCore. =20 @@ -40,6 +42,8 @@ HandOffToDxeCore ( VOID *GhcbBase; UINTN GhcbSize; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // @@ -83,8 +87,8 @@ HandOffToDxeCore ( // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE // for the DxeIpl and the DxeCore are both X64. // - ASSERT (PcdGetBool (PcdSetNxForStack) =3D=3D FALSE); - ASSERT (PcdGetBool (PcdCpuStackGuard) =3D=3D FALSE); + ASSERT (!mMps.Dxe.StackExecutionProtectionEnabled); + ASSERT (!mMps.Dxe.CpuStackGuardEnabled); } =20 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) { diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayl= oadPkg/UefiPayloadEntry/X64/VirtualMemory.c index 1899404b244c..6a986c82cc4b 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -27,11 +27,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include #include "VirtualMemory.h" =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + // // Global variable to keep track current available memory used as page tab= le. // @@ -115,7 +118,7 @@ IsNullDetectionEnabled ( VOID ) { - return ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) !=3D 0); + return mMps.Dxe.NullPointerDetection.Enabled; } =20 /** @@ -169,9 +172,9 @@ IsEnableNonExecNeeded ( // XD flag (BIT63) in page table entry is only valid if IA32_EFER.NXE is= set. // Features controlled by Following PCDs need this feature to be enabled. // - return (PcdGetBool (PcdSetNxForStack) || - PcdGet64 (PcdDxeNxMemoryProtectionPolicy) !=3D 0 || - PcdGet32 (PcdImageProtectionPolicy) !=3D 0); + return (mMps.Dxe.StackExecutionProtectionEnabled || + !IsZeroBuffer (&mMps.Dxe.ExecutionProtection.EnabledForType, MPS= _MEMORY_TYPE_BUFFER_SIZE) || + (mMps.Dxe.ImageProtection.ProtectImageFromFv || mMps.Dxe.ImagePr= otection.ProtectImageFromUnknown)); } =20 /** @@ -399,14 +402,14 @@ Split2MPageTo4K ( PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && (PhysicalAddress4K =3D=3D 0)) || - (PcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K =3D=3D StackB= ase))) + (mMps.Dxe.CpuStackGuardEnabled && (PhysicalAddress4K =3D=3D StackB= ase))) { PageTableEntry->Bits.Present =3D 0; } else { PageTableEntry->Bits.Present =3D 1; } =20 - if ( PcdGetBool (PcdSetNxForStack) + if ( mMps.Dxe.StackExecutionProtectionEnabled && (PhysicalAddress4K >=3D StackBase) && (PhysicalAddress4K < StackBase + StackSize)) { diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.h index ad8a9fd22b66..c966f3583c77 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include #include diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPay= loadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index e2af8a4b7c1b..589dd9d3a99c 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -55,6 +55,7 @@ [LibraryClasses] PeCoffLib PlatformSupportLib CpuLib + SetMemoryProtectionsLib =20 [Guids] gEfiMemoryTypeInformationGuid @@ -76,9 +77,6 @@ [FeaturePcd.X64] [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ##= SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 @@ -91,8 +89,3 @@ [Pcd.IA32,Pcd.X64] gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode - - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES - diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf b/Ue= fiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf index 5112cdc1e5df..3e99011e0ac6 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf @@ -53,6 +53,7 @@ [LibraryClasses] HobLib PeCoffLib CpuLib + SetMemoryProtectionsLib =20 [Guids] gEfiMemoryTypeInformationGuid @@ -81,17 +82,9 @@ [Pcd.IA32,Pcd.X64] gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ##= SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemBase gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize - - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES - diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index 47812048ddcf..b00d75ba08db 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -312,6 +312,18 @@ [LibraryClasses] CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf =20 +# +# Memory Protection Libraries +# +[LibraryClasses.common] + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLib.inf + +[LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER] + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/MmG= etMemoryProtectionsLib.inf + +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, Library= Classes.common.UEFI_APPLICATION, LibraryClasses.common.UEFI_DRIVER] + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Dxe= GetMemoryProtectionsLib.inf + [LibraryClasses.common] !if $(BOOTSPLASH_IMAGE) SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf --=20 2.42.0.windows.1 -=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 (#108167): https://edk2.groups.io/g/devel/message/108167 Mute This Topic: https://groups.io/mt/101064087/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- From nobody Sat May 11 07:38:29 2024 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+108168+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+108168+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437554; cv=none; d=zohomail.com; s=zohoarc; b=IRbXVjLqF/tg8tX1ExCm7g0mSCKOgrsxw959QgYYnWfjLXHv5DZnfHAyWmr0Qq8rUHEpsyOuGT5dLzhgv+f1slpCDdkBIr2BocApxAyJKsGnN61dKWnlFIOLT3/w+xmDkRM1B94ZFW5utqn23pdx+U/tyLSfspvexM282VoA07A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437554; 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=CCPrIEkxqQmIu3x3zTfgn/+gojiBtzJxuAw0S1+ol6I=; b=ZOO8GFiXX8QGYUrm0rHJqb0sLiE1+cXH5SPvxFyrMGiPzqYaQMwkh70nhflCg9Z6eLIXvptO749FaEK7bwTIoWTPCMq8YxQT3juABlLb1rt+LNXR8G6pHYt7TAXV521KXAP/5HpgoDDcs9hNUDYq6tDZukgc93bGVr9/t6BW7ps= 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+108168+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 1693437554692553.1482730877078; Wed, 30 Aug 2023 16:19:14 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=h1LEKpw/pd5/dIwygTVgNxTcZlJvmRe8lsprWNVbCJ4=; 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=1693437554; v=1; b=M17v7A5MIBsx9u83bsxW1hoXFFCwWgpV5fzfnGx/HPh6Du0s4CmISeq+qjaGELO1/h1cKbE1 gPMZa5I+WBuXScmGcdLKEEpFLFu2KVrWcJAng0AKZa4MzzTjQmUJpd4m6Ui45m5stjY6SqM6XRP wMm/aEFnosd0OnPK4RFWPqtY= X-Received: by 127.0.0.2 with SMTP id 9ErmYY1788612xbr1XHLbycL; Wed, 30 Aug 2023 16:19:14 -0700 X-Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mx.groups.io with SMTP id smtpd.web10.4870.1693437553606304852 for ; Wed, 30 Aug 2023 16:19:13 -0700 X-Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-56f84dd2079so254469a12.1 for ; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) X-Gm-Message-State: SCbYvGKY0VPSGH1doG7CSPLzx1787277AA= X-Google-Smtp-Source: AGHT+IG6MAuzX5P67tVyAqq2Z89dRbYL2EmVqueb90My2cJFwuaxD+yOQR92hSAXFexVocabjmf4gw== X-Received: by 2002:a05:6a20:729f:b0:135:1af6:9a01 with SMTP id o31-20020a056a20729f00b001351af69a01mr4643285pzk.8.1693437552842; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:12 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 14/26] MdeModulePkg: Update DXE Handoff to use SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:22 -0700 Message-ID: <20230830231851.779-15-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437554966100051 Content-Type: text/plain; charset="utf-8" Update the DXE handoff logic in MdeModulePkg to use SetMemoryProtectionsLib to fetch the platform memory protection settings and reference them when creating the page tables. Because the protection profile is equivalent to the PCD settings even when the platform does not explicitly set a profile, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c | 4 +++- MdeModulePkg/Core/DxeIplPeim/DxeLoad.c | 2 ++ MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 9 +++++++-- MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c | 6 ++++-- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 16 ++++++++-------- MdeModulePkg/Core/DxeIplPeim/DxeIpl.h | 3 +++ MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 11 +---------- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c b/MdeModulePkg/Core/= DxeIplPeim/DxeHandoff.c index 60400da3521a..9f7ed2069a46 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c @@ -33,13 +33,15 @@ HandOffToDxeCore ( EFI_STATUS Status; EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Allocate 128KB for the Stack // BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); ASSERT (BaseOfStack !=3D NULL); =20 - if (PcdGetBool (PcdSetNxForStack)) { + if (mMps.Dxe.StackExecutionProtectionEnabled) { Status =3D PeiServicesLocatePpi ( &gEdkiiMemoryAttributePpiGuid, 0, diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/Dxe= IplPeim/DxeLoad.c index 2c19f1a507ba..0789dbca6ad8 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -50,6 +50,8 @@ CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyL= ist =3D { InstallIplPermanentMemoryPpis }; =20 +MEMORY_PROTECTION_SETTINGS mMps =3D { 0 }; + /** Entry point of DXE IPL PEIM. =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 4bc7b749b0fc..762c288d5924 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -219,11 +219,14 @@ ToBuildPageTable ( return TRUE; } =20 - if (PcdGet8 (PcdHeapGuardPropertyMask) !=3D 0) { + if (mMps.Dxe.HeapGuard.PageGuardEnabled || + mMps.Dxe.HeapGuard.PoolGuardEnabled || + mMps.Dxe.HeapGuard.FreedMemoryGuardEnabled) + { return TRUE; } =20 - if (PcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { return TRUE; } =20 @@ -265,6 +268,8 @@ HandOffToDxeCore ( EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; BOOLEAN BuildPageTablesIa32Pae; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index fa2050cf023a..7e17a963e9ff 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -36,6 +36,8 @@ HandOffToDxeCore ( VOID *GhcbBase; UINTN GhcbSize; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // @@ -104,8 +106,8 @@ HandOffToDxeCore ( // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE // for the DxeIpl and the DxeCore are both X64. // - ASSERT (PcdGetBool (PcdSetNxForStack) =3D=3D FALSE); - ASSERT (PcdGetBool (PcdCpuStackGuard) =3D=3D FALSE); + ASSERT (!mMps.Dxe.StackExecutionProtectionEnabled); + ASSERT (!mMps.Dxe.CpuStackGuardEnabled); } =20 // diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 980c2002d4f5..2c75702d6a25 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -109,7 +109,7 @@ IsNullDetectionEnabled ( VOID ) { - return ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) !=3D 0); + return mMps.Dxe.NullPointerDetection.Enabled; } =20 /** @@ -163,9 +163,9 @@ IsEnableNonExecNeeded ( // XD flag (BIT63) in page table entry is only valid if IA32_EFER.NXE is= set. // Features controlled by Following PCDs need this feature to be enabled. // - return (PcdGetBool (PcdSetNxForStack) || - PcdGet64 (PcdDxeNxMemoryProtectionPolicy) !=3D 0 || - PcdGet32 (PcdImageProtectionPolicy) !=3D 0); + return (mMps.Dxe.StackExecutionProtectionEnabled || + !IsZeroBuffer (&mMps.Dxe.ExecutionProtection.EnabledForType, MPS= _MEMORY_TYPE_BUFFER_SIZE) || + mMps.Dxe.ImageProtection.ProtectImageFromFv || mMps.Dxe.ImagePro= tection.ProtectImageFromUnknown); } =20 /** @@ -214,13 +214,13 @@ ToSplitPageTable ( return TRUE; } =20 - if (PcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { if ((StackBase >=3D Address) && (StackBase < (Address + Size))) { return TRUE; } } =20 - if (PcdGetBool (PcdSetNxForStack)) { + if (mMps.Dxe.StackExecutionProtectionEnabled) { if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase= )) { return TRUE; } @@ -403,14 +403,14 @@ Split2MPageTo4K ( PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && (PhysicalAddress4K =3D=3D 0)) || - (PcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K =3D=3D StackB= ase))) + (mMps.Dxe.CpuStackGuardEnabled && (PhysicalAddress4K =3D=3D StackB= ase))) { PageTableEntry->Bits.Present =3D 0; } else { PageTableEntry->Bits.Present =3D 1; } =20 - if ( PcdGetBool (PcdSetNxForStack) + if ( mMps.Dxe.StackExecutionProtectionEnabled && (PhysicalAddress4K >=3D StackBase) && (PhysicalAddress4K < StackBase + StackSize)) { diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h b/MdeModulePkg/Core/DxeI= plPeim/DxeIpl.h index 2f015befceca..f6826349c378 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h @@ -37,6 +37,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define STACK_SIZE 0x20000 #define BSP_STORE_SIZE 0x4000 =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + // // This PPI is installed to indicate the end of the PEI usage of memory // diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index f1990eac7760..ccbf5c36d7f6 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -67,6 +67,7 @@ [LibraryClasses] DebugAgentLib PeiServicesTablePointerLib PerformanceLib + SetMemoryProtectionsLib =20 [Ppis] gEfiDxeIplPpiGuid ## PRODUCES @@ -101,20 +102,10 @@ [FeaturePcd] [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ##= SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable ##= SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 -[Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES - [Depex] gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid =20 --=20 2.42.0.windows.1 -=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 (#108168): https://edk2.groups.io/g/devel/message/108168 Mute This Topic: https://groups.io/mt/101064088/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- From nobody Sat May 11 07:38:29 2024 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+108169+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+108169+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437555; cv=none; d=zohomail.com; s=zohoarc; b=JKfqye3fVSSFB9BwyLPJOAvIC679LesGnQdmAHGl9WhAOglke+RRznA6ibDu5WqXneMKJEUwmz0n9jGfSfgmmyGZBGoI2cxfRrRXgp3E9sSPy7NlhmRee1dEeLMtU6YjVX9a70aLsJZw2CD+PoOGTNEwLljag4ljDqIYoRqsRMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437555; 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=01tOiTqM05AVph7SmzBlCU/gqtwAfB2bAHdGOlAKMKk=; b=jSCT+ihYzwWCD5RtdQOeDJDLLDcfhAXFMmj/kxGkhNCyXGX+6wAc7cbyqjorj90FhkA9SoG8FHePjXvBU6uTKQLr6za6LosA7zIBIROsyMIGBJ5HKMqk89Fywec+L7D4h1uIm+v7Hn9EFYFxc7C3MinGHTReUO1w2YMa/oXG/Ng= 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+108169+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 1693437555092595.9468255724139; Wed, 30 Aug 2023 16:19:15 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=OjHx9GZd8rCi5rY+bvWBwsCmT+64jJGPdpUiXxxjitc=; 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=1693437554; v=1; b=YB04xI0CKjqjNnPCmuMOOyKqrZIMZ+rzh0lMmwhQyc55ybqVip3PpvlB/ztB/vXWXR2RP1Ru /s7adj3esXSnd+hWXdUDMfxoJqDGeH4pxwHj7DF37TEfIJ7P6yx0ai+QnAVSc7CElblDcbmOYAX iqVWYgKM50wADgajRPwYf3Es= X-Received: by 127.0.0.2 with SMTP id uCX9YY1788612xpL30K7UBWO; Wed, 30 Aug 2023 16:19:14 -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.4871.1693437554056293879 for ; Wed, 30 Aug 2023 16:19:14 -0700 X-Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5654051b27fso237893a12.0 for ; Wed, 30 Aug 2023 16:19:14 -0700 (PDT) X-Gm-Message-State: Xlqtztla0MBuRzqSvogkELM8x1787277AA= X-Google-Smtp-Source: AGHT+IGnr3giPdZ52yv1Q19QJEuDzmsEHdVTqRtAOIuVd10qdJZKH0o/zgKMmIbaVsWjOqi0udI8Dg== X-Received: by 2002:a05:6a20:191:b0:137:23a2:2b3c with SMTP id 17-20020a056a20019100b0013723a22b3cmr3647340pzy.49.1693437553372; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:13 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sami Mujawar Subject: [edk2-devel] [PATCH v3 15/26] ArmPkg: Use GetMemoryProtectionsLib instead of Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:23 -0700 Message-ID: <20230830231851.779-16-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437556961100063 Content-Type: text/plain; charset="utf-8" Replace references to the memory protection PCDs to instead check the platform protections via GetMemoryProtectionsLib. Signed-off-by: Taylor Beebe Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar --- ArmPkg/Drivers/CpuDxe/CpuDxe.c | 5 ++--- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Drivers/CpuDxe/CpuDxe.inf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c b/ArmPkg/Drivers/CpuDxe/CpuDxe.c index fc63e527846a..8a25e78dfebd 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c @@ -12,6 +12,7 @@ #include =20 #include +#include =20 BOOLEAN mIsFlushingGCD; =20 @@ -241,7 +242,6 @@ RemapUnusedMemoryNx ( VOID ) { - UINT64 TestBit; UINTN MemoryMapSize; UINTN MapKey; UINTN DescriptorSize; @@ -251,8 +251,7 @@ RemapUnusedMemoryNx ( EFI_MEMORY_DESCRIPTOR *MemoryMapEnd; EFI_STATUS Status; =20 - TestBit =3D LShiftU64 (1, EfiBootServicesData); - if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & TestBit) =3D=3D 0) { + if (!gMps.Dxe.ExecutionProtection.EnabledForType[EfiBootServicesData]) { return; } =20 diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 4939b3d59b7f..354535eb3718 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -57,6 +57,7 @@ [LibraryClasses.common] PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Get= MemoryProtectionsLibNull.inf =20 UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.inf b/ArmPkg/Drivers/CpuDxe/CpuDx= e.inf index 7d8132200e64..4d0a3de99546 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.inf +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.inf @@ -46,6 +46,7 @@ [LibraryClasses] CpuExceptionHandlerLib DebugLib DefaultExceptionHandlerLib + GetMemoryProtectionsLib DxeServicesTableLib HobLib MemoryAllocationLib @@ -65,7 +66,6 @@ [Guids] =20 [Pcd.common] gArmTokenSpaceGuid.PcdVFPEnabled - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy =20 [FeaturePcd.common] gArmTokenSpaceGuid.PcdDebuggerExceptionSupport --=20 2.42.0.windows.1 -=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 (#108169): https://edk2.groups.io/g/devel/message/108169 Mute This Topic: https://groups.io/mt/101064089/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- From nobody Sat May 11 07:38:29 2024 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+108170+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+108170+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437555; cv=none; d=zohomail.com; s=zohoarc; b=LdHTx4qb6KuR1zqCjn0pDxoIC/8AkH9QcVQ/8L/mFjA21GsbNDswhHVTKpc+G+lFzAprKSj3G6rT5jh08kP7q2vYGsR6qzJBppo349T8C/N6IUwzMG0jvU4w3gN8tYULMw1vsamQ+WRVTk5ZpzOD/1iJWwfcYaAeK3oMuSUmtlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437555; 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=mJkIANL6uPhxAXTKjQEEiZrpuusrNTsdT+3hCkKZRmU=; b=Swvd0uWysIFDrrhx7FARPfYkru7fHcdgGE+3RD3pXDx7Ht+AaR1vRoTWWiu093aaVK1VpvoaAWW3ndIZOA8wklbh88DDZQ+RBn07m8bbnIjkCkXzqiQ/VxXLh2fms/F/QUb6/Uf+wjq7ih2BpEWJOtcfVDY8S4Utf9JuwNouQvM= 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+108170+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 1693437555849463.68963859330324; Wed, 30 Aug 2023 16:19:15 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=/hBFzL6laoNZC5xqrmzBTIa0gGlnVaVjr+xskK/hyVA=; 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=1693437555; v=1; b=wBDF0bxZvOTPEMOer/RHMZm9z9+l9qTZke9K+5kNaNIZl/QTAnDgCrpBOTYbJX4nEMOFqgKi WL3DtdoQnpzHgU7/hVfgkjSIVBw5gKqNh54C1TxLFHRBXzB4nUIubM+0tOhZALl6FLgNEOE6doo bZeMfibC0dCBTeDkLBcYtX6c= X-Received: by 127.0.0.2 with SMTP id Z1D0YY1788612xkNrnnyMMaf; Wed, 30 Aug 2023 16:19:15 -0700 X-Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mx.groups.io with SMTP id smtpd.web11.4956.1693437554933878834 for ; Wed, 30 Aug 2023 16:19:15 -0700 X-Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-68c576d35feso158595b3a.2 for ; Wed, 30 Aug 2023 16:19:14 -0700 (PDT) X-Gm-Message-State: CTeZvEnbOaW3uGCg0lWGyTf7x1787277AA= X-Google-Smtp-Source: AGHT+IGJYbpmog7XFvSe7U8zVGrqM9zwwcgYbNa7toVEsI3XYuuGDKPXGIFfiEA+ahiJtBBk9/PwHw== X-Received: by 2002:a05:6a00:b42:b0:68a:5395:7aa5 with SMTP id p2-20020a056a000b4200b0068a53957aa5mr3704839pfo.17.1693437554091; Wed, 30 Aug 2023 16:19:14 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:13 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni Subject: [edk2-devel] [PATCH v3 16/26] EmulatorPkg: Use GetMemoryProtectionsLib instead of Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:24 -0700 Message-ID: <20230830231851.779-17-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437557940100069 Content-Type: text/plain; charset="utf-8" Replace references to the memory protection PCDs to instead check the platform protections via GetMemoryProtectionsLib. Because the protection profile is equivalent to the PCD settings, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Andrew Fish Cc: Ray Ni --- EmulatorPkg/EmulatorPkg.dsc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index b44435d7e6ee..1e2c903f5c30 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -126,6 +126,8 @@ [LibraryClasses] SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Get= MemoryProtectionsLibNull.inf + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLibNull.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -216,7 +218,6 @@ [PcdsFeatureFlag] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables|FALSE =20 [PcdsFixedAtBuild] - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy|0x00000000 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000040 gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0f --=20 2.42.0.windows.1 -=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 (#108170): https://edk2.groups.io/g/devel/message/108170 Mute This Topic: https://groups.io/mt/101064090/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- From nobody Sat May 11 07:38:29 2024 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+108171+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+108171+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437556; cv=none; d=zohomail.com; s=zohoarc; b=my42oqqDmwQSIwhK8jqxSO+XtJcIcw98Z09vWN2uvF5Bmibq+45z3XECj1hSmEAY4RR2QV0Z5ks1QnaI1X6ssYfk1INmX6f0GRzhoaUDfWlGB3NjWV3ARfXSklCy7qn0KVV+hNq+qm1qbuXEp7eq0vrCcuv3CznaWsNLt9gVo0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437556; 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=1fB6N4Eio8+VH2ukQKMk7eqheP4QZ2BMls2JGsDzlng=; b=GURtT8HwetYlwi9AlUaCQIJJ3WCTGGdEb4BpN05CY5X7P/M0OHrGVUvcjhNUESgb7WLl3eck2js/CllVzAZUhoLjsaK3JILuEsKhKCtPQSuJqJpKhswTYQITbQIgQ1WVsgMe0ETSobq4e7phqt0c2bcjIiHpibQO7Fd3Kr/aRHQ= 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+108171+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 1693437556276670.1914881967288; Wed, 30 Aug 2023 16:19:16 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=IMwcNXIsL4wABLRo0AUNhL1bW0js7Cnt0QrZ+U+WPnE=; 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=1693437555; v=1; b=ZNpjzkoVrhkfZQ46d+gD1np0cXs+r3jlXU3Ua69moxYO9SHXDwSQ/6Wvhpwp3YdGLS/yVIij rj3Xtj9QuSbPQWOzJllfXRGvAhX+wPnyzMUh1Gq5YKJpDKN8F3xDemqITinHm3sER3Xa+snBLk2 ZOYA9nRKqmNZKW7iLPtzQwt8= X-Received: by 127.0.0.2 with SMTP id HfYuYY1788612xx51slIufSy; Wed, 30 Aug 2023 16:19:15 -0700 X-Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mx.groups.io with SMTP id smtpd.web11.4957.1693437555352348551 for ; Wed, 30 Aug 2023 16:19:15 -0700 X-Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-68bed286169so170129b3a.1 for ; Wed, 30 Aug 2023 16:19:15 -0700 (PDT) X-Gm-Message-State: S0hTvAGJerYYSDTDEjqVQAd1x1787277AA= X-Google-Smtp-Source: AGHT+IFcW82eHDLrsXLxL8l2/5AilnkdT02He7ExrhZcsBFKLSw1foYB9f0lMe5u7qvXhb/NZfFxwA== X-Received: by 2002:a05:6a00:1913:b0:68a:49bc:e091 with SMTP id y19-20020a056a00191300b0068a49bce091mr4030298pfi.2.1693437554703; Wed, 30 Aug 2023 16:19:14 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:14 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Leif Lindholm , Abner Chang Subject: [edk2-devel] [PATCH v3 17/26] OvmfPkg: Use GetMemoryProtectionsLib instead of Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:25 -0700 Message-ID: <20230830231851.779-18-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437556968100064 Content-Type: text/plain; charset="utf-8" Replace references to the memory protection PCDs to instead check the platform protections via GetMemoryProtectionsLib. Because the protection profile is equivalent to the PCD settings, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Abner Chang --- OvmfPkg/Fdt/HighMemDxe/HighMemDxe.c | 5 ++--- OvmfPkg/QemuVideoDxe/VbeShim.c | 3 ++- OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf | 4 +--- OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.c b/OvmfPkg/Fdt/HighMemDxe/H= ighMemDxe.c index 779bf5c827f5..2bef34427341 100644 --- a/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.c +++ b/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include #include @@ -148,9 +149,7 @@ InitializeHighMemDxe ( // on the page table mappings by going through the cpu arch protoc= ol. // Attributes =3D EFI_MEMORY_WB; - if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & - (1U << (UINT32)EfiConventionalMemory)) !=3D 0) - { + if (gMps.Dxe.ExecutionProtection.EnabledForType[EfiConventionalMem= ory]) { Attributes |=3D EFI_MEMORY_XP; } =20 diff --git a/OvmfPkg/QemuVideoDxe/VbeShim.c b/OvmfPkg/QemuVideoDxe/VbeShim.c index 8f151b96f9a5..a60e409f50de 100644 --- a/OvmfPkg/QemuVideoDxe/VbeShim.c +++ b/OvmfPkg/QemuVideoDxe/VbeShim.c @@ -19,6 +19,7 @@ #include #include #include +#include #include =20 #include "Qemu.h" @@ -69,7 +70,7 @@ InstallVbeShim ( UINTN Printed; VBE_MODE_INFO *VbeModeInfo; =20 - if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) =3D=3D= BIT0) { + if (gMps.Dxe.NullPointerDetection.Enabled && !gMps.Dxe.NullPointerDetect= ion.DisableEndOfDxe) { DEBUG (( DEBUG_WARN, "%a: page 0 protected, not installing VBE shim\n", diff --git a/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf b/OvmfPkg/Fdt/HighMemDxe= /HighMemDxe.inf index c7dde9f455f2..40cbbe1c39af 100644 --- a/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf +++ b/OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf @@ -33,13 +33,11 @@ [LibraryClasses] PcdLib UefiBootServicesTableLib UefiDriverEntryPoint + GetMemoryProtectionsLib =20 [Protocols] gEfiCpuArchProtocolGuid ## CONSUMES gFdtClientProtocolGuid ## CONSUMES =20 -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy - [Depex] gEfiCpuArchProtocolGuid AND gFdtClientProtocolGuid diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf b/OvmfPkg/QemuVideoDxe/Q= emuVideoDxe.inf index 43a6e07faa88..15693ce85674 100644 --- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf @@ -55,6 +55,7 @@ [LibraryClasses] UefiBootServicesTableLib UefiDriverEntryPoint UefiLib + GetMemoryProtectionsLib =20 [Protocols] gEfiGraphicsOutputProtocolGuid # PROTOCOL BY_START @@ -64,6 +65,5 @@ [Protocols] [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution --=20 2.42.0.windows.1 -=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 (#108171): https://edk2.groups.io/g/devel/message/108171 Mute This Topic: https://groups.io/mt/101064091/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- From nobody Sat May 11 07:38:29 2024 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+108172+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+108172+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437557; cv=none; d=zohomail.com; s=zohoarc; b=cy+a/DQzXUT55Wz10tnkg2u90atjgEkUFESdKk5qT/VPkGqVNlw0ip7G9xdpcBl01YbI6+fR/hVEinefCuSBApeZ9hrjpDGfDGeJXEakqUpVwS09JxLcCrQt87OGL572TtmzmggyhfIhvVBRbjkyz9EtTLJ5FGa7Lrfj3fRGkr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437557; 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=bchRMnimaB5C1D/gYIU9RHZkZA/PB9sDzqVH4mQXdgY=; b=AIkejJGcROQe+G4TXXZ1WpwHcRnAOOGXzKFPOc7MI+lQArFiQltPfcGgmq6+ms0B0tet3S04nsg3Q+oVLXXhzgCjgIGoZ8InZhhZ55OxkJBgSR9B7QY/WQEC6Ak7vA7CgyZqyuVfQ5wx+pv9ORHafSf1PZqhGhVCbAYsFbaC7IM= 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+108172+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 1693437557430529.1346342853589; Wed, 30 Aug 2023 16:19:17 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=KOlbYh/xq/dZse6vw7sqsM2rW/V3AsAvVX5VWp0QdSA=; 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=1693437557; v=1; b=pqByk2nzzNrYIbdPbzcJlcELubupMsW0wUg5Y6D1ZR96y76gQ7U45MBL8hcK8i2oRRg5suzP O08kI/hLS8g7nlCyYAmKEtIkzo/NHbBQ/jhUuI6wNivpfgl01mWJVXS4KK6TYO3uSe14q2U9IDG gIYt3UyjUR5XIcI+mAqUFjYU= X-Received: by 127.0.0.2 with SMTP id WujoYY1788612xecohAg6n5D; Wed, 30 Aug 2023 16:19:17 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web11.4958.1693437556475330254 for ; Wed, 30 Aug 2023 16:19:16 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68a41031768so160651b3a.3 for ; Wed, 30 Aug 2023 16:19:16 -0700 (PDT) X-Gm-Message-State: rBgusmI1MzIbcff5fQtbxwY0x1787277AA= X-Google-Smtp-Source: AGHT+IHQljGhsjgTYY9It2j/pTJFgEUBYEIJJTBXf5FqRaOSF+8x9Hb9KF5Vv85F9jeRg0f3BrSG6g== X-Received: by 2002:a05:6a00:24c3:b0:68b:daf4:212f with SMTP id d3-20020a056a0024c300b0068bdaf4212fmr4157135pfv.21.1693437555439; Wed, 30 Aug 2023 16:19:15 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:15 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 18/26] UefiCpuPkg: Use GetMemoryProtectionsLib instead of Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:26 -0700 Message-ID: <20230830231851.779-19-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437557992100071 Content-Type: text/plain; charset="utf-8" Replace references to the memory protection PCDs to instead check the platform protections via GetMemoryProtectionsLib. Because the protection profile is equivalent to the PCD settings, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/CpuDxe/CpuDxe.c = | 2 +- UefiCpuPkg/CpuDxe/CpuMp.c = | 2 +- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandlerTest= Common.c | 6 +----- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerU= nitTest.c | 15 ++++++++++++++ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHandlerU= nitTest.c | 21 ++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c = | 3 ++- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c = | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c = | 13 ++++++------ UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c = | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c = | 2 +- UefiCpuPkg/CpuDxe/CpuDxe.h = | 11 ++++++---- UefiCpuPkg/CpuDxe/CpuDxe.inf = | 4 +--- UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf = | 3 --- UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf = | 1 - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf = | 1 - UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf= | 1 - UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf = | 1 - UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandlerTest= .h | 13 +++++++++++- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerL= ibUnitTest.inf | 2 +- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHandlerL= ibUnitTest.inf | 2 +- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf = | 3 ++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf = | 3 +-- UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h = | 9 +++++---- UefiCpuPkg/UefiCpuPkg.dec = | 7 +++---- UefiCpuPkg/UefiCpuPkg.dsc = | 2 ++ UefiCpuPkg/UefiCpuPkg.uni = | 10 ++++------ 26 files changed, 90 insertions(+), 51 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index 804ef5d1fe8e..b12c43f4c1d4 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -399,7 +399,7 @@ CpuSetMemoryAttributes ( // During memory attributes updating, new pages may be allocated to setup // smaller granularity of page table. Page allocation action might then = cause // another calling of CpuSetMemoryAttributes() recursively, due to memory - // protection policy configured (such as PcdDxeNxMemoryProtectionPolicy). + // protection policy configured (such as the DXE NX Protection Policy). // Since this driver will always protect memory used as page table by it= self, // there's no need to apply protection policy requested from memory serv= ice. // So it's safe to just return EFI_SUCCESS if this time of calling is ca= used diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index e7575d9b8062..d8f978eec09d 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -734,7 +734,7 @@ InitializeMpExceptionHandlers ( // // Setup stack switch for Stack Guard feature. // - if (PcdGetBool (PcdCpuStackGuard)) { + if (gMps.Dxe.CpuStackGuardEnabled) { InitializeMpExceptionStackSwitchHandlers (); } } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptio= nHandlerTestCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/C= puExceptionHandlerTestCommon.c index 9ba70c5b7340..fe74b0e0eaae 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandle= rTestCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandle= rTestCommon.c @@ -743,10 +743,6 @@ TestCpuStackGuardInBspAndAp ( VOID *NewIdtr; UINTN *CpuStackBaseBuffer; =20 - if (!PcdGetBool (PcdCpuStackGuard)) { - return UNIT_TEST_PASSED; - } - // // Get MP Service Protocol // @@ -846,7 +842,7 @@ AddCommonTestCase ( AddTestCase (CpuExceptionLibUnitTestSuite, "Check if exception handler c= an be registered/unregistered for GP and PF", "TestRegisterHandlerForGPAndP= F", TestRegisterHandlerForGPAndPF, NULL, NULL, NULL); =20 AddTestCase (CpuExceptionLibUnitTestSuite, "Check if Cpu Context is cons= istent before and after exception.", "TestCpuContextConsistency", TestCpuCo= ntextConsistency, NULL, NULL, NULL); - AddTestCase (CpuExceptionLibUnitTestSuite, "Check if stack overflow is c= aptured by CpuStackGuard in Bsp and AP", "TestCpuStackGuardInBspAndAp", Tes= tCpuStackGuardInBspAndAp, NULL, NULL, NULL); + AddTestCase (CpuExceptionLibUnitTestSuite, "Check if stack overflow is c= aptured by CpuStackGuard in Bsp and AP", "TestCpuStackGuardInBspAndAp", Tes= tCpuStackGuardInBspAndAp, IsStackGuardEnabled, NULL, NULL); =20 return EFI_SUCCESS; } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExcep= tionHandlerUnitTest.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/= DxeCpuExceptionHandlerUnitTest.c index 1cec3ed809d9..c1de3a6663ae 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c @@ -8,6 +8,7 @@ =20 #include "CpuExceptionHandlerTest.h" #include +#include #include =20 /** @@ -145,6 +146,20 @@ GetMpServices ( return gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&= MpServices->Protocol); } =20 +/** + Checks if stack guard is enabled. + + @param[in] Context The unit test context +**/ +UNIT_TEST_STATUS +EFIAPI +IsStackGuardEnabled ( + IN UNIT_TEST_CONTEXT Context + ) +{ + return gMps.Dxe.CpuStackGuardEnabled; +} + /** Entry for CpuExceptionHandlerDxeTest driver. =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExcep= tionHandlerUnitTest.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/= PeiCpuExceptionHandlerUnitTest.c index d9408d2f5e2f..763268f55314 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHan= dlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHan= dlerUnitTest.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 /** Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR b= uffer. @@ -152,6 +153,26 @@ GetMpServices ( return PeiServicesLocatePpi (&gEdkiiPeiMpServices2PpiGuid, 0, NULL, (VOI= D **)&MpServices->Ppi); } =20 +/** + Checks if stack guard is enabled. + + @param[in] Context The unit test context +**/ +UNIT_TEST_STATUS +EFIAPI +IsStackGuardEnabled ( + IN UNIT_TEST_CONTEXT Context + ) +{ + MEMORY_PROTECTION_SETTINGS Mps; + + if (!EFI_ERROR (GetCurrentMemoryProtectionSettings (&Mps))) { + return Mps.Dxe.CpuStackGuardEnabled; + } + + return FALSE; +} + /** Entry point of CpuExceptionHandlerPeiTest PEIM. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 57ddb86600a7..551a7924fad3 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include =20 @@ -497,7 +498,7 @@ InitMpGlobalData ( return; } =20 - if (PcdGetBool (PcdCpuStackGuard)) { + if (gMps.Dxe.CpuStackGuardEnabled) { // // One extra page at the bottom of the stack is needed for Guard page. // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c b/UefiCpuPkg/PiSmmCpu= DxeSmm/Ia32/PageTbl.c index b11264ce4aa7..7e6c9899b069 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c @@ -160,7 +160,7 @@ SmiPFHandler ( // // If NULL pointer was just accessed // - if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) !=3D 0) && + if (gMps.Mm.NullPointerDetection.Enabled && (PFAddress < EFI_PAGE_SIZE)) { DumpCpuContext (InterruptType, SystemContext); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPk= g/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 6f498666157e..4c02749c174e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1679,7 +1679,7 @@ GenSmmPageTable ( } } =20 - if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) !=3D 0) { + if (gMps.Mm.NullPointerDetection.Enabled) { // // Mark [0, 4k] as non-present // @@ -1834,13 +1834,13 @@ IfReadOnlyPageTableNeeded ( // // Don't mark page table memory as read-only if // - no restriction on access to non-SMRAM memory; or - // - SMM heap guard feature enabled; or - // BIT2: SMM page guard enabled - // BIT3: SMM pool guard enabled + // - SMM page guard enabled + // - SMM pool guard enabled // - SMM profile feature enabled // if (!IsRestrictedMemoryAccess () || - ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) !=3D 0) || + IS_MM_PAGE_GUARD_ACTIVE || + IS_MM_POOL_GUARD_ACTIVE || FeaturePcdGet (PcdCpuSmmProfileEnable)) { if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { @@ -1849,7 +1849,8 @@ IfReadOnlyPageTableNeeded ( // ASSERT ( !(IsRestrictedMemoryAccess () && - (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) !=3D 0) + (IS_MM_PAGE_GUARD_ACTIVE || + IS_MM_POOL_GUARD_ACTIVE)) ); =20 // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/SmmProfile.c index 7ac3c66f911c..4f48e0c4f399 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c @@ -610,7 +610,7 @@ InitPaging ( // // [0, 4k] may be non-present. // - PreviousAddress =3D ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BI= T1) !=3D 0) ? BASE_4KB : 0; + PreviousAddress =3D (gMps.Mm.NullPointerDetection.Enabled) ? BASE_4KB : = 0; =20 DEBUG ((DEBUG_INFO, "Patch page table start ...\n")); if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuD= xeSmm/X64/PageTbl.c index ddd9be66b53f..10e26cd72f6d 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -932,7 +932,7 @@ SmiPFHandler ( // // If NULL pointer was just accessed // - if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) !=3D 0) && + if (gMps.Mm.NullPointerDetection.Enabled && (PFAddress < EFI_PAGE_SIZE)) { DumpCpuContext (InterruptType, SystemContext); diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h index 0e7d88dd357c..a0284c562fa1 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.h +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h @@ -35,15 +35,18 @@ #include #include #include +#include =20 #include #include =20 -#define HEAP_GUARD_NONSTOP_MODE \ - ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) > BI= T6) +#define HEAP_GUARD_NONSTOP_MODE (gMps.Dxe.HeapGuard.NonstopModeEnable= d && \ + (IS_DXE_PAGE_GUARD_ACTIVE = || \ + IS_DXE_POOL_GUARD_ACTIVE = || \ + gMps.Dxe.HeapGuard.FreedMemoryGuardE= nabled)) \ =20 -#define NULL_DETECTION_NONSTOP_MODE \ - ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT0)) > B= IT6) +#define NULL_DETECTION_NONSTOP_MODE (gMps.Dxe.NullPointerDetection.Enable= d && \ + gMps.Dxe.NullPointerDetection.Nonsto= pModeEnabled) =20 /** Flush CPU data cache. If the instruction cache is fully coherent diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf index 1d3e9f8cdb29..85387c3ecdf2 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf @@ -40,6 +40,7 @@ [LibraryClasses] MpInitLib TimerLib PeCoffGetEntryPointLib + GetMemoryProtectionsLib =20 [Sources] CpuDxe.c @@ -74,9 +75,6 @@ [Ppis] =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask ##= CONSUMES diff --git a/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf b/UefiCpuPkg/CpuDxe= RiscV64/CpuDxeRiscV64.inf index 9d9a5ef8f247..262f9e6d9d5a 100644 --- a/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf +++ b/UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf @@ -56,9 +56,6 @@ [Ppis] gEfiSecPlatformInformationPpiGuid ## UNDEFINED # HOB =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ##= CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index fdbebadab93d..1fddf15b70bd 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -39,7 +39,6 @@ [Sources.common] DxeException.c =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index 3bcaff5c5fe4..348f7ed56c99 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -55,7 +55,6 @@ [LibraryClasses] CcExitLib =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index e7b1144f6941..0217c983d7c6 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -51,7 +51,6 @@ [LibraryClasses] CcExitLib =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 27f0b96fa9e9..6dc09b447ff0 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -54,7 +54,6 @@ [LibraryClasses] CcExitLib =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptio= nHandlerTest.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExce= ptionHandlerTest.h index bad3387db5bc..47bde8574b32 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandle= rTest.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/CpuExceptionHandle= rTest.h @@ -27,7 +27,7 @@ In this test case, stack overflow is triggered by a funtion which call= s itself continuously. This test case triggers stack overflow in both BSP and AP. All AP use same Idt with Bsp. The expecta= tion is: 1. PF exception is triggered (leading to a DF if sepereated stack is= not prepared for PF) when Rsp <=3D StackBase + SIZE_4KB - since [StackBase, StackBase + SIZE_4KB] is marked as not present = in page table when PcdCpuStackGuard is TRUE. + since [StackBase, StackBase + SIZE_4KB] is marked as not present = in page table when CpuStackGuard is TRUE. 2. Stack for PF/DF exception handler in both Bsp and AP is succussfu= lly switched by InitializeSeparateExceptionStacks. =20 **/ @@ -342,4 +342,15 @@ CpuStackGuardExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ); =20 +/** + Checks if stack guard is enabled. + + @param[in] Context The unit test context +**/ +UNIT_TEST_STATUS +EFIAPI +IsStackGuardEnabled ( + IN UNIT_TEST_CONTEXT Context + ); + #endif diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExcep= tionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Unit= Test/DxeCpuExceptionHandlerLibUnitTest.inf index a904eb250475..09c00fce8627 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf @@ -43,12 +43,12 @@ [LibraryClasses] HobLib UefiBootServicesTableLib CpuPageTableLib + GetMemoryProtectionsLib =20 [Guids] gEfiHobMemoryAllocStackGuid =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES =20 [Protocols] diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExcep= tionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Unit= Test/PeiCpuExceptionHandlerLibUnitTest.inf index 25f8f8dbe0e9..41fa759bf31e 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHan= dlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHan= dlerLibUnitTest.inf @@ -48,9 +48,9 @@ [LibraryClasses] PeiServicesLib CpuPageTableLib PeiServicesTablePointerLib + SetMemoryProtectionsLib =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES =20 [Ppis] diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 55e46d4a1fad..8edc7227d108 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -58,6 +58,8 @@ [LibraryClasses] PcdLib CcExitLib MicrocodeLib + GetMemoryProtectionsLib + [LibraryClasses.X64] CpuPageTableLib =20 @@ -82,6 +84,5 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdFirstTimeWakeUpAPsBySipi ## = CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## = CONSUMES diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 5d52ed7d1329..56f64873fe50 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -103,6 +103,7 @@ [LibraryClasses] PerformanceLib CpuPageTableLib MmSaveStateLib + GetMemoryProtectionsLib =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES @@ -146,8 +147,6 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesInitOnS3Resume ## CONS= UMES gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable ## CONS= UMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdePkgTokenSpaceGuid.PcdControlFlowEnforcementPropertyMask ##= CONSUMES =20 [FixedPcd] diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h b/UefiCpuPkg/Pi= SmmCpuDxeSmm/SmmProfileInternal.h index 964dd5281780..1ac91d9d3ce4 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h @@ -15,6 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include "SmmProfileArch.h" =20 @@ -57,11 +58,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define MSR_DEBUG_CTL_BTINT 0x100 #define MSR_DS_AREA 0x600 =20 -#define HEAP_GUARD_NONSTOP_MODE \ - ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT3|BIT2)) > BIT6) +#define HEAP_GUARD_NONSTOP_MODE (gMps.Mm.HeapGuard.NonstopModeEnabled = && \ + (IS_MM_PAGE_GUARD_ACTIVE || IS_MM_POOL_G= UARD_ACTIVE)) =20 -#define NULL_DETECTION_NONSTOP_MODE \ - ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT1)) > B= IT6) +#define NULL_DETECTION_NONSTOP_MODE (gMps.Mm.NullPointerDetection.Nonstop= ModeEnabled && \ + gMps.Mm.NullPointerDetection.Enabled) =20 typedef struct { EFI_PHYSICAL_ADDRESS Base; diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 68473fc640e6..8c667269ad7f 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -192,13 +192,13 @@ [PcdsFeatureFlag] =20 [PcdsFixedAtBuild] ## List of exception vectors which need switching stack. - # This PCD will only take into effect if PcdCpuStackGuard is enabled. + # This PCD will only take into effect if the CPU Stack Guard is enabled. # By default exception #DD(8), #PF(14) are supported. # @Prompt Specify exception vectors which need switching stack. gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList|{0x08, 0x0E}|VO= ID*|0x30002000 =20 ## Size of good stack for an exception. - # This PCD will only take into effect if PcdCpuStackGuard is enabled. + # This PCD will only take into effect if the CPU Stack Guard is enabled. # @Prompt Specify size of good stack of exception which need switching s= tack. gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize|2048|UINT32|0x30002001 =20 @@ -388,9 +388,8 @@ [PcdsFixedAtBuild.X64, PcdsPatchableInModule.X64, PcdsD= ynamic.X64, PcdsDynamicEx # and the memory occupied by page table is protected by page table itse= lf as read-only. # In X64 build, it cannot be enabled at the same time with SMM profile = feature (PcdCpuSmmProfileEnable). # In X64 build, it could not be enabled also at the same time with heap= guard feature for SMM - # (PcdHeapGuardPropertyMask in MdeModulePkg). # In IA32 build, page table memory is not marked as read-only when eith= er SMM profile feature (PcdCpuSmmProfileEnable) - # or heap guard feature for SMM (PcdHeapGuardPropertyMask in MdeModuleP= kg) is enabled. + # or heap guard feature for SMM is enabled. # TRUE - Access to non-SMRAM memory is restricted to reserved, runtim= e and ACPI NVS type after SmmReadyToLock.
# FALSE - Access to any type of non-SMRAM memory after SmmReadyToLock = is allowed.
# @Prompt Access to non-SMRAM memory is restricted to reserved, runtime = and ACPI NVS type after SmmReadyToLock. diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 074fd774616d..2dbb8394b382 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -66,6 +66,8 @@ [LibraryClasses] UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersistenceL= ibNull/UnitTestPersistenceLibNull.inf UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultRepor= tLib/UnitTestResultReportLibDebugLib.inf + GetMemoryProtectionsLib|MdeModulePkg/Library/GetMemoryProtectionsLib/Get= MemoryProtectionsLibNull.inf + SetMemoryProtectionsLib|MdeModulePkg/Library/SetMemoryProtectionsLib/Set= MemoryProtectionsLibNull.inf =20 [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index d17bcfd10c7a..5719917a041e 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -170,8 +170,7 @@ = "If enabled, SMM will not use on-demand paging. SMM will build s= tatic page table for all memory.\n" = "This flag only impacts X64 build, because SMM always builds sta= tic page table for IA32.\n" = "It could not be enabled at the same time with SMM profile featu= re (PcdCpuSmmProfileEnable).\n" - = "It could not be enabled also at the same time with heap guard f= eature for SMM\n" - = "(PcdHeapGuardPropertyMask in MdeModulePkg).

\n" + = "It could not be enabled also at the same time with heap guard f= eature for SMM.

\n" = "TRUE - SMM uses static page table for all memory.
\n" = "FALSE - SMM uses static page table for below 4G memory and use = on-demand paging for above 4G memory.
" =20 @@ -217,9 +216,8 @@ = "and the memory occupied by page table is protected by pa= ge table itself as read-only.
\n" = "In X64 build, it cannot be enabled at the same time with= SMM profile feature (PcdCpuSmmProfileEnable).
\n" = "In X64 build, it could not be enabled also at the same t= ime with heap guard feature for SMM
\n" - = "(PcdHeapGuardPropertyMask in MdeModulePkg).
\n" = "In IA32 build, page table memory is not marked as read-o= nly when either SMM profile feature (PcdCpuSmmProfileEnable)
\n" - = "or heap guard feature for SMM (PcdHeapGuardPropertyMask = in MdeModulePkg) is enabled.
\n" + = "or heap guard feature for SMM is enabled.
\n" = "TRUE - Access to non-SMRAM memory is restricted to rese= rved, runtime and ACPI NVS type after SmmReadyToLock.
\n" = "FALSE - Access to any type of non-SMRAM memory after Smm= ReadyToLock is allowed.
" =20 @@ -266,13 +264,13 @@ #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuStackSwitchExceptionList_PROMP= T #language en-US "Specify exception vectors which need switching stack." =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuStackSwitchExceptionList_HELP = #language en-US "List of exception vectors which need switching stack.\n" - = "This PCD will only take into effect if PcdCpuStackGuard i= s enabled.n" + = "This PCD will only take into effect if the CPU Stack Guar= d is enabled.n" = "By default exception #DD(8), #PF(14) are supported.n" =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuKnownGoodStackSize_PROMPT #la= nguage en-US "Specify size of good stack of exception which need switching = stack." =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuKnownGoodStackSize_HELP #lang= uage en-US "Size of good stack for an exception.\n" - = "This PCD will only take into effect if PcdCpuStackGuard is enab= led.\n" + = "This PCD will only take into effect if the CPU Stack Guard is e= nabled.\n" =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuCoreCrystalClockFrequency_PROM= PT #language en-US "Specifies CPUID Leaf 0x15 Time Stamp Counter and Nomin= al Core Crystal Clock Frequency." =20 --=20 2.42.0.windows.1 -=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 (#108172): https://edk2.groups.io/g/devel/message/108172 Mute This Topic: https://groups.io/mt/101064092/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- From nobody Sat May 11 07:38:29 2024 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+108173+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+108173+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437557; cv=none; d=zohomail.com; s=zohoarc; b=QW86ZSKRG15gANyhREf6z9AQrihBGyLohsHhqMhJRm4vXuw9rDrjd6JoUYvw3Y+CIwJTIsmCEmV7NkHx1b+0ALq+VvhGbJqnEWH04b4sFbMW60ilcKWZaAZtnAe5gmIOJ3QhdKZbcleu4GL01TYgrwdSsdquvz/ol9/kIenlquU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437557; 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=rfwfOdvDYO5XJGqJ55aHRf36GzXc/LLedIXF+7NNKrA=; b=bsCZrTeD2PVf2nZ11mfmw4xZG1j5JAXbLmvMWePcd8TH86r7Kx7BVslQqg4IEw0ADstrOM+3Sa4CAXPFhfm0AFpaBLJbvQamySyoF21y6BGMYzKG2J4MUC8h0BSg9KOcV4uEIDbCEOMpwz9jqzwZZ33F6mpyogS/olTUySc3VZY= 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+108173+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 1693437557882340.6523087964441; Wed, 30 Aug 2023 16:19:17 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=bvMrRHuTR4NUpNhEvGRH5go3RbSHxRcOyEAMCDVzoec=; 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=1693437557; v=1; b=gwVtIqZUiTCw0CnSxXnZGcMOPEze+l4g0oLLWbbJ14SUvNSbbMFoQzAPy+ofbzYLQTvB6k3Y x0n1M/4IuHb01tGzPrEnNQlWGSIZDpMey+6/q8wZJpvrAdo9fBoavF+B+6+6gCeSff+Oe6Gzy4s r5IT9aO9ql8loRo+R7qeLyxg= X-Received: by 127.0.0.2 with SMTP id 4AXdYY1788612x9MJd10HldS; Wed, 30 Aug 2023 16:19:17 -0700 X-Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web11.4960.1693437557024411516 for ; Wed, 30 Aug 2023 16:19:17 -0700 X-Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-68a529e1974so149903b3a.3 for ; Wed, 30 Aug 2023 16:19:16 -0700 (PDT) X-Gm-Message-State: 9VGF8uIyqR0c51hvroMC5wjDx1787277AA= X-Google-Smtp-Source: AGHT+IEjdoiLB7vh0bKeS3iXOXFYG7xw4LW9gXU1/h6XbEvRve/3MyAD9QBWCM9WhoL5+MUfPFnHkw== X-Received: by 2002:a05:6a20:1447:b0:147:5ab9:8496 with SMTP id a7-20020a056a20144700b001475ab98496mr4352343pzi.55.1693437556210; Wed, 30 Aug 2023 16:19:16 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:15 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 19/26] MdeModulePkg: Use GetMemoryProtectionsLib instead of Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:27 -0700 Message-ID: <20230830231851.779-20-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437559037100076 Content-Type: text/plain; charset="utf-8" Replace references to the memory protection PCDs to instead check the platform protections via GetMemoryProtectionsLib. Because the protection profile is equivalent to the PCD settings, this updated does not cause a torn state. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 4 +- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 46 ++++++++------ MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +- MdeModulePkg/Core/Dxe/Mem/Pool.c | 4 +- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 67 +++++++++++--------- MdeModulePkg/Core/PiSmmCore/HeapGuard.c | 29 ++++----- MdeModulePkg/Core/PiSmmCore/Pool.c | 4 +- MdeModulePkg/Core/Dxe/DxeMain.h | 1 + MdeModulePkg/Core/Dxe/DxeMain.inf | 8 +-- MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 1 + MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf | 4 +- 11 files changed, 87 insertions(+), 83 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dx= e/DxeMain/DxeMain.c index 0e0f9769b99d..66cb2fcf2ff7 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -256,10 +256,12 @@ DxeMain ( Status =3D InitializeCpuExceptionHandlers (VectorInfoList); ASSERT_EFI_ERROR (Status); =20 + PopulateMpsGlobal (); + // // Setup Stack Guard // - if (PcdGetBool (PcdCpuStackGuard)) { + if (gMps.Dxe.CpuStackGuardEnabled) { Status =3D InitializeSeparateExceptionStacks (NULL, NULL); ASSERT_EFI_ERROR (Status); } diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/= Mem/HeapGuard.c index 0c0ca61872b4..59d8f36c89b7 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -553,7 +553,7 @@ UnsetGuardPage ( // memory. // Attributes =3D 0; - if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & (1 << EfiConventionalMe= mory)) !=3D 0) { + if (gMps.Dxe.ExecutionProtection.EnabledForType[EfiConventionalMemory]) { Attributes |=3D EFI_MEMORY_XP; } =20 @@ -590,38 +590,48 @@ IsMemoryTypeToGuard ( IN UINT8 PageOrPool ) { - UINT64 TestBit; + UINT32 MpsMemoryType; UINT64 ConfigBit; =20 if (AllocateType =3D=3D AllocateAddress) { return FALSE; } =20 - if ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) =3D=3D 0) { + ConfigBit =3D gMps.Dxe.HeapGuard.PageGuardEnabled ? GUARD_HEAP_TYPE_PAG= E : 0; + ConfigBit |=3D gMps.Dxe.HeapGuard.PoolGuardEnabled ? GUARD_HEAP_TYPE_POO= L : 0; + ConfigBit |=3D gMps.Dxe.HeapGuard.FreedMemoryGuardEnabled ? GUARD_HEAP_T= YPE_FREED : 0; + + if ((PageOrPool & ConfigBit) =3D=3D 0) { return FALSE; } =20 - if (PageOrPool =3D=3D GUARD_HEAP_TYPE_POOL) { - ConfigBit =3D PcdGet64 (PcdHeapGuardPoolType); - } else if (PageOrPool =3D=3D GUARD_HEAP_TYPE_PAGE) { - ConfigBit =3D PcdGet64 (PcdHeapGuardPageType); - } else { - ConfigBit =3D (UINT64)-1; + if (((PageOrPool & GUARD_HEAP_TYPE_FREED) !=3D 0) && gMps.Dxe.HeapGuard.= FreedMemoryGuardEnabled) { + return TRUE; } =20 if ((UINT32)MemoryType >=3D MEMORY_TYPE_OS_RESERVED_MIN) { - TestBit =3D BIT63; + MpsMemoryType =3D OS_RESERVED_MPS_MEMORY_TYPE; } else if ((UINT32)MemoryType >=3D MEMORY_TYPE_OEM_RESERVED_MIN) { - TestBit =3D BIT62; + MpsMemoryType =3D OEM_RESERVED_MPS_MEMORY_TYPE; } else if (MemoryType < EfiMaxMemoryType) { - TestBit =3D LShiftU64 (1, MemoryType); + MpsMemoryType =3D MemoryType; } else if (MemoryType =3D=3D EfiMaxMemoryType) { - TestBit =3D (UINT64)-1; + return (((PageOrPool & GUARD_HEAP_TYPE_PAGE) !=3D 0) && IS_DXE_PAGE_GU= ARD_ACTIVE) || + (((PageOrPool & GUARD_HEAP_TYPE_POOL) !=3D 0) && IS_DXE_POOL_GU= ARD_ACTIVE) || + (((PageOrPool & GUARD_HEAP_TYPE_FREED) !=3D 0) && gMps.Dxe.Heap= Guard.FreedMemoryGuardEnabled); } else { - TestBit =3D 0; + return FALSE; } =20 - return ((ConfigBit & TestBit) !=3D 0); + if (((PageOrPool & GUARD_HEAP_TYPE_PAGE) !=3D 0) && gMps.Dxe.PageGuard.E= nabledForType[MpsMemoryType]) { + return TRUE; + } + + if (((PageOrPool & GUARD_HEAP_TYPE_POOL) !=3D 0) && gMps.Dxe.PoolGuard.E= nabledForType[MpsMemoryType]) { + return TRUE; + } + + return FALSE; } =20 /** @@ -835,7 +845,7 @@ AdjustMemoryS ( // indicated to put the pool near the Tail Guard, we need extra bytes to // make sure alignment of the returned pool address. // - if ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) =3D=3D 0) { + if (gMps.Dxe.HeapGuard.GuardAlignedToTail) { SizeRequested =3D ALIGN_VALUE (SizeRequested, 8); } =20 @@ -1019,7 +1029,7 @@ AdjustPoolHeadA ( IN UINTN Size ) { - if ((Memory =3D=3D 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != =3D 0)) { + if ((Memory =3D=3D 0) || (!gMps.Dxe.HeapGuard.GuardAlignedToTail)) { // // Pool head is put near the head Guard // @@ -1050,7 +1060,7 @@ AdjustPoolHeadF ( IN UINTN Size ) { - if ((Memory =3D=3D 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != =3D 0)) { + if ((Memory =3D=3D 0) || (!gMps.Dxe.HeapGuard.GuardAlignedToTail)) { // // Pool head is put near the head Guard // diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/P= age.c index 41af50b3d5ab..5cdc2b0c1927 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -181,7 +181,7 @@ CoreAddRange ( // used for other purposes. // if ((Type =3D=3D EfiConventionalMemory) && (Start =3D=3D 0) && (End >=3D= EFI_PAGE_SIZE - 1)) { - if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0) { + if (!gMps.Dxe.NullPointerDetection.Enabled) { SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0); } } diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/P= ool.c index 716dd045f9fd..ae1e8b67db10 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -385,7 +385,7 @@ CoreAllocatePoolI ( // =20 HasPoolTail =3D !(NeedGuard && - ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) =3D=3D 0)); + gMps.Dxe.HeapGuard.GuardAlignedToTail); PageAsPool =3D (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) && !mOnGuardi= ng); =20 // @@ -717,7 +717,7 @@ CoreFreePoolI ( IsGuarded =3D IsPoolTypeToGuard (Head->Type) && IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head); HasPoolTail =3D !(IsGuarded && - ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) =3D=3D 0)); + gMps.Dxe.HeapGuard.GuardAlignedToTail); PageAsPool =3D (Head->Signature =3D=3D POOLPAGE_HEAD_SIGNATURE); =20 if (HasPoolTail) { diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 94ed3111688b..215a9f254065 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -9,7 +9,7 @@ 2) This policy is applied only if the UEFI image meets the page alignment requirement. 3) This policy is applied only if the Source UEFI image matches the - PcdImageProtectionPolicy definition. + Image Protection Policy definition. 4) This policy is not applied to the non-PE image region. =20 The DxeCore calls CpuArchProtocol->SetMemoryAttributes() to protect @@ -60,7 +60,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) =20 -UINT32 mImageProtectionPolicy; +STATIC BOOLEAN mIsExecutionProtectionActive =3D FALSE; + +STATIC BOOLEAN mIsPageOrPoolGuardActive =3D FALSE; =20 extern LIST_ENTRY mGcdMemorySpaceMap; =20 @@ -149,11 +151,13 @@ GetProtectionPolicyFromImageType ( IN UINT32 ImageType ) { - if ((ImageType & mImageProtectionPolicy) =3D=3D 0) { - return DO_NOT_PROTECT; - } else { + if (((ImageType =3D=3D IMAGE_UNKNOWN) && gMps.Dxe.ImageProtection.Protec= tImageFromUnknown) || + ((ImageType =3D=3D IMAGE_FROM_FV) && gMps.Dxe.ImageProtection.Protec= tImageFromFv)) + { return PROTECT_IF_ALIGNED_ELSE_ALLOW; } + + return DO_NOT_PROTECT; } =20 /** @@ -611,7 +615,7 @@ UnprotectUefiImage ( IMAGE_PROPERTIES_RECORD *ImageRecord; LIST_ENTRY *ImageRecordLink; =20 - if (PcdGet32 (PcdImageProtectionPolicy) !=3D 0) { + if (IS_DXE_IMAGE_PROTECTION_ACTIVE) { for (ImageRecordLink =3D mProtectedImageRecordList.ForwardLink; ImageRecordLink !=3D &mProtectedImageRecordList; ImageRecordLink =3D ImageRecordLink->ForwardLink) @@ -648,21 +652,23 @@ GetPermissionAttributeForMemoryType ( IN EFI_MEMORY_TYPE MemoryType ) { - UINT64 TestBit; + UINT32 TestMemoryType; =20 if ((UINT32)MemoryType >=3D MEMORY_TYPE_OS_RESERVED_MIN) { - TestBit =3D BIT63; + TestMemoryType =3D OS_RESERVED_MPS_MEMORY_TYPE; } else if ((UINT32)MemoryType >=3D MEMORY_TYPE_OEM_RESERVED_MIN) { - TestBit =3D BIT62; + TestMemoryType =3D OEM_RESERVED_MPS_MEMORY_TYPE; + } else if (MemoryType >=3D EfiMaxMemoryType) { + return EFI_MEMORY_XP; } else { - TestBit =3D LShiftU64 (1, MemoryType); + TestMemoryType =3D MemoryType; } =20 - if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & TestBit) !=3D 0) { + if (gMps.Dxe.ExecutionProtection.EnabledForType[TestMemoryType]) { return EFI_MEMORY_XP; - } else { - return 0; } + + return 0; } =20 /** @@ -772,7 +778,7 @@ MergeMemoryMapForProtectionPolicy ( =20 /** Remove exec permissions from all regions whose type is identified by - PcdDxeNxMemoryProtectionPolicy. + the DXE Execution Protection Policy. **/ STATIC VOID @@ -827,7 +833,7 @@ InitializeDxeNxMemoryProtectionPolicy ( ASSERT_EFI_ERROR (Status); =20 StackBase =3D 0; - if (PcdGetBool (PcdCpuStackGuard)) { + if (gMps.Dxe.CpuStackGuardEnabled) { // // Get the base of stack from Hob. // @@ -885,7 +891,7 @@ InitializeDxeNxMemoryProtectionPolicy ( // enabled. // if ((MemoryMapEntry->PhysicalStart =3D=3D 0) && - (PcdGet8 (PcdNullPointerDetectionPropertyMask) !=3D 0)) + (gMps.Dxe.NullPointerDetection.Enabled)) { ASSERT (MemoryMapEntry->NumberOfPages > 0); SetUefiImageMemoryAttributes ( @@ -903,7 +909,7 @@ InitializeDxeNxMemoryProtectionPolicy ( ((StackBase >=3D MemoryMapEntry->PhysicalStart) && (StackBase < MemoryMapEntry->PhysicalStart + LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT))) && - PcdGetBool (PcdCpuStackGuard)) + gMps.Dxe.CpuStackGuardEnabled) { SetUefiImageMemoryAttributes ( StackBase, @@ -1024,7 +1030,7 @@ MemoryProtectionCpuArchProtocolNotify ( // // Apply the memory protection policy on non-BScode/RTcode regions. // - if (PcdGet64 (PcdDxeNxMemoryProtectionPolicy) !=3D 0) { + if (IS_DXE_EXECUTION_PROTECTION_ACTIVE) { InitializeDxeNxMemoryProtectionPolicy (); } =20 @@ -1036,7 +1042,7 @@ MemoryProtectionCpuArchProtocolNotify ( // Mark the HOB list XP and RO. ProtectHobList (); =20 - if (mImageProtectionPolicy =3D=3D 0) { + if (!IS_DXE_IMAGE_PROTECTION_ACTIVE) { goto Done; } =20 @@ -1099,7 +1105,7 @@ MemoryProtectionExitBootServicesCallback ( // delay setting protections on RT code pages until after SetVirtualAddr= essMap(). // OS may set protection on RT based upon EFI_MEMORY_ATTRIBUTES_TABLE la= ter. // - if (mImageProtectionPolicy !=3D 0) { + if (IS_DXE_IMAGE_PROTECTION_ACTIVE) { for (Link =3D gRuntime->ImageHead.ForwardLink; Link !=3D &gRuntime->Im= ageHead; Link =3D Link->ForwardLink) { RuntimeImage =3D BASE_CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link); SetUefiImageMemoryAttributes ((UINT64)(UINTN)RuntimeImage->ImageBase= , ALIGN_VALUE (RuntimeImage->ImageSize, EFI_PAGE_SIZE), 0); @@ -1173,19 +1179,20 @@ CoreInitializeMemoryProtection ( EFI_EVENT EndOfDxeEvent; VOID *Registration; =20 - mImageProtectionPolicy =3D PcdGet32 (PcdImageProtectionPolicy); + mIsExecutionProtectionActive =3D IS_DXE_EXECUTION_PROTECTION_ACTIVE; + mIsPageOrPoolGuardActive =3D IS_DXE_PAGE_GUARD_ACTIVE || IS_DXE_POOL= _GUARD_ACTIVE; =20 InitializeListHead (&mProtectedImageRecordList); =20 // - // Sanity check the PcdDxeNxMemoryProtectionPolicy setting: + // Sanity check the DXE NX protection policy setting: // - code regions should have no EFI_MEMORY_XP attribute // - EfiConventionalMemory and EfiBootServicesData should use the // same attribute // - ASSERT ((GetPermissionAttributeForMemoryType (EfiBootServicesCode) & EFI= _MEMORY_XP) =3D=3D 0); - ASSERT ((GetPermissionAttributeForMemoryType (EfiRuntimeServicesCode) & = EFI_MEMORY_XP) =3D=3D 0); - ASSERT ((GetPermissionAttributeForMemoryType (EfiLoaderCode) & EFI_MEMOR= Y_XP) =3D=3D 0); + ASSERT (!gMps.Dxe.ExecutionProtection.EnabledForType[EfiLoaderCode]); + ASSERT (!gMps.Dxe.ExecutionProtection.EnabledForType[EfiBootServicesCode= ]); + ASSERT (!gMps.Dxe.ExecutionProtection.EnabledForType[EfiRuntimeServicesC= ode]); ASSERT ( GetPermissionAttributeForMemoryType (EfiBootServicesData) =3D=3D GetPermissionAttributeForMemoryType (EfiConventionalMemory) @@ -1213,9 +1220,7 @@ CoreInitializeMemoryProtection ( // // Register a callback to disable NULL pointer detection at EndOfDxe // - if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) - =3D=3D (BIT0|BIT7)) - { + if (gMps.Dxe.NullPointerDetection.Enabled && gMps.Dxe.NullPointerDetecti= on.DisableEndOfDxe) { Status =3D CoreCreateEventEx ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY, @@ -1279,7 +1284,7 @@ ApplyMemoryProtectionPolicy ( UINT64 NewAttributes; =20 // - // The policy configured in PcdDxeNxMemoryProtectionPolicy + // The policy configured in DXE Execution Protection Policy // does not apply to allocations performed in SMM mode. // if (IsInSmm ()) { @@ -1298,7 +1303,7 @@ ApplyMemoryProtectionPolicy ( // // Check if a DXE memory protection policy has been configured // - if (PcdGet64 (PcdDxeNxMemoryProtectionPolicy) =3D=3D 0) { + if (!mIsExecutionProtectionActive) { return EFI_SUCCESS; } =20 @@ -1306,7 +1311,7 @@ ApplyMemoryProtectionPolicy ( // Don't overwrite Guard pages, which should be the first and/or last pa= ge, // if any. // - if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL)) { + if (mIsPageOrPoolGuardActive) { if (IsGuardPage (Memory)) { Memory +=3D EFI_PAGE_SIZE; Length -=3D EFI_PAGE_SIZE; diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c b/MdeModulePkg/Core/Pi= SmmCore/HeapGuard.c index 25310122ca1b..eac38e699c30 100644 --- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c +++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c @@ -592,36 +592,29 @@ IsMemoryTypeToGuard ( IN UINT8 PageOrPool ) { - UINT64 TestBit; UINT64 ConfigBit; =20 - if ( ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) =3D=3D 0) + ConfigBit =3D gMps.Mm.HeapGuard.PageGuardEnabled ? GUARD_HEAP_TYPE_PAGE= : 0; + ConfigBit |=3D gMps.Mm.HeapGuard.PoolGuardEnabled ? GUARD_HEAP_TYPE_POOL= : 0; + + if ( ((ConfigBit & PageOrPool) =3D=3D 0) || mOnGuarding || (AllocateType =3D=3D AllocateAddress)) { return FALSE; } =20 - ConfigBit =3D 0; - if ((PageOrPool & GUARD_HEAP_TYPE_POOL) !=3D 0) { - ConfigBit |=3D PcdGet64 (PcdHeapGuardPoolType); - } - - if ((PageOrPool & GUARD_HEAP_TYPE_PAGE) !=3D 0) { - ConfigBit |=3D PcdGet64 (PcdHeapGuardPageType); - } - if ((MemoryType =3D=3D EfiRuntimeServicesData) || (MemoryType =3D=3D EfiRuntimeServicesCode)) { - TestBit =3D LShiftU64 (1, MemoryType); + return (((PageOrPool & GUARD_HEAP_TYPE_PAGE) !=3D 0) && gMps.Mm.PageGu= ard.EnabledForType[MemoryType]) || + (((PageOrPool & GUARD_HEAP_TYPE_POOL) !=3D 0) && gMps.Mm.PoolGu= ard.EnabledForType[MemoryType]); } else if (MemoryType =3D=3D EfiMaxMemoryType) { - TestBit =3D (UINT64)-1; - } else { - TestBit =3D 0; + return (((PageOrPool & GUARD_HEAP_TYPE_PAGE) !=3D 0) && IS_MM_PAGE_GUA= RD_ACTIVE) || + (((PageOrPool & GUARD_HEAP_TYPE_POOL) !=3D 0) && IS_MM_POOL_GUA= RD_ACTIVE); } =20 - return ((ConfigBit & TestBit) !=3D 0); + return FALSE; } =20 /** @@ -951,7 +944,7 @@ AdjustPoolHeadA ( IN UINTN Size ) { - if ((Memory =3D=3D 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != =3D 0)) { + if ((Memory =3D=3D 0) || (!gMps.Mm.HeapGuard.GuardAlignedToTail)) { // // Pool head is put near the head Guard // @@ -977,7 +970,7 @@ AdjustPoolHeadF ( IN EFI_PHYSICAL_ADDRESS Memory ) { - if ((Memory =3D=3D 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != =3D 0)) { + if ((Memory =3D=3D 0) || (!gMps.Mm.HeapGuard.GuardAlignedToTail)) { // // Pool head is put near the head Guard // diff --git a/MdeModulePkg/Core/PiSmmCore/Pool.c b/MdeModulePkg/Core/PiSmmCo= re/Pool.c index e1ff40a8ea55..991efaf33bdd 100644 --- a/MdeModulePkg/Core/PiSmmCore/Pool.c +++ b/MdeModulePkg/Core/PiSmmCore/Pool.c @@ -258,7 +258,7 @@ SmmInternalAllocatePool ( =20 NeedGuard =3D IsPoolTypeToGuard (PoolType); HasPoolTail =3D !(NeedGuard && - ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) =3D=3D 0)); + gMps.Mm.HeapGuard.GuardAlignedToTail); =20 // // Adjust the size by the pool header & tail overhead @@ -392,7 +392,7 @@ SmmInternalFreePool ( MemoryGuarded =3D IsHeapGuardEnabled () && IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)FreePoolHd= r); HasPoolTail =3D !(MemoryGuarded && - ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) =3D=3D 0)); + gMps.Mm.HeapGuard.GuardAlignedToTail); =20 if (HasPoolTail) { PoolTail =3D HEAD_TO_TAIL (&FreePoolHdr->Header); diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 43daa037be44..8b8b97666f38 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -84,6 +84,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 // // attributes for reserved memory before it is promoted to system memory diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeM= ain.inf index 6c896a0e7f0f..ddbbee5f68ce 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -94,6 +94,7 @@ [LibraryClasses] DebugAgentLib CpuExceptionHandlerLib PcdLib + GetMemoryProtectionsLib =20 [Guids] gEfiEventMemoryMapChangeGuid ## PRODUCES ##= Event @@ -179,13 +180,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileMemoryType = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask = ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdFwVolDxeMaxEncapsulationDepth = ## CONSUMES gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel = ## CONSUMES =20 diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/Pi= SmmCore/PiSmmCore.h index b8a490a8c3b5..2fabed0670e0 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h @@ -55,6 +55,7 @@ #include #include #include +#include =20 #include "PiSmmCorePrivateData.h" #include "HeapGuard.h" diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/= PiSmmCore/PiSmmCore.inf index 3df44b38f13c..4586ec39d7c7 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -61,6 +61,7 @@ [LibraryClasses] HobLib SmmMemLib SafeIntLib + GetMemoryProtectionsLib =20 [Protocols] gEfiDxeSmmReadyToLockProtocolGuid ## UNDEFINED # SmiHandlerR= egister @@ -94,9 +95,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdSmiHandlerProfilePropertyMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable ##= CONSUMES =20 [Guids] --=20 2.42.0.windows.1 -=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 (#108173): https://edk2.groups.io/g/devel/message/108173 Mute This Topic: https://groups.io/mt/101064093/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- From nobody Sat May 11 07:38:29 2024 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+108174+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+108174+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437558; cv=none; d=zohomail.com; s=zohoarc; b=fUxkrSSTTV8Up0uU5beUEPwM4bRWe5lUFzI5XNqSawn43zRJdkdoIHkGH5QRkdZWQXKzAsNnyMT8nhx6tPUYYxIuZqJHiHQwQ695GDH2uSH5BOLrO8bA3d/EfqEs/WSWsnqH7vPUmLIPh9FeV3llzsnvrETsoezB3KOCD91e2mc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437558; 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=aTZgynY42UU2DEnq/Ocj2mxo3Mb47eWW8zf7bUBxMzE=; b=KGZMJkZtBEdBQ4aZvO9bBXasClR3rPuc1dgVjr09WBk6cTTacg95TjB5V3DB2llLO2E7zQC+MO9nFsKTxpMRGV6Gj2jLiKVo5dwybE9rwxSOb/jwKzJuZjBjXmoGGPmHJstwVzAQLDUn2iPVZk+WSZFBdB0jRTs/w3V1nOUkYo0= 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+108174+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 169343755894432.23033957123471; Wed, 30 Aug 2023 16:19:18 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rLrcaUK+m7zAGfccwSBPE2kWgRpvxToyeES7pOfNNQg=; 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=1693437558; v=1; b=h5HvYbitECafOosS5gWfeT0bo1Qst8Hzk8cAGW0wfb2gTphxORWl5UDcQFQJ4FxbII6QwXTz NTOmPk60D4W7hlB7H49fEbuJXd3dwcgQ7fx7/as+/gsAG4ZJV/LwmFSloj7dVglAvNBF8M5GYiH dgMc9vqSNlz2xZsHvD46ndQY= X-Received: by 127.0.0.2 with SMTP id JdtaYY1788612x82iku7dnQX; Wed, 30 Aug 2023 16:19:18 -0700 X-Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mx.groups.io with SMTP id smtpd.web10.4872.1693437558053800868 for ; Wed, 30 Aug 2023 16:19:18 -0700 X-Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-56963f2e48eso251453a12.1 for ; Wed, 30 Aug 2023 16:19:18 -0700 (PDT) X-Gm-Message-State: MC0ciztyRJTwPo29rSh0xsYNx1787277AA= X-Google-Smtp-Source: AGHT+IEJKE0QOJ/qfStwJW5BYUVmO08rItiVUnCUROKQ09zwCyZqcxBIS7d77rBX+W5g/cgo2qrpGg== X-Received: by 2002:a05:6a20:5483:b0:14c:fadb:4e5e with SMTP id i3-20020a056a20548300b0014cfadb4e5emr4329823pzk.5.1693437557217; Wed, 30 Aug 2023 16:19:17 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:16 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 20/26] MdeModulePkg: Add Additional Profiles to SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:28 -0700 Message-ID: <20230830231851.779-21-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437560081100081 Content-Type: text/plain; charset="utf-8" Now that the EDK2 tree uses GetMemoryProtectionsLib to query the platform memory protection settings, we can add additional profiles to SetMemoryProtectionsLib to give plaforms more options for setting memory protections. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c | 4= 17 +++++++++++++++++++- MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h | = 7 + 2 files changed, 422 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.c b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtection= sLib.c index 13032ec80fbf..40d4f3081133 100644 --- a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c @@ -28,6 +28,227 @@ typedef struct { // DXE PROFILE DEFINITIONS // ///////////////////////////// =20 +// +// A memory profile with strict settings ideal for development scenarios. +// +#define DXE_MEMORY_PROTECTION_SETTINGS_DEBUG \ +{ \ + DXE_MEMORY_PROTECTION_SIGNATURE, \ + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + TRUE, /* Stack Guard */ \ + TRUE, /* Stack Execution Protection */ \ + { /* NULL Pointer Detection */ \ + .Enabled =3D TRUE, \ + .DisableEndOfDxe =3D FALSE, \ + .NonstopModeEnabled =3D TRUE \ + }, \ + { /* Image Protection */ \ + .ProtectImageFromUnknown =3D TRUE, \ + .ProtectImageFromFv =3D TRUE \ + }, \ + { /* Execution Protection */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D TRUE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D TRUE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D TRUE, \ + [EfiUnusableMemory] =3D TRUE, \ + [EfiACPIReclaimMemory] =3D TRUE, \ + [EfiACPIMemoryNVS] =3D TRUE, \ + [EfiMemoryMappedIO] =3D TRUE, \ + [EfiMemoryMappedIOPortSpace] =3D TRUE, \ + [EfiPalCode] =3D TRUE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D TRUE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D TRUE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D TRUE \ + } \ + }, \ + { /* Heap Guard */ \ + .PageGuardEnabled =3D TRUE, \ + .PoolGuardEnabled =3D TRUE, \ + .FreedMemoryGuardEnabled =3D FALSE, \ + .NonstopModeEnabled =3D TRUE, \ + .GuardAlignedToTail =3D FALSE \ + }, \ + { /* Pool Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D TRUE, \ + [EfiLoaderCode] =3D TRUE, \ + [EfiLoaderData] =3D TRUE, \ + [EfiBootServicesCode] =3D TRUE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D TRUE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D TRUE, \ + [EfiACPIReclaimMemory] =3D TRUE, \ + [EfiACPIMemoryNVS] =3D TRUE, \ + [EfiMemoryMappedIO] =3D TRUE, \ + [EfiMemoryMappedIOPortSpace] =3D TRUE, \ + [EfiPalCode] =3D TRUE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D TRUE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D TRUE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D TRUE \ + } \ + }, \ + { /* Page Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D TRUE, \ + [EfiLoaderCode] =3D TRUE, \ + [EfiLoaderData] =3D TRUE, \ + [EfiBootServicesCode] =3D TRUE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D TRUE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D TRUE, \ + [EfiACPIReclaimMemory] =3D TRUE, \ + [EfiACPIMemoryNVS] =3D TRUE, \ + [EfiMemoryMappedIO] =3D TRUE, \ + [EfiMemoryMappedIOPortSpace] =3D TRUE, \ + [EfiPalCode] =3D TRUE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D TRUE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D TRUE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D TRUE \ + } \ + } \ +} + +// +// A memory profile recommended for production. Compared to the debug +// settings, this profile removes the pool guards and uses page guards +// for fewer memory types. +// +#define DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE \ +{ \ + DXE_MEMORY_PROTECTION_SIGNATURE, \ + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + TRUE, /* Stack Guard */ \ + TRUE, /* Stack Execution Protection */ \ + { /* NULL Pointer Detection */ \ + .Enabled =3D TRUE, \ + .DisableEndOfDxe =3D FALSE, \ + .NonstopModeEnabled =3D FALSE \ + }, \ + { /* Image Protection */ \ + .ProtectImageFromUnknown =3D FALSE, \ + .ProtectImageFromFv =3D TRUE \ + }, \ + { /* Execution Protection */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D TRUE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D TRUE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D TRUE, \ + [EfiUnusableMemory] =3D TRUE, \ + [EfiACPIReclaimMemory] =3D TRUE, \ + [EfiACPIMemoryNVS] =3D TRUE, \ + [EfiMemoryMappedIO] =3D TRUE, \ + [EfiMemoryMappedIOPortSpace] =3D TRUE, \ + [EfiPalCode] =3D TRUE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D TRUE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D TRUE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D TRUE \ + } \ + }, \ + { /* Heap Guard */ \ + .PageGuardEnabled =3D TRUE, \ + .PoolGuardEnabled =3D FALSE, \ + .FreedMemoryGuardEnabled =3D FALSE, \ + .NonstopModeEnabled =3D FALSE, \ + .GuardAlignedToTail =3D FALSE \ + }, \ + { /* Pool Guard */ \ + 0 \ + }, \ + { /* Page Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D FALSE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D FALSE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D FALSE, \ + [EfiACPIReclaimMemory] =3D FALSE, \ + [EfiACPIMemoryNVS] =3D FALSE, \ + [EfiMemoryMappedIO] =3D FALSE, \ + [EfiMemoryMappedIOPortSpace] =3D FALSE, \ + [EfiPalCode] =3D FALSE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D FALSE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D FALSE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D FALSE \ + } \ + } \ +} + +// +// A memory profile which mirrors DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE +// but doesn't include page guards. +// +#define DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE_NO_PAGE_GUARDS \ +{ \ + DXE_MEMORY_PROTECTION_SIGNATURE, \ + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + TRUE, /* Stack Guard */ \ + TRUE, /* Stack Execution Protection */ \ + { /* NULL Pointer Detection */ \ + .Enabled =3D TRUE, \ + .DisableEndOfDxe =3D FALSE, \ + .NonstopModeEnabled =3D FALSE \ + }, \ + { /* Image Protection */ \ + .ProtectImageFromUnknown =3D FALSE, \ + .ProtectImageFromFv =3D TRUE \ + }, \ + { /* Execution Protection */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D TRUE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D TRUE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D TRUE, \ + [EfiUnusableMemory] =3D TRUE, \ + [EfiACPIReclaimMemory] =3D TRUE, \ + [EfiACPIMemoryNVS] =3D TRUE, \ + [EfiMemoryMappedIO] =3D TRUE, \ + [EfiMemoryMappedIOPortSpace] =3D TRUE, \ + [EfiPalCode] =3D TRUE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D TRUE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D TRUE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D TRUE \ + } \ + }, \ + { /* Heap Guard */ \ + 0 \ + }, \ + { /* Pool Guard */ \ + 0 \ + }, \ + { /* Page Guard */ \ + 0 \ + } \ +} + // // A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec // @@ -121,10 +342,146 @@ typedef struct { } = \ } =20 +// +// A memory profile which disables all DXE memory protection settings. +// +#define DXE_MEMORY_PROTECTION_SETTINGS_OFF \ +{ \ + DXE_MEMORY_PROTECTION_SIGNATURE, \ + DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + FALSE, /* Stack Guard */ \ + FALSE, /* Stack Execution Protection */ \ + { /* NULL Pointer Detection */ \ + 0 \ + }, \ + { /* Image Protection */ \ + 0 \ + }, \ + { /* Execution Protection */ \ + 0 \ + }, \ + { /* Heap Guard */ \ + 0 \ + }, \ + { /* Pool Guard */ \ + 0 \ + }, \ + { /* Page Guard */ \ + 0 \ + } \ +} + //////////////////////////// // MM PROFILE DEFINITIONS // //////////////////////////// =20 +// +// A memory profile ideal for development scenarios. +// +#define MM_MEMORY_PROTECTION_SETTINGS_DEBUG \ +{ \ + MM_MEMORY_PROTECTION_SIGNATURE, \ + MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + { /* NULL Pointer Detection */ \ + .Enabled =3D TRUE, \ + .NonstopModeEnabled =3D TRUE \ + }, \ + { /* Heap Guard */ \ + .PageGuardEnabled =3D TRUE, \ + .PoolGuardEnabled =3D TRUE, \ + .NonstopModeEnabled =3D TRUE, \ + .GuardAlignedToTail =3D FALSE \ + }, \ + { /* Pool Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D FALSE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D FALSE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D FALSE, \ + [EfiACPIReclaimMemory] =3D FALSE, \ + [EfiACPIMemoryNVS] =3D FALSE, \ + [EfiMemoryMappedIO] =3D FALSE, \ + [EfiMemoryMappedIOPortSpace] =3D FALSE, \ + [EfiPalCode] =3D FALSE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D FALSE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D FALSE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D FALSE \ + } \ + }, \ + { /* Page Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D FALSE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D FALSE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D FALSE, \ + [EfiACPIReclaimMemory] =3D FALSE, \ + [EfiACPIMemoryNVS] =3D FALSE, \ + [EfiMemoryMappedIO] =3D FALSE, \ + [EfiMemoryMappedIOPortSpace] =3D FALSE, \ + [EfiPalCode] =3D FALSE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D FALSE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D FALSE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D FALSE \ + } \ + } \ +} + +// +// A memory profile ideal for production scenarios. +// +#define MM_MEMORY_PROTECTION_SETTINGS_PROD_MODE \ +{ \ + MM_MEMORY_PROTECTION_SIGNATURE, \ + MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + { /* NULL Pointer Detection */ \ + .Enabled =3D TRUE, \ + .NonstopModeEnabled =3D FALSE \ + }, \ + { /* Heap Guard */ \ + .PageGuardEnabled =3D TRUE, \ + .PoolGuardEnabled =3D FALSE, \ + .NonstopModeEnabled =3D FALSE, \ + .GuardAlignedToTail =3D FALSE \ + }, \ + { /* Pool Guard */ \ + 0 \ + }, \ + { /* Page Guard */ \ + .EnabledForType =3D { \ + [EfiReservedMemoryType] =3D FALSE, \ + [EfiLoaderCode] =3D FALSE, \ + [EfiLoaderData] =3D FALSE, \ + [EfiBootServicesCode] =3D FALSE, \ + [EfiBootServicesData] =3D TRUE, \ + [EfiRuntimeServicesCode] =3D FALSE, \ + [EfiRuntimeServicesData] =3D TRUE, \ + [EfiConventionalMemory] =3D FALSE, \ + [EfiUnusableMemory] =3D FALSE, \ + [EfiACPIReclaimMemory] =3D FALSE, \ + [EfiACPIMemoryNVS] =3D FALSE, \ + [EfiMemoryMappedIO] =3D FALSE, \ + [EfiMemoryMappedIOPortSpace] =3D FALSE, \ + [EfiPalCode] =3D FALSE, \ + [EfiPersistentMemory] =3D FALSE, \ + [EfiUnacceptedMemoryType] =3D FALSE, \ + [OEM_RESERVED_MPS_MEMORY_TYPE] =3D FALSE, \ + [OS_RESERVED_MPS_MEMORY_TYPE] =3D FALSE \ + } \ + } \ +} + // // A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec // @@ -188,24 +545,80 @@ typedef struct { } = \ } =20 +// +// A memory profile which disables all MM memory protection settings. +// +#define MM_MEMORY_PROTECTION_SETTINGS_OFF \ +{ \ + MM_MEMORY_PROTECTION_SIGNATURE, \ + MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, \ + { /* NULL Pointer Detection */ \ + 0 \ + }, \ + { /* Heap Guard */ \ + 0 \ + }, \ + { /* Pool Guard */ \ + 0 \ + }, \ + { /* Page Guard */ \ + 0 \ + } \ +} + //////////////////////////// // PROFILE CONFIGURATIONS // //////////////////////////// =20 DXE_MEMORY_PROTECTION_PROFILES DxeMemoryProtectionProfiles[DxeMemoryProte= ctionSettingsMax] =3D { - [DxeMemoryProtectionSettingsPcd] =3D { + [DxeMemoryProtectionSettingsDebug] =3D { + .Name =3D "Debug", + .Description =3D "Development profile ideal for debug scenarios", + .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_DEBUG + }, + [DxeMemoryProtectionSettingsRelease] =3D { + .Name =3D "Release", + .Description =3D "Release profile recommended for production scenarios= ", + .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE + }, + [DxeMemoryProtectionSettingsReleaseNoPageGuards] =3D { + .Name =3D "ReleaseNoPageGuards", + .Description =3D "Release profile without page guards recommended for = performance sensitive production scenarios", + .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE_NO_PAGE_GUAR= DS + }, + [DxeMemoryProtectionSettingsPcd] =3D { .Name =3D "Pcd", .Description =3D "Memory protection settings from PCDs", .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PCD }, + [DxeMemoryProtectionSettingsOff] =3D { + .Name =3D "Off", + .Description =3D "Disables all memory protection settings", + .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_OFF + } }; =20 MM_MEMORY_PROTECTION_PROFILES MmMemoryProtectionProfiles[MmMemoryProtecti= onSettingsMax] =3D { - [MmMemoryProtectionSettingsPcd] =3D { + [MmMemoryProtectionSettingsDebug] =3D { + .Name =3D "Debug", + .Description =3D "Development profile ideal for debug scenarios", + .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_DEBUG + }, + [MmMemoryProtectionSettingsRelease] =3D { + .Name =3D "Release", + .Description =3D "Release profile recommended for production scenarios= ", + .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_PROD_MODE + }, + [MmMemoryProtectionSettingsPcd] =3D { .Name =3D "Pcd", .Description =3D "Memory protection settings from PCDs", .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_PCD }, + [MmMemoryProtectionSettingsOff] =3D { + .Name =3D "Off", + .Description =3D "Disables all memory protection settings", + .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_OFF + } }; =20 ///////////////////////////////////// diff --git a/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h b/MdeMo= dulePkg/Include/Library/SetMemoryProtectionsLib.h index 023c987c3c7e..f4665130b0b3 100644 --- a/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h +++ b/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h @@ -17,6 +17,10 @@ typedef struct { } DXE_MEMORY_PROTECTION_PROFILES; =20 typedef enum { + DxeMemoryProtectionSettingsDebug =3D 0, + DxeMemoryProtectionSettingsRelease, + DxeMemoryProtectionSettingsReleaseNoPageGuards, + DxeMemoryProtectionSettingsOff, DxeMemoryProtectionSettingsPcd, DxeMemoryProtectionSettingsMax } DXE_MEMORY_PROTECTION_PROFILE_INDEX; @@ -28,6 +32,9 @@ typedef struct { } MM_MEMORY_PROTECTION_PROFILES; =20 typedef enum { + MmMemoryProtectionSettingsDebug =3D 0, + MmMemoryProtectionSettingsRelease, + MmMemoryProtectionSettingsOff, MmMemoryProtectionSettingsPcd, MmMemoryProtectionSettingsMax } MM_MEMORY_PROTECTION_PROFILE_INDEX; --=20 2.42.0.windows.1 -=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 (#108174): https://edk2.groups.io/g/devel/message/108174 Mute This Topic: https://groups.io/mt/101064094/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- From nobody Sat May 11 07:38:29 2024 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+108175+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+108175+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437559; cv=none; d=zohomail.com; s=zohoarc; b=HybvTxVY8LczrD/1VHp7r71e81HXzou/wk+K0AjrGmZ6WO364XKrOIhD8mqSIQM4RGfxIhSzK+Nj8xPocRGw6gs5R1yexb6ZpjCOVLqHgeEFnb5E3YSDeanN+w3hnWQ93fy8PJyOCEZ/phBHj+Ch9UqzKzxfZc6J+RJf4k6eXcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437559; 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=ZgWNcdUkVDgZKkfB66zAEQFYUmRV4h5AsmZ/Zz/tkYM=; b=c4jw81w2uqW9kGrwZLTF4Yizg0fqmk+KRzkbN2MCmqjrlYgRw4xdSbs9hhiULathHaUWAQt9vTNx2RLXUfMvcbwAmQL8bBF0WS1qFISYqsJkqI8l9kXCpdncNhEUp8oHdDDbndOuUt2dmBTf6HprZOXxX3b6iYe/Z9Z5urkRB64= 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+108175+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 1693437559986652.3134017875614; Wed, 30 Aug 2023 16:19:19 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=QEg6pY3WDqjBbELeY1Pimbj3/w3ftloiLXtNPQ3xyDc=; 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=1693437559; v=1; b=iRDBNac+VB+eZLuufTb+pHUZFV5GwQJRVaycUS49dWIMVAYAQ0VNQUdIxQGx5IT2n9QYV2/D VBZ54wxs4MDl18PBYfZSNfHTdGZgpLOfuueO7UFKxVPDhoaQHdmMLfzUilVpGUHTQlbcf2bqxyH D3CDWPKMAzd7eUn2+jqbuJwc= X-Received: by 127.0.0.2 with SMTP id uhEgYY1788612xFYu9X8FS5k; Wed, 30 Aug 2023 16:19:19 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web11.4963.1693437559186418376 for ; Wed, 30 Aug 2023 16:19:19 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68a56401b9aso164541b3a.1 for ; Wed, 30 Aug 2023 16:19:19 -0700 (PDT) X-Gm-Message-State: eXJWUjjB5XTv0Aen2rN5MSE1x1787277AA= X-Google-Smtp-Source: AGHT+IFv1k8Bd1IHROgvpLB4KKpEvYg2gsxl0NdYTCOvZAOrSbhUGkbK2axRuvDX3rr9EMVFFQ3a9g== X-Received: by 2002:a05:6a00:21d6:b0:68b:da4b:4620 with SMTP id t22-20020a056a0021d600b0068bda4b4620mr4139697pfj.31.1693437558329; Wed, 30 Aug 2023 16:19:18 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:17 -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 v3 21/26] OvmfPkg: Enable Choosing Memory Protection Profile via QemuCfg Date: Wed, 30 Aug 2023 16:18:29 -0700 Message-ID: <20230830231851.779-22-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437562125100090 Content-Type: text/plain; charset="utf-8" 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\ufffd\ufffdhne --- .../PeilessStartupLib/PeilessStartup.c | 60 +++++++++++++-- .../PeilessStartupLib/X64/VirtualMemory.c | 13 +--- OvmfPkg/Library/PlatformInitLib/Platform.c | 15 ---- .../QemuFwCfgSimpleParser.c | 11 +++ OvmfPkg/PlatformPei/IntelTdx.c | 2 - OvmfPkg/PlatformPei/Platform.c | 74 +++++++++++++------ OvmfPkg/TdxDxe/TdxDxe.c | 7 +- OvmfPkg/Bhyve/PlatformPei/PlatformPei.inf | 1 - OvmfPkg/Include/Library/PlatformInitLib.h | 13 ---- .../Library/QemuFwCfgSimpleParserLib.h | 8 ++ .../PeilessStartupLib/PeilessStartupLib.inf | 1 - OvmfPkg/PlatformCI/PlatformBuildLib.py | 8 ++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 - OvmfPkg/TdxDxe/TdxDxe.inf | 1 - 14 files changed, 135 insertions(+), 80 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index cf645aad3246..8626b00da964 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -28,6 +28,12 @@ =20 #define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f)) =20 +#define DXE_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \ + "opt/org.tianocore/DxeMemoryProtectionProfile" + +#define MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \ + "opt/org.tianocore/MmMemoryProtectionProfile" + EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D { { EfiACPIMemoryNVS, 0x004 }, { EfiACPIReclaimMemory, 0x008 }, @@ -48,6 +54,10 @@ InitializePlatform ( VOID *VariableStore; DXE_MEMORY_PROTECTION_SETTINGS DxeSettings; MM_MEMORY_PROTECTION_SETTINGS MmSettings; + CHAR8 String[100]; + UINTN StringSize; + EFI_STATUS Status; + UINTN Index; =20 DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n")); PlatformDebugDumpCmos (); @@ -109,18 +119,54 @@ 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); + StringSize =3D sizeof (String); + Status =3D QemuFwCfgParseString (DXE_MEMORY_PROTECTION_PROFILE_FWCFG= _FILE, &StringSize, String); + if (!EFI_ERROR (Status)) { + Index =3D 0; + do { + if (AsciiStriCmp (DxeMemoryProtectionProfiles[Index].Name, String) = =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Setting DXE Memory Protection Profile: %a\n",= String)); + DxeSettings =3D DxeMemoryProtectionProfiles[Index].Settings; + break; + } + } while (++Index < DxeMemoryProtectionSettingsMax); =20 - SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); - SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); + if (Index >=3D DxeMemoryProtectionSettingsMax) { + DEBUG ((DEBUG_ERROR, "Invalid DXE memory protection profile: %a\n", = String)); + ASSERT (Index < DxeMemoryProtectionSettingsMax); + } + } else { + DxeSettings =3D DxeMemoryProtectionProfiles[DxeMemoryProtectionSetting= sRelease].Settings; + } + + Status =3D QemuFwCfgParseString (MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE= , &StringSize, String); + if (!EFI_ERROR (Status)) { + Index =3D 0; + do { + if (AsciiStriCmp (MmMemoryProtectionProfiles[Index].Name, String) = =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Setting MM Memory Protection Profile: %a\n", = String)); + MmSettings =3D MmMemoryProtectionProfiles[Index].Settings; + break; + } + } while (++Index < MmMemoryProtectionSettingsMax); + + if (Index >=3D MmMemoryProtectionSettingsMax) { + DEBUG ((DEBUG_ERROR, "Invalid MM memory protection profile: %a\n", S= tring)); + ASSERT (Index < MmMemoryProtectionSettingsMax); + } + } else { + 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/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser= .c b/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c index c9e0091b82d1..63c8711a9f2e 100644 --- a/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c +++ b/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c @@ -426,3 +426,14 @@ QemuFwCfgParseUintn ( *Value =3D (UINTN)Uint64; return RETURN_SUCCESS; } + +RETURN_STATUS +EFIAPI +QemuFwCfgParseString ( + IN CONST CHAR8 *FileName, + IN OUT UINTN *BufferSize, + OUT CHAR8 *Buffer + ) +{ + return QemuFwCfgGetAsString (FileName, BufferSize, Buffer); +} 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..4d391974cbf8 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -50,6 +50,12 @@ EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] =3D { } }; =20 +#define DXE_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \ + "opt/org.tianocore/DxeMemoryProtectionProfile" + +#define MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \ + "opt/org.tianocore/MmMemoryProtectionProfile" + VOID MemMapInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob @@ -74,21 +80,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, @@ -309,6 +300,9 @@ InitializePlatform ( EFI_STATUS Status; DXE_MEMORY_PROTECTION_SETTINGS DxeSettings; MM_MEMORY_PROTECTION_SETTINGS MmSettings; + CHAR8 String[100]; + UINTN StringSize; + UINTN Index; =20 DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); PlatformInfoHob =3D BuildPlatformInfoHob (); @@ -345,13 +339,50 @@ 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); + StringSize =3D sizeof (String); + Status =3D QemuFwCfgParseString (DXE_MEMORY_PROTECTION_PROFILE_FWCFG= _FILE, &StringSize, String); + if (!EFI_ERROR (Status)) { + Index =3D 0; + do { + if (AsciiStriCmp (DxeMemoryProtectionProfiles[Index].Name, String) = =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Setting DXE Memory Protection Profile: %a\n",= String)); + DxeSettings =3D DxeMemoryProtectionProfiles[Index].Settings; + break; + } + } while (++Index < DxeMemoryProtectionSettingsMax); =20 - SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sPcd); - SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPc= d); + if (Index >=3D DxeMemoryProtectionSettingsMax) { + DEBUG ((DEBUG_ERROR, "Invalid DXE memory protection profile: %a\n", = String)); + ASSERT (Index < DxeMemoryProtectionSettingsMax); + } + } else { + DxeSettings =3D DxeMemoryProtectionProfiles[DxeMemoryProtectionSetting= sRelease].Settings; + } + + Status =3D QemuFwCfgParseString (MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE= , &StringSize, String); + if (!EFI_ERROR (Status)) { + Index =3D 0; + do { + if (AsciiStriCmp (MmMemoryProtectionProfiles[Index].Name, String) = =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Setting MM Memory Protection Profile: %a\n", = String)); + MmSettings =3D MmMemoryProtectionProfiles[Index].Settings; + break; + } + } while (++Index < MmMemoryProtectionSettingsMax); + + if (Index >=3D MmMemoryProtectionSettingsMax) { + DEBUG ((DEBUG_ERROR, "Invalid MM memory protection profile: %a\n", S= tring)); + ASSERT (Index < MmMemoryProtectionSettingsMax); + } + } else { + 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 +396,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/Bhyve/PlatformPei/PlatformPei.inf b/OvmfPkg/Bhyve/Plat= formPei/PlatformPei.inf index 07570d4e30ca..07f032941404 100644 --- a/OvmfPkg/Bhyve/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/Bhyve/PlatformPei/PlatformPei.inf @@ -89,7 +89,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy 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/Include/Library/QemuFwCfgSimpleParserLib.h b/OvmfPkg/I= nclude/Library/QemuFwCfgSimpleParserLib.h index bcbf3bc4fc96..ea9fcf7b402e 100644 --- a/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h +++ b/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h @@ -125,4 +125,12 @@ QemuFwCfgParseUintn ( OUT UINTN *Value ); =20 +RETURN_STATUS +EFIAPI +QemuFwCfgParseString ( + IN CONST CHAR8 *FileName, + IN OUT UINTN *BufferSize, + OUT CHAR8 *Buffer + ); + #endif // QEMU_FW_CFG_SIMPLE_PARSER_LIB_H_ diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index 47bd42d23d11..f433a6681bbd 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -79,7 +79,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ##= CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/Pl= atformBuildLib.py index 1ada935d3cb4..bd6de6fd26a4 100644 --- a/OvmfPkg/PlatformCI/PlatformBuildLib.py +++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py @@ -182,6 +182,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"): @@ -198,6 +200,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..c4179931a583 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -103,7 +103,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf index 9793562884c7..42317228c1aa 100644 --- a/OvmfPkg/TdxDxe/TdxDxe.inf +++ b/OvmfPkg/TdxDxe/TdxDxe.inf @@ -68,6 +68,5 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize --=20 2.42.0.windows.1 -=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 (#108175): https://edk2.groups.io/g/devel/message/108175 Mute This Topic: https://groups.io/mt/101064096/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- From nobody Sat May 11 07:38:29 2024 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+108176+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+108176+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437561; cv=none; d=zohomail.com; s=zohoarc; b=mWEU+/iCKC4zTVXb5YvxwZyVRbpOefJIywml52WTUxbErLo8JT1ecfX3KumLi51DLKuheb5MHmhKQAXqjN3f3YlYObvMSVtfcFPOvcb5J0Q8D17iqsA0DXPdxMKB+zcyBaAQsJGpbOs0n89Sta550gP0IXBDqbXuRzlPPzHBeUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437561; 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=I2xOxm5TjtU2mLbOikNcmM8MZxNfkqn9GoMwhy2FaLs=; b=cktOquSreHzqKJPZuWg9vMDu2hWy1r7G//N69pYD78wxGP+iYUuN5rU4UuPIQjq8EyqVPgAcbP12koQZlw/C2QPRu21919elvrqE/QjmtbFJKj9yM8hNVoKc3t1wxlYmlz4GRFyOew0OjAXQp4yQbHPTNcxM33Q1QtaIYVKdZ6c= 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+108176+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 16934375609451016.5348669193695; Wed, 30 Aug 2023 16:19:20 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=vIErlT7iRRM6tZzdAR/Gu51oQlfF5tQfH8zrht01ol0=; 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=1693437560; v=1; b=EknDt7kEuKPg3EMfT9cE5oC5KafrBweNlHNIgpHn0m3M7At3dBpo0J5QPXsJPqfrmfYKECTB 57yDTDivTntVTh4b6oO7EB5R7Y9aabmVGuPEtp7O+FxcXvOJPpdzQ9o7rUCtk5oW8rCzRQQYyOQ C73qY+mCSwMGQWjs6ewf+lM8= X-Received: by 127.0.0.2 with SMTP id ZwLYYY1788612xO6QiMY7dNp; Wed, 30 Aug 2023 16:19:20 -0700 X-Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web11.4964.1693437560064622897 for ; Wed, 30 Aug 2023 16:19:20 -0700 X-Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-68becf931bfso164995b3a.0 for ; Wed, 30 Aug 2023 16:19:20 -0700 (PDT) X-Gm-Message-State: Q5tRI7cLxeOwhsECRtplZbl9x1787277AA= X-Google-Smtp-Source: AGHT+IHG1op0DsSogS5vhjMYGHelWVK9d9oYwn7RwYX0mfN9jHqvIQ5q7LIuXjE0/DJatz0SkCdJDA== X-Received: by 2002:a05:6a21:790a:b0:13d:af0e:4ee5 with SMTP id bg10-20020a056a21790a00b0013daf0e4ee5mr4246433pzc.18.1693437559345; Wed, 30 Aug 2023 16:19:19 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:18 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 22/26] ArmVirtPkg: Apply Memory Protections via SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:30 -0700 Message-ID: <20230830231851.779-23-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437562071100089 Content-Type: text/plain; charset="utf-8" Set the memory protections on Arm virtual platforms. Because the QemuFg parser is not currently available in ArmVirtPkg, use the RELEASE profile by default. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann --- ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c | 11 +++++++++-- ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c b/ArmVirtPkg/MemoryI= nitPei/MemoryInitPeim.c index ef88a9df1d62..90718d05abe8 100644 --- a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -76,8 +77,9 @@ InitializeMemory ( IN CONST EFI_PEI_SERVICES **PeiServices ) { - UINTN UefiMemoryBase; - EFI_STATUS Status; + UINTN UefiMemoryBase; + EFI_STATUS Status; + DXE_MEMORY_PROTECTION_SETTINGS DxeSettings; =20 ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS); =20 @@ -100,5 +102,10 @@ InitializeMemory ( ); ASSERT_EFI_ERROR (Status); =20 + DxeSettings =3D DxeMemoryProtection= Profiles[DxeMemoryProtectionSettingsRelease].Settings; + DxeSettings.NullPointerDetection.DisableEndOfDxe =3D TRUE; + + SetDxeMemoryProtectionSettings (&DxeSettings, DxeMemoryProtectionSetting= sRelease); + return Status; } diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf b/ArmVirtPkg/Memor= yInitPei/MemoryInitPeim.inf index 2039f71a0ebe..d13325a89e14 100644 --- a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -34,6 +34,7 @@ [LibraryClasses] ArmLib ArmPlatformLib MemoryInitPeiLib + SetMemoryProtectionsLib =20 [Guids] gEfiMemoryTypeInformationGuid --=20 2.42.0.windows.1 -=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 (#108176): https://edk2.groups.io/g/devel/message/108176 Mute This Topic: https://groups.io/mt/101064097/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- From nobody Sat May 11 07:38:29 2024 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+108177+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+108177+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437561; cv=none; d=zohomail.com; s=zohoarc; b=cap/o5kPD4tA1TurfrGC77rg+TfLDABVJmZ4iDYyXaOdJrlt/i3/a+xU0hO0tezvotYA+ubJH34aRR5i0sBLG3gqpB7xkz1NrP1V0wmM1xqX1Gr6ZqbynGrfBsalwnf1LTGJTizZnCcyHqjaiCPV+PeyNlBqRwFVeu7gUgtMJiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437561; 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=EsU4+JjjNH/N9lWv7+mwOtQ9d67gzNCwyMAoZP3b0kw=; b=T98mWuTlDAJd696UcxQTLL3lyhGSHI76vdQAUNGYEShO87k/0gPzTxEWEoEBQRirm4oQZDqNsQUXp07/ikdTT5FSfGp8yGGEAv6RDJcvihSwuzQRh57qJU4ZSk2UocDAJ3Z5Qqaty2Kn373D8X2B8nAxhasELVE1LOmY55UPEMo= 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+108177+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 1693437561836555.4009652326797; Wed, 30 Aug 2023 16:19:21 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=UCiPhLriOI945OgZEhQvfmtHnwOg+CXF3q+DA/qP5XI=; 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=1693437561; v=1; b=b+TFk52v0+HuaKlWv7Ig9v+9AK5F9fTPcCRwVrwucuOWGRdambXGzuSfaawF5kZ1wccc10QS W06GMNR/YiBfWbkyFRiBd1xZoIPWCRPx0fLBPRpTgjw0UuhGAukHoGy4eo1OT4zI4SoPE0/oCDf nTehUB5Daule2hgajbVTHYCE= X-Received: by 127.0.0.2 with SMTP id D2KaYY1788612xbKBwlLfzBn; Wed, 30 Aug 2023 16:19:21 -0700 X-Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mx.groups.io with SMTP id smtpd.web11.4966.1693437560952830773 for ; Wed, 30 Aug 2023 16:19:21 -0700 X-Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-68a410316a2so171588b3a.0 for ; Wed, 30 Aug 2023 16:19:20 -0700 (PDT) X-Gm-Message-State: TzzxUkiVkBtQZw7B3bQWhUxlx1787277AA= X-Google-Smtp-Source: AGHT+IGybl8Lb5+fdVOMZyupulGMkJ/qHRzSEuwv3lYD0T1YaahwIJIfi4+/MWzk2O5pRt0ExhzASg== X-Received: by 2002:aa7:8883:0:b0:68b:fb93:5b48 with SMTP id z3-20020aa78883000000b0068bfb935b48mr4262308pfe.18.1693437560123; Wed, 30 Aug 2023 16:19:20 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:19 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 23/26] MdeModulePkg: Delete PCD Profile from SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:31 -0700 Message-ID: <20230830231851.779-24-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437563862100095 Content-Type: text/plain; charset="utf-8" Now that the transition to use SetMemoryProtectionsLib and GetMemoryProtectionsLib is complete, delete the PCD profile to avoid confusing the interface. All memory protection settings will now be set and consumed via the libraries. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c |= 174 +------------------- MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h |= 2 - MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.inf |= 11 -- 3 files changed, 4 insertions(+), 183 deletions(-) diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.c b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtection= sLib.c index 40d4f3081133..dffc7f0eea5d 100644 --- a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.c @@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include =20 #pragma pack(1) @@ -249,99 +248,6 @@ typedef struct { } \ } =20 -// -// A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec -// -#define DXE_MEMORY_PROTECTION_SETTINGS_PCD = \ -{ = \ - DXE_MEMORY_PROTECTION_SIGNATURE, = \ - DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, = \ - FixedPcdGetBool (PcdCpuStackGuard), /* Stack Guard */ = \ - TRUE, /* Stack Execution Protection (MUST = BE POPULATED) */ \ - { /* NULL Pointer Detection */ = \ - .Enabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT0) !=3D 0), \ - .DisableEndOfDxe =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT7) !=3D 0), \ - .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT6) !=3D 0) \ - }, = \ - { /* Image Protection */ = \ - .ProtectImageFromUnknown =3D ((FixedPcdGet32 (PcdImageProtectionPolicy= ) & BIT0) !=3D 0), \ - .ProtectImageFromFv =3D ((FixedPcdGet32 (PcdImageProtectionPolicy= ) & BIT1) !=3D 0) \ - }, = \ - { /* Execution Protection */ = \ - .EnabledForType =3D { = \ - [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiReservedMemoryType) !=3D 0), \ - [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiLoaderCode) !=3D 0), \ - [EfiLoaderData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiLoaderData) !=3D 0), \ - [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiBootServicesCode) !=3D 0), \ - [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiBootServicesData) !=3D 0), \ - [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiRuntimeServicesCode) !=3D 0), \ - [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiRuntimeServicesData) !=3D 0), \ - [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiConventionalMemory) !=3D 0), \ - [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiUnusableMemory) !=3D 0), \ - [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiACPIReclaimMemory) !=3D 0), \ - [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiACPIMemoryNVS) !=3D 0), \ - [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiMemoryMappedIO) !=3D 0), \ - [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiMemoryMappedIOPortSpace) !=3D 0), \ - [EfiPalCode] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiPalCode) !=3D 0), \ - [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiPersistentMemory) !=3D 0), \ - [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & EfiUnacceptedMemoryType) !=3D 0), \ - [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & BIT62) !=3D 0), \ - [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdDxeNxM= emoryProtectionPolicy) & BIT63) !=3D 0) \ - } = \ - }, = \ - { /* Heap Guard */ = \ - .PageGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT0) !=3D 0), \ - .PoolGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT1) !=3D 0), \ - .FreedMemoryGuardEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT4) !=3D 0), \ - .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT6) !=3D 0), \ - .GuardAlignedToTail =3D ((FixedPcdGet8 (PcdHeapGua= rdPropertyMask) & BIT7) =3D=3D 0) \ - }, = \ - { /* Pool Guard */ = \ - .EnabledForType =3D { = \ - [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiReservedMemoryType) !=3D 0), \ - [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderCode) !=3D 0), \ - [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderData) !=3D 0), \ - [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesCode) !=3D 0), \ - [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesData) !=3D 0), \ - [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesCode) !=3D 0), \ - [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesData) !=3D 0), \ - [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiConventionalMemory) !=3D 0), \ - [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnusableMemory) !=3D 0), \ - [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIReclaimMemory) !=3D 0), \ - [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIMemoryNVS) !=3D 0), \ - [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIO) !=3D 0), \ - [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ - [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPalCode) !=3D 0), \ - [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPersistentMemory) !=3D 0), \ - [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnacceptedMemoryType) !=3D 0), \ - [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT62) !=3D 0), \ - [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT63) !=3D 0) \ - } = \ - }, = \ - { /* Page Guard */ = \ - .EnabledForType =3D { = \ - [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiReservedMemoryType) !=3D 0), \ - [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderCode) !=3D 0), \ - [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderData) !=3D 0), \ - [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesCode) !=3D 0), \ - [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesData) !=3D 0), \ - [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesCode) !=3D 0), \ - [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesData) !=3D 0), \ - [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiConventionalMemory) !=3D 0), \ - [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnusableMemory) !=3D 0), \ - [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIReclaimMemory) !=3D 0), \ - [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIMemoryNVS) !=3D 0), \ - [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIO) !=3D 0), \ - [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ - [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPalCode) !=3D 0), \ - [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPersistentMemory) !=3D 0), \ - [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnacceptedMemoryType) !=3D 0), \ - [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT62) !=3D 0), \ - [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT63) !=3D 0) \ - } = \ - } = \ -} - // // A memory profile which disables all DXE memory protection settings. // @@ -482,69 +388,6 @@ typedef struct { } \ } =20 -// -// A memory profile which uses the fixed at build PCDs defined in MdeModu= lePkg.dec -// -#define MM_MEMORY_PROTECTION_SETTINGS_PCD = \ -{ = \ - MM_MEMORY_PROTECTION_SIGNATURE, = \ - MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VERSION, = \ - { /* NULL Pointer Detection */ = \ - .Enabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT1) !=3D 0), \ - .NonstopModeEnabled =3D ((FixedPcdGet8 (PcdNullPointerDetectionPropert= yMask) & BIT6) !=3D 0) \ - }, = \ - { /* Heap Guard */ = \ - .PageGuardEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT2) !=3D 0), \ - .PoolGuardEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT3) !=3D 0), \ - .NonstopModeEnabled =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT6) !=3D 0), \ - .GuardAlignedToTail =3D ((FixedPcdGet8(PcdHeapGuar= dPropertyMask) & BIT7) =3D=3D 0) \ - }, = \ - { /* Pool Guard */ = \ - .EnabledForType =3D { = \ - [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiReservedMemoryType) !=3D 0), \ - [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderCode) !=3D 0), \ - [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiLoaderData) !=3D 0), \ - [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesCode) !=3D 0), \ - [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiBootServicesData) !=3D 0), \ - [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesCode) !=3D 0), \ - [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiRuntimeServicesData) !=3D 0), \ - [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiConventionalMemory) !=3D 0), \ - [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnusableMemory) !=3D 0), \ - [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIReclaimMemory) !=3D 0), \ - [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiACPIMemoryNVS) !=3D 0), \ - [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIO) !=3D 0), \ - [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ - [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPalCode) !=3D 0), \ - [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiPersistentMemory) !=3D 0), \ - [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & EfiUnacceptedMemoryType) !=3D 0), \ - [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT62) !=3D 0), \ - [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPoolType) & BIT63) !=3D 0) \ - } = \ - }, = \ - { /* Page Guard */ = \ - .EnabledForType =3D { = \ - [EfiReservedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiReservedMemoryType) !=3D 0), \ - [EfiLoaderCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderCode) !=3D 0), \ - [EfiLoaderData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiLoaderData) !=3D 0), \ - [EfiBootServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesCode) !=3D 0), \ - [EfiBootServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiBootServicesData) !=3D 0), \ - [EfiRuntimeServicesCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesCode) !=3D 0), \ - [EfiRuntimeServicesData] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiRuntimeServicesData) !=3D 0), \ - [EfiConventionalMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiConventionalMemory) !=3D 0), \ - [EfiUnusableMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnusableMemory) !=3D 0), \ - [EfiACPIReclaimMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIReclaimMemory) !=3D 0), \ - [EfiACPIMemoryNVS] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiACPIMemoryNVS) !=3D 0), \ - [EfiMemoryMappedIO] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIO) !=3D 0), \ - [EfiMemoryMappedIOPortSpace] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiMemoryMappedIOPortSpace) !=3D 0), \ - [EfiPalCode] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPalCode) !=3D 0), \ - [EfiPersistentMemory] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiPersistentMemory) !=3D 0), \ - [EfiUnacceptedMemoryType] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & EfiUnacceptedMemoryType) !=3D 0), \ - [OEM_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT62) !=3D 0), \ - [OS_RESERVED_MPS_MEMORY_TYPE] =3D ((FixedPcdGet64 (PcdHeapGu= ardPageType) & BIT63) !=3D 0) \ - } = \ - } = \ -} - // // A memory profile which disables all MM memory protection settings. // @@ -586,11 +429,6 @@ DXE_MEMORY_PROTECTION_PROFILES DxeMemoryProtectionPro= files[DxeMemoryProtectionS .Description =3D "Release profile without page guards recommended for = performance sensitive production scenarios", .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PROD_MODE_NO_PAGE_GUAR= DS }, - [DxeMemoryProtectionSettingsPcd] =3D { - .Name =3D "Pcd", - .Description =3D "Memory protection settings from PCDs", - .Settings =3D DXE_MEMORY_PROTECTION_SETTINGS_PCD - }, [DxeMemoryProtectionSettingsOff] =3D { .Name =3D "Off", .Description =3D "Disables all memory protection settings", @@ -609,11 +447,6 @@ MM_MEMORY_PROTECTION_PROFILES MmMemoryProtectionProfi= les[MmMemoryProtectionSett .Description =3D "Release profile recommended for production scenarios= ", .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_PROD_MODE }, - [MmMemoryProtectionSettingsPcd] =3D { - .Name =3D "Pcd", - .Description =3D "Memory protection settings from PCDs", - .Settings =3D MM_MEMORY_PROTECTION_SETTINGS_PCD - }, [MmMemoryProtectionSettingsOff] =3D { .Name =3D "Off", .Description =3D "Disables all memory protection settings", @@ -648,9 +481,10 @@ GetOrCreateMemoryProtectionSettings ( } =20 ZeroMem (&Mpsp, sizeof (Mpsp)); - Mpsp.Mps.Dxe =3D DxeMemoryProtectionProf= iles[DxeMemoryProtectionSettingsPcd].Settings; - Mpsp.Mps.Mm =3D MmMemoryProtectionProfi= les[MmMemoryProtectionSettingsPcd].Settings; - Mpsp.Mps.Dxe.StackExecutionProtectionEnabled =3D PcdGetBool (PcdSetNxFor= Stack); + Mpsp.Mps.Dxe.StructVersion =3D DXE_MEMORY_PROTECTION_SETTINGS_CURRENT_VE= RSION; + Mpsp.Mps.Dxe.Signature =3D DXE_MEMORY_PROTECTION_SIGNATURE; + Mpsp.Mps.Mm.StructVersion =3D MM_MEMORY_PROTECTION_SETTINGS_CURRENT_VER= SION; + Mpsp.Mps.Mm.Signature =3D MM_MEMORY_PROTECTION_SIGNATURE; =20 Ptr =3D BuildGuidDataHob ( &gMemoryProtectionSettingsGuid, diff --git a/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h b/MdeMo= dulePkg/Include/Library/SetMemoryProtectionsLib.h index f4665130b0b3..0b6495c3cc3a 100644 --- a/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h +++ b/MdeModulePkg/Include/Library/SetMemoryProtectionsLib.h @@ -21,7 +21,6 @@ typedef enum { DxeMemoryProtectionSettingsRelease, DxeMemoryProtectionSettingsReleaseNoPageGuards, DxeMemoryProtectionSettingsOff, - DxeMemoryProtectionSettingsPcd, DxeMemoryProtectionSettingsMax } DXE_MEMORY_PROTECTION_PROFILE_INDEX; =20 @@ -35,7 +34,6 @@ typedef enum { MmMemoryProtectionSettingsDebug =3D 0, MmMemoryProtectionSettingsRelease, MmMemoryProtectionSettingsOff, - MmMemoryProtectionSettingsPcd, MmMemoryProtectionSettingsMax } MM_MEMORY_PROTECTION_PROFILE_INDEX; =20 diff --git a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.inf b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtecti= onsLib.inf index 2e4a9a66ac68..830d151a8378 100644 --- a/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.= inf +++ b/MdeModulePkg/Library/SetMemoryProtectionsLib/SetMemoryProtectionsLib.= inf @@ -29,17 +29,6 @@ [LibraryClasses] BaseLib HobLib DebugLib - PcdLib - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy =20 [Guids] gMemoryProtectionSettingsGuid --=20 2.42.0.windows.1 -=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 (#108177): https://edk2.groups.io/g/devel/message/108177 Mute This Topic: https://groups.io/mt/101064098/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- From nobody Sat May 11 07:38:29 2024 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+108178+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+108178+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437562; cv=none; d=zohomail.com; s=zohoarc; b=DtwPCzWMPCzu7/a7gCNlsF4Y/C4AfnRAjRVppp+7yddH2Tg638V3Bd3GzJXx/EVWiphvmzn2ewtB8aM5z1f40TH0xMAe+LOF4nqTDMVRHWAq2i+GgKbDxXrBZwEgh1CHTFS5BGVNxNmWoz8XNMxELFmAvKwcqRkUOZiUnyiRS/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437562; 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=rmqn6QeH7Nl0POlfNz7Ysnf+cgq9/Sin0T3a3LfeCR8=; b=WTaWMOXIxwnlIs4fTe3Fh3Mp0yqI8DjQXpU+N5HgEnEZGYPGTO/QNq0NunydBfoFldfCJq/zyR+9IPearDNxs9/2cIMBjsKc6YxidNPXhn7N9RCqVi2hu1hB/mlS8+dQyqN5tpzlUZB2vDCPX3hmR0vsAz4UqEBxQG/hHaGbiv0= 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+108178+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 1693437562747283.85600809664595; Wed, 30 Aug 2023 16:19:22 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Wkg1Z6QuDGJGCIoIco24sKE86q+8KT371g5RJKnOnbk=; 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=1693437562; v=1; b=LaF2h4i7s6cyWEKhzFvVZjBdvzWAs43lYoCe7Erz3TxHzkmEe6iHg039Xzwrp9V8Z5nLToNz JTJag1ObAdOP5p5re/0kt3VT+kusOKwjUWX28GwpZ9vOQg3HiFD4gShLkEjmfrG4tjKCucatRbE +XxjTahJpk9HowPqIN1mm+pQ= X-Received: by 127.0.0.2 with SMTP id FgqfYY1788612xJZGgGarIU3; Wed, 30 Aug 2023 16:19:22 -0700 X-Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mx.groups.io with SMTP id smtpd.web10.4876.1693437561974334903 for ; Wed, 30 Aug 2023 16:19:22 -0700 X-Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-68a41031768so160734b3a.3 for ; Wed, 30 Aug 2023 16:19:21 -0700 (PDT) X-Gm-Message-State: VRjoi9tlZbOBkkCYIhfehPFpx1787277AA= X-Google-Smtp-Source: AGHT+IEcpoeW9w/NWZKRCYAdQ0YjNtfFCsEZxpCmz4pdaQKxwPKy1dUXlcRZKDlpaK6Im5ADbBEVxA== X-Received: by 2002:a05:6a21:3e0a:b0:14b:f8cf:c318 with SMTP id bk10-20020a056a213e0a00b0014bf8cfc318mr3536432pzc.62.1693437561216; Wed, 30 Aug 2023 16:19:21 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19: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?= , Jianyong Wu , Anatol Belski , Anthony Perard , Julien Grall , Erdem Aktas , James Bottomley , Min Xu , Tom Lendacky , Michael Roth , Sunil V L , Andrei Warkentin Subject: [edk2-devel] [PATCH v3 24/26] OvmfPkg: Delete Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:32 -0700 Message-ID: <20230830231851.779-25-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437564067100097 Content-Type: text/plain; charset="utf-8" Now that the transition to use SetMemoryProtectionsLib and GetMemoryProtectionsLib is complete, delete the memory protection PCDs to avoid confusing the interface. All memory protection settings will now be set and consumed via the libraries. 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\ufffd\ufffdhne Cc: Jianyong Wu Cc: Anatol Belski Cc: Anthony Perard Cc: Julien Grall Cc: Erdem Aktas Cc: James Bottomley Cc: Min Xu Cc: Tom Lendacky Cc: Michael Roth Cc: Sunil V L Cc: Andrei Warkentin --- OvmfPkg/AmdSev/AmdSevX64.dsc | 3 --- OvmfPkg/Bhyve/BhyveX64.dsc | 3 --- OvmfPkg/CloudHv/CloudHvX64.dsc | 3 --- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 3 --- OvmfPkg/Microvm/MicrovmX64.dsc | 3 --- OvmfPkg/OvmfPkgIa32.dsc | 3 --- OvmfPkg/OvmfPkgIa32X64.dsc | 3 --- OvmfPkg/OvmfPkgX64.dsc | 3 --- OvmfPkg/OvmfXen.dsc | 3 --- OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 13 ------------- 10 files changed, 40 deletions(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 0913aa734114..2e2e320c61fb 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -507,9 +507,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index c2a3b9bf3960..30f0e27ea840 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -550,9 +550,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000 diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 20d609156e7d..ecf723b20439 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -600,9 +600,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 7d589d887732..7406eefbc156 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -511,9 +511,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 1c9b0532599c..f0573fcc12ca 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -623,9 +623,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 8267cf20e4a9..ced2fd724954 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -634,9 +634,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 583033fe3d93..f5c638812ac4 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -652,9 +652,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index bbe825d5f50d..3fa62d0cfea8 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -670,9 +670,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # UefiCpuPkg PCDs related to initial AP bringup and general AP managemen= t. gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0 diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 7f99f8dd4783..62b1acd41201 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -506,9 +506,6 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE =20 - # Noexec settings for DXE. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE - # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVV= irt.dsc.inc index bc204ba5fe52..efc976088c9a 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -271,19 +271,6 @@ [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0 =20 - # - # Enable strict image permissions for all images. (This applies - # only to images that were built with >=3D 4 KB section alignment.) - # - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy|0x3 - - # - # Enable NX memory protection for all non-code regions, including OEM an= d OS - # reserved ones, with the exception of LoaderData regions, of which OS l= oaders - # (i.e., GRUB) may assume that its contents are executable. - # - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0xC0000000= 00007FD5 - [Components.common] # # Ramdisk support --=20 2.42.0.windows.1 -=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 (#108178): https://edk2.groups.io/g/devel/message/108178 Mute This Topic: https://groups.io/mt/101064099/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- From nobody Sat May 11 07:38:29 2024 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+108179+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+108179+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437563; cv=none; d=zohomail.com; s=zohoarc; b=K7VCwD98su4fgSk7oti9gxqyDzEbB/zd0p3z7iBzBKytggFmt/ywpXvqRFWBORQ1tYzHPmN3hsIRA/dJX+FKHtjCU3HKvDW65M98YLOFtgCPCzvL8I7riiOyoa5s1tfYn7qP1IUtS3qBFlAqBv0GQ80PgdZsIZrtf2U9OnVQi0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437563; 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=SzH7Z16ZE+Mw2IMTPM1Es50ZyCl5eY+W9QvCyTfrT6s=; b=Rc8KahLDLZJAxkdeMnRlAVl6BkBtpnFPVbqyuhzuoD1MQrNBeIpjUqJueMuGKCnZrINnKnkamS4oxwzy8wYFvB5bNMIi8pvA04LHwkpkXbAyZrSbvKe8/l2CnMg7tqnxYmsl5G8fnXhXdGuD6SUANzRZzEBPfj4GE+ByA6RJOdI= 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+108179+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 1693437563747292.0641991272339; Wed, 30 Aug 2023 16:19:23 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wbY/xgrqG9qGJ5z2Ax9mBW2tfCCexhO637X1w1bW4Eg=; 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=1693437563; v=1; b=nHVzerSNRWfZYKwaXXpE+QyanTpP12juur/TZUlgm7coliX+sKRROdy8IRSjp/sNX5JFJynJ 28EmKrR0Np3RpYKnjUV5xD+XPtZsuUfw7prKwXMyPDAchxFSJKSE9LHehL0HlFBTgDl4Ma6XnCW ciF2El7PdkyqXHNZe8KbdB5s= X-Received: by 127.0.0.2 with SMTP id ZuAZYY1788612xhbGAziiWOJ; Wed, 30 Aug 2023 16:19:23 -0700 X-Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by mx.groups.io with SMTP id smtpd.web10.4877.1693437562873670956 for ; Wed, 30 Aug 2023 16:19:22 -0700 X-Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-564b8e60ce9so225066a12.2 for ; Wed, 30 Aug 2023 16:19:22 -0700 (PDT) X-Gm-Message-State: BsGxeT2ctKWcJ9N4ornAHEkkx1787277AA= X-Google-Smtp-Source: AGHT+IFly0yYx1tiM/lnB9yun2+zaATL9qfAsCBsLPF6cAw3FnmfQhjGDymZSriIzXdxAleATa2Z+g== X-Received: by 2002:a05:6a21:619:b0:13a:43e8:3fa6 with SMTP id ll25-20020a056a21061900b0013a43e83fa6mr3383505pzb.23.1693437562138; Wed, 30 Aug 2023 16:19:22 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:21 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 25/26] ArmVirtPkg: Delete Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:33 -0700 Message-ID: <20230830231851.779-26-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437564081100098 Content-Type: text/plain; charset="utf-8" Now that the transition to use SetMemoryProtectionsLib and GetMemoryProtectionsLib is complete, delete the memory protection PCDs to avoid confusing the interface. All memory protection settings will now be set and consumed via the libraries. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann --- ArmVirtPkg/ArmVirt.dsc.inc | 15 --------------- ArmVirtPkg/ArmVirtCloudHv.dsc | 5 ----- ArmVirtPkg/ArmVirtQemu.dsc | 5 ----- 3 files changed, 25 deletions(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 6de28d0e0d4e..2df479331ae6 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -360,21 +360,6 @@ [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0 =20 - # - # Enable strict image permissions for all images. (This applies - # only to images that were built with >=3D 4 KB section alignment.) - # - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy|0x3 - - # - # Enable NX memory protection for all non-code regions, including OEM an= d OS - # reserved ones, with the exception of LoaderData regions, of which OS l= oaders - # (i.e., GRUB) may assume that its contents are executable. - # - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0xC0000000= 00007FD5 - - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|TRUE - [Components.common] # # Ramdisk support diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index c975e139a216..c4c3e0da4491 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -140,11 +140,6 @@ [PcdsFixedAtBuild.common] # gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16 =20 - # - # Enable the non-executable DXE stack. (This gets set up by DxeIpl) - # - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE - !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE # override the default values from SecurityPkg to ensure images from all= sources are verified in secure boot gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x04 diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 1e0225951aef..214e08b789eb 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -212,11 +212,6 @@ [PcdsFixedAtBuild.common] # gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16 =20 - # - # Enable the non-executable DXE stack. (This gets set up by DxeIpl) - # - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE - !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE # override the default values from SecurityPkg to ensure images from all= sources are verified in secure boot gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x04 --=20 2.42.0.windows.1 -=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 (#108179): https://edk2.groups.io/g/devel/message/108179 Mute This Topic: https://groups.io/mt/101064100/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- From nobody Sat May 11 07:38:29 2024 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+108180+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+108180+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437564; cv=none; d=zohomail.com; s=zohoarc; b=V5Ncn6OwUmogE/BmfbrZgT9YLbI1FQyCVyedO9MRSch4dcYuoSbRWfstlqfIWFbVAhZ997VOP5oHRiZaNsumtu8VyxDXTbXmJx3yXDo7lXa09SK+igIl+kUz+z8Q72w+qpUVYJ2AKevCRtenILkE3BnCFs9L+AnIqmn2MctPkcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437564; 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=0TBZrBqb8q3F1naOpcsPu8kFrfZJfzZXMDWcnshmO18=; b=DyHXNR56qvN7m/Sl9pYDffouZpYbcYpYiHkf+3nzyB9rXpqbMOZE2VMpxbsDdUy175ZbprC0S/ay55s56WGK3CNcuLSOvkz9R6S32OdT4ymxQu+eBg+nzqRcXfb0hGLPccQdZGX8c5mJShCnXP6V3nZv5nhYookPluSN+2YLQUo= 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+108180+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 1693437564978742.5282824999929; Wed, 30 Aug 2023 16:19:24 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qGd3i+3qOxtQAhLluaCCMusn4hTGRMffuVvHliA6QN0=; 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=1693437564; v=1; b=eFw1qjD4KgbMoQ28UF8RKjMpSAA85hY3VjI6+CdsXdluw6gXnAv7eanWwaN7gW+LZesnCVR+ cKvTZvu81t2FKuTglfvIWF63QHFabcGFfEAzrk3W/x9qJnWkJ/4GPC6UOwQFlOCdmcuGEAnH5iG 3SjkHfXjtFe8OhIrDSXHs+8k= X-Received: by 127.0.0.2 with SMTP id 2ERSYY1788612xnp5uBGNrDv; Wed, 30 Aug 2023 16:19:24 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web11.4971.1693437563940191922 for ; Wed, 30 Aug 2023 16:19:24 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-68c0d886ea0so172711b3a.2 for ; Wed, 30 Aug 2023 16:19:23 -0700 (PDT) X-Gm-Message-State: XkMK7eIvNVON3Ulzq7FTCBwxx1787277AA= X-Google-Smtp-Source: AGHT+IHciAmc5Pxpc8jXvPgmwnEw0O24sDX+HY+6H1Q0Lpqf9P3fcF80TxlZ4a/aAEKHiK5cFMrowg== X-Received: by 2002:a05:6a00:158a:b0:68b:dbad:7ae0 with SMTP id u10-20020a056a00158a00b0068bdbad7ae0mr4469716pfk.21.1693437562894; Wed, 30 Aug 2023 16:19:22 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:22 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v3 26/26] MdeModulePkg: Delete Memory Protection PCDs Date: Wed, 30 Aug 2023 16:18:34 -0700 Message-ID: <20230830231851.779-27-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-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: 1693437566127100107 Content-Type: text/plain; charset="utf-8" Now that the transition to use SetMemoryProtectionsLib and GetMemoryProtectionsLib is complete, delete the memory protection PCDs to avoid confusing the interface. All memory protection settings will now be set and consumed via the libraries. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao --- MdeModulePkg/MdeModulePkg.dec | 169 -------------------- MdeModulePkg/MdeModulePkg.uni | 153 ------------------ 2 files changed, 322 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 50c26fedaf6f..c701173b9803 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1004,119 +1004,12 @@ [PcdsFixedAtBuild] # @ValidList 0x80000006 | 0x03058002 gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable|0x03058002|UINT32= |0x30001040 =20 - ## Mask to control the NULL address detection in code for different phas= es. - # If enabled, accessing NULL address in UEFI or SMM code can be caught.=

- # BIT0 - Enable NULL pointer detection for UEFI.
- # BIT1 - Enable NULL pointer detection for SMM.
- # BIT2..5 - Reserved for future uses.
- # BIT6 - Enable non-stop mode.
- # BIT7 - Disable NULL pointer detection just after EndOfDxe.
- # This is a workaround for those unsolvable NULL access iss= ues in - # OptionROM, boot loader, etc. It can also help to avoid un= necessary - # exception caused by legacy memory (0-4095) access after E= ndOfDxe, - # such as Windows 7 boot on Qemu.
- # @Prompt Enable NULL address detection. - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask|0x0|U= INT8|0x30001050 - ## Init Value in Temp Stack to be shared between SEC and PEI_CORE # SEC fills the full temp stack with this values. When switch stack, Pei= Core can check # this value in the temp stack to know how many stack has been used. # @Prompt Init Value in Temp Stack gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack|0x5AA55AA5|UINT32= |0x30001051 =20 - ## Indicates which type allocation need guard page. - # - # If a bit is set, a head guard page and a tail guard page will be added= just - # before and after corresponding type of pages allocated if there's enou= gh - # free pages for all of them. The page allocation for the type related to - # cleared bits keeps the same as ususal. - # - # This PCD is only valid if BIT0 and/or BIT2 are set in PcdHeapGuardProp= ertyMask. - # - # Below is bit mask for this PCD: (Order is same as UEFI spec)
- # EfiReservedMemoryType 0x0000000000000001
- # EfiLoaderCode 0x0000000000000002
- # EfiLoaderData 0x0000000000000004
- # EfiBootServicesCode 0x0000000000000008
- # EfiBootServicesData 0x0000000000000010
- # EfiRuntimeServicesCode 0x0000000000000020
- # EfiRuntimeServicesData 0x0000000000000040
- # EfiConventionalMemory 0x0000000000000080
- # EfiUnusableMemory 0x0000000000000100
- # EfiACPIReclaimMemory 0x0000000000000200
- # EfiACPIMemoryNVS 0x0000000000000400
- # EfiMemoryMappedIO 0x0000000000000800
- # EfiMemoryMappedIOPortSpace 0x0000000000001000
- # EfiPalCode 0x0000000000002000
- # EfiPersistentMemory 0x0000000000004000
- # OEM Reserved 0x4000000000000000
- # OS Reserved 0x8000000000000000
- # e.g. LoaderCode+LoaderData+BootServicesCode+BootServicesData are neede= d, 0x1E should be used.
- # @Prompt The memory type mask for Page Guard. - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPageType|0x0|UINT64|0x30001052 - - ## Indicates which type allocation need guard page. - # - # If a bit is set, a head guard page and a tail guard page will be added= just - # before and after corresponding type of pages which the allocated pool = occupies, - # if there's enough free memory for all of them. The pool allocation for= the - # type related to cleared bits keeps the same as ususal. - # - # This PCD is only valid if BIT1 and/or BIT3 are set in PcdHeapGuardProp= ertyMask. - # - # Below is bit mask for this PCD: (Order is same as UEFI spec)
- # EfiReservedMemoryType 0x0000000000000001
- # EfiLoaderCode 0x0000000000000002
- # EfiLoaderData 0x0000000000000004
- # EfiBootServicesCode 0x0000000000000008
- # EfiBootServicesData 0x0000000000000010
- # EfiRuntimeServicesCode 0x0000000000000020
- # EfiRuntimeServicesData 0x0000000000000040
- # EfiConventionalMemory 0x0000000000000080
- # EfiUnusableMemory 0x0000000000000100
- # EfiACPIReclaimMemory 0x0000000000000200
- # EfiACPIMemoryNVS 0x0000000000000400
- # EfiMemoryMappedIO 0x0000000000000800
- # EfiMemoryMappedIOPortSpace 0x0000000000001000
- # EfiPalCode 0x0000000000002000
- # EfiPersistentMemory 0x0000000000004000
- # OEM Reserved 0x4000000000000000
- # OS Reserved 0x8000000000000000
- # e.g. LoaderCode+LoaderData+BootServicesCode+BootServicesData are neede= d, 0x1E should be used.
- # @Prompt The memory type mask for Pool Guard. - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType|0x0|UINT64|0x30001053 - - ## This mask is to control Heap Guard behavior. - # - # Note: - # a) Heap Guard is for debug purpose and should not be enabled in prod= uct - # BIOS. - # b) Due to the limit of pool memory implementation and the alignment - # requirement of UEFI spec, BIT7 is a try-best setting which cannot - # guarantee that the returned pool is exactly adjacent to head guard - # page or tail guard page. - # c) UEFI freed-memory guard and UEFI pool/page guard cannot be enabled - # at the same time. - # - # BIT0 - Enable UEFI page guard.
- # BIT1 - Enable UEFI pool guard.
- # BIT2 - Enable SMM page guard.
- # BIT3 - Enable SMM pool guard.
- # BIT4 - Enable UEFI freed-memory guard (Use-After-Free memory detecti= on).
- # BIT6 - Enable non-stop mode.
- # BIT7 - The direction of Guard Page for Pool Guard. - # 0 - The returned pool is near the tail guard page.
- # 1 - The returned pool is near the head guard page.
- # @Prompt The Heap Guard feature mask - gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask|0x0|UINT8|0x3000= 1054 - - ## Indicates if UEFI Stack Guard will be enabled. - # If enabled, stack overflow in UEFI can be caught, preventing chaotic = consequences.

- # TRUE - UEFI Stack Guard will be enabled.
- # FALSE - UEFI Stack Guard will be disabled.
- # @Prompt Enable UEFI Stack Guard. - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055 - ## Indicate debug level of Trace Hub. # 0x0 - TraceHubDebugLevelError.
# 0x1 - TraceHubDebugLevelErrorWarning.
@@ -1393,54 +1286,6 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] # @Prompt Memory profile driver path. gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath|{0x0}|VOID*|0x= 00001043 =20 - ## Set image protection policy. The policy is bitwise. - # If a bit is set, the image will be protected by DxeCore if it is alig= ned. - # The code section becomes read-only, and the data section becomes non= -executable. - # If a bit is clear, nothing will be done to image code/data sections.<= BR>
- # BIT0 - Image from unknown device.
- # BIT1 - Image from firmware volume.
- #
- # Note: If a bit is cleared, the data section could be still non-execut= able if - # PcdDxeNxMemoryProtectionPolicy is enabled for EfiLoaderData, EfiBootS= ervicesData - # and/or EfiRuntimeServicesData.
- #
- # @Prompt Set image protection policy. - # @ValidRange 0x80000002 | 0x00000000 - 0x0000001F - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy|0x00000002|UINT3= 2|0x00001047 - - ## Set DXE memory protection policy. The policy is bitwise. - # If a bit is set, memory regions of the associated type will be mapped - # non-executable.
- # If a bit is cleared, nothing will be done to associated type of memor= y.
- #
- # Below is bit mask for this PCD: (Order is same as UEFI spec)
- # EfiReservedMemoryType 0x0001
- # EfiLoaderCode 0x0002
- # EfiLoaderData 0x0004
- # EfiBootServicesCode 0x0008
- # EfiBootServicesData 0x0010
- # EfiRuntimeServicesCode 0x0020
- # EfiRuntimeServicesData 0x0040
- # EfiConventionalMemory 0x0080
- # EfiUnusableMemory 0x0100
- # EfiACPIReclaimMemory 0x0200
- # EfiACPIMemoryNVS 0x0400
- # EfiMemoryMappedIO 0x0800
- # EfiMemoryMappedIOPortSpace 0x1000
- # EfiPalCode 0x2000
- # EfiPersistentMemory 0x4000
- # OEM Reserved 0x4000000000000000
- # OS Reserved 0x8000000000000000
- # - # NOTE: User must NOT set NX protection for EfiLoaderCode / EfiBootServi= cesCode / EfiRuntimeServicesCode.
- # User MUST set the same NX protection for EfiBootServicesData and= EfiConventionalMemory.
- # - # e.g. 0x7FD5 can be used for all memory except Code.
- # e.g. 0x7BD4 can be used for all memory except Code and ACPINVS/Reserve= d.
- # - # @Prompt Set DXE memory protection policy. - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0x0000000|= UINT64|0x00001048 - ## PCI Serial Device Info. It is an array of Device, Function, and Power= Management # information that describes the path that contains zero or more PCI to= PCI bridges # followed by a PCI serial device. Each array entry is 4-bytes in leng= th. The @@ -2029,20 +1874,6 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynami= c, PcdsDynamicEx] # @Prompt Default Creator Revision for ACPI table creation. gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision|0x01000013|= UINT32|0x30001038 =20 - ## Indicates if to set NX for stack.

- # For the DxeIpl and the DxeCore are both X64, set NX for stack feature= also require PcdDxeIplBuildPageTables be TRUE.
- # For the DxeIpl and the DxeCore are both IA32 (PcdDxeIplSwitchToLongMo= de is FALSE), set NX for stack feature also require - # IA32 PAE is supported and Execute Disable Bit is available.
- #
- # TRUE - Set NX for stack.
- # FALSE - Do nothing for stack.
- #
- # Note: If this PCD is set to FALSE, NX could be still applied to stack= due to PcdDxeNxMemoryProtectionPolicy enabled for - # EfiBootServicesData.
- #
- # @Prompt Set NX for stack. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE|BOOLEAN|0x0001006f - ## This PCD specifies the PCI-based SD/MMC host controller mmio base add= ress. # Define the mmio base address of the pci-based SD/MMC host controller. = If there are multiple SD/MMC # host controllers, their mmio base addresses are calculated one by one = from this base address. diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index a17d34d60b21..afbbc44761ca 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -330,16 +330,6 @@ =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSerialRegisterStride_HELP #= language en-US "The number of bytes between registers in serial device. Th= e default is 1 byte." =20 -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNxForStack_PROMPT #langu= age en-US "Set NX for stack" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNxForStack_HELP #languag= e en-US "Indicates if to set NX for stack.

" - = "For the DxeIpl and the DxeCore are both X64, set NX for stack feat= ure also require PcdDxeIplBuildPageTables be TRUE.
" - = "For the DxeIpl and the DxeCore are both IA32 (PcdDxeIplSwitchToLon= gMode is FALSE), set NX for stack feature also require" - = "IA32 PAE is supported and Execute Disable Bit is available.
" - = "TRUE - Set NX for stack.
" - = "FALSE - Do nothing for stack.
" - = "Note: If this PCD is set to FALSE, NX could be still applied to st= ack due to PcdDxeNxMemoryProtectionPolicy enabled for EfiBootServicesData.<= BR>" - #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdAcpiS3Enable_PROMPT #langua= ge en-US "ACPI S3 Enable" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdAcpiS3Enable_HELP #language= en-US "Indicates if ACPI S3 will be enabled.

" @@ -1096,51 +1086,6 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSmiHandlerProfilePropertyMas= k_HELP #language en-US "The mask is used to control SmiHandlerProfile beha= vior.

\n" = "BIT0 - Enable SmiHandlerProfile.
" =20 -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdImageProtectionPolicy_PROMPT= #language en-US "Set image protection policy." - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdImageProtectionPolicy_HELP = #language en-US "Set image protection policy. The policy is bitwise.\n" - = "If a bit is set, the image will be protected by DxeCore if= it is aligned.\n" - = "The code section becomes read-only, and the data section b= ecomes non-executable.\n" - = "If a bit is clear, nothing will be done to image code/data= sections.

\n" - = "BIT0 - Image from unknown device.
\n" - = "BIT1 - Image from firmware volume.
" - = "Note: If a bit is cleared, the data section could be still= non-executable if\n" - = "PcdDxeNxMemoryProtectionPolicy is enabled for EfiLoaderDat= a, EfiBootServicesData\n" - = "and/or EfiRuntimeServicesData.
" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdDxeNxMemoryProtectionPolicy_= PROMPT #language en-US "Set DXE memory protection policy." - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdDxeNxMemoryProtectionPolicy_= HELP #language en-US "Set DXE memory protection policy. The policy is bitw= ise.\n" - = "If a bit is set, memory regions of the associated ty= pe will be mapped\n" - = "non-executable.
\n" - = "If a bit is cleared, nothing will be done to associa= ted type of memory.

\n" - = "\n" - = "Below is bit mask for this PCD: (Order is same as UE= FI spec)
\n" - = "EfiReservedMemoryType 0x0001
\n" - = "EfiLoaderCode 0x0002
\n" - = "EfiLoaderData 0x0004
\n" - = "EfiBootServicesCode 0x0008
\n" - = "EfiBootServicesData 0x0010
\n" - = "EfiRuntimeServicesCode 0x0020
\n" - = "EfiRuntimeServicesData 0x0040
\n" - = "EfiConventionalMemory 0x0080
\n" - = "EfiUnusableMemory 0x0100
\n" - = "EfiACPIReclaimMemory 0x0200
\n" - = "EfiACPIMemoryNVS 0x0400
\n" - = "EfiMemoryMappedIO 0x0800
\n" - = "EfiMemoryMappedIOPortSpace 0x1000
\n" - = "EfiPalCode 0x2000
\n" - = "EfiPersistentMemory 0x4000
\n" - = "OEM Reserved 0x4000000000000000
\n" - = "OS Reserved 0x8000000000000000
\n" - = "\n" - = "NOTE: User must NOT set NX protection for EfiLoaderC= ode / EfiBootServicesCode / EfiRuntimeServicesCode.
\n" - = "User MUST set the same NX protection for EfiBootServ= icesData and EfiConventionalMemory.
\n" - = "\n" - = "e.g. 0x7FD5 can be used for all memory except Code. =
\n" - = "e.g. 0x7BD4 can be used for all memory except Code a= nd ACPINVS/Reserved.
\n" - = "" - #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPteMemoryEncryptionAddressOr= Mask_PROMPT #language en-US "The address mask when memory encryption is en= abled." =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPteMemoryEncryptionAddressOr= Mask_HELP #language en-US "This PCD holds the address mask for page table = entries when memory encryption is\n" @@ -1186,110 +1131,12 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCodRelocationDevPath_HELP #= language en-US "Full device path of platform specific device to store Cap= sule On Disk temp relocation file.
" = "If this PCD is set, Capsule On Disk temp relocation file = will be stored in the device specified by this PCD, instead of the EFI Syst= em Partition that stores capsule image file." =20 -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdNullPointerDetectionProperty= Mask_PROMPT #language en-US "Enable NULL pointer detection" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdNullPointerDetectionProperty= Mask_HELP #language en-US "Mask to control the NULL address detection in= code for different phases.\n" - = " If enabled, accessing NULL address in UEFI o= r SMM code can be caught.\n\n" - = " BIT0 - Enable NULL pointer detection fo= r UEFI.\n" - = " BIT1 - Enable NULL pointer detection fo= r SMM.\n" - = " BIT2..6 - Reserved for future uses.\n" - = " BIT7 - Disable NULL pointer detection j= ust after EndOfDxe." - = " This is a workaround for those unsolvable NU= LL access issues in" - = " OptionROM, boot loader, etc. It can also hel= p to avoid unnecessary" - = " exception caused by legacy memory (0-4095) a= ccess after EndOfDxe," - = " such as Windows 7 boot on Qemu.\n" - #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdInitValueInTempStack_PROMPT = #language en-US "Init Value in Temp Stack" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdInitValueInTempStack_HELP = #language en-US "Init Value in Temp Stack to be shared between SEC and PEI= _CORE\n" = "SEC fills the full temp stack with this values. When swit= ch stack, PeiCore can check\n" = "this value in the temp stack to know how many stack has b= een used.\n" =20 -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPageType_PROMPT #l= anguage en-US "The memory type mask for Page Guard" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPageType_HELP #l= anguage en-US "Indicates which type allocation need guard page.\n\n" - = " If a bit is set, a head guard page and a tail guard page wi= ll be added just\n" - = " before and after corresponding type of pages allocated if t= here's enough\n" - = " free pages for all of them. The page allocation for the typ= e related to\n" - = " cleared bits keeps the same as ususal.\n\n" - = " This PCD is only valid if BIT0 and/or BIT2 are set in PcdHe= apGuardPropertyMask.\n\n" - = " Below is bit mask for this PCD: (Order is same as UEFI spec= )
\n" - = " EfiReservedMemoryType 0x0000000000000001\n" - = " EfiLoaderCode 0x0000000000000002\n" - = " EfiLoaderData 0x0000000000000004\n" - = " EfiBootServicesCode 0x0000000000000008\n" - = " EfiBootServicesData 0x0000000000000010\n" - = " EfiRuntimeServicesCode 0x0000000000000020\n" - = " EfiRuntimeServicesData 0x0000000000000040\n" - = " EfiConventionalMemory 0x0000000000000080\n" - = " EfiUnusableMemory 0x0000000000000100\n" - = " EfiACPIReclaimMemory 0x0000000000000200\n" - = " EfiACPIMemoryNVS 0x0000000000000400\n" - = " EfiMemoryMappedIO 0x0000000000000800\n" - = " EfiMemoryMappedIOPortSpace 0x0000000000001000\n" - = " EfiPalCode 0x0000000000002000\n" - = " EfiPersistentMemory 0x0000000000004000\n" - = " OEM Reserved 0x4000000000000000\n" - = " OS Reserved 0x8000000000000000\n" - = " e.g. LoaderCode+LoaderData+BootServicesCode+BootServicesDat= a are needed, 0x1E should be used.
" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPoolType_PROMPT #l= anguage en-US "The memory type mask for Pool Guard" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPoolType_HELP #l= anguage en-US "Indicates which type allocation need guard page.\n\n" - = " If a bit is set, a head guard page and a tail guard page wi= ll be added just\n" - = " before and after corresponding type of pages which the allo= cated pool occupies,\n" - = " if there's enough free memory for all of them. The pool all= ocation for the\n" - = " type related to cleared bits keeps the same as ususal.\n\n" - = " This PCD is only valid if BIT1 and/or BIT3 are set in PcdHe= apGuardPropertyMask.\n\n" - = " Below is bit mask for this PCD: (Order is same as UEFI spec= )
\n" - = " EfiReservedMemoryType 0x0000000000000001\n" - = " EfiLoaderCode 0x0000000000000002\n" - = " EfiLoaderData 0x0000000000000004\n" - = " EfiBootServicesCode 0x0000000000000008\n" - = " EfiBootServicesData 0x0000000000000010\n" - = " EfiRuntimeServicesCode 0x0000000000000020\n" - = " EfiRuntimeServicesData 0x0000000000000040\n" - = " EfiConventionalMemory 0x0000000000000080\n" - = " EfiUnusableMemory 0x0000000000000100\n" - = " EfiACPIReclaimMemory 0x0000000000000200\n" - = " EfiACPIMemoryNVS 0x0000000000000400\n" - = " EfiMemoryMappedIO 0x0000000000000800\n" - = " EfiMemoryMappedIOPortSpace 0x0000000000001000\n" - = " EfiPalCode 0x0000000000002000\n" - = " EfiPersistentMemory 0x0000000000004000\n" - = " OEM Reserved 0x4000000000000000\n" - = " OS Reserved 0x8000000000000000\n" - = " e.g. LoaderCode+LoaderData+BootServicesCode+BootServicesDat= a are needed, 0x1E should be used.
" - - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPropertyMask_PROMPT= #language en-US "The Heap Guard feature mask" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPropertyMask_HELP = #language en-US "This mask is to control Heap Guard behavior.\n" - = " Note:\n" - = " a) Heap Guard is for debug purpose and should not be = enabled in product" - = " BIOS.\n" - = " b) Due to the limit of pool memory implementation and= the alignment" - = " requirement of UEFI spec, BIT7 is a try-best setti= ng which cannot" - = " guarantee that the returned pool is exactly adjace= nt to head guard" - = " page or tail guard page.\n" - = " c) UEFI freed-memory guard and UEFI pool/page guard c= annot be enabled" - = " at the same time.\n" - = " BIT0 - Enable UEFI page guard.
\n" - = " BIT1 - Enable UEFI pool guard.
\n" - = " BIT2 - Enable SMM page guard.
\n" - = " BIT3 - Enable SMM pool guard.
\n" - = " BIT4 - Enable UEFI freed-memory guard (Use-After-Free= memory detection).
\n" - = " BIT7 - The direction of Guard Page for Pool Guard.\n" - = " 0 - The returned pool is near the tail guard p= age.
\n" - = " 1 - The returned pool is near the head guard p= age.
" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCpuStackGuard_PROMPT #langu= age en-US "Enable UEFI Stack Guard" - -#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCpuStackGuard_HELP #langu= age en-US "Indicates if UEFI Stack Guard will be enabled.\n" - = " If enabled, stack overflow in UEFI can be caught, preventing c= haotic consequences.

\n" - = " TRUE - UEFI Stack Guard will be enabled.
\n" - = " FALSE - UEFI Stack Guard will be disabled.
" - #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_PROMPT #= language en-US "Debug level of Trace Hub." =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_HELP #= language en-US "Indicate debug level of Trace Hub" --=20 2.42.0.windows.1 -=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 (#108180): https://edk2.groups.io/g/devel/message/108180 Mute This Topic: https://groups.io/mt/101064101/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-