From nobody Sun Feb 8 20:28:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106825+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+106825+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689119586; cv=none; d=zohomail.com; s=zohoarc; b=eCiurPiFUthl/ioiJGEJNwCqze79KcxVYpFIRyLMb3t0Y4/Wzo5R1vVMzjM5FfcDmbgDKiXpFcFa+JzIFafVzSOfHpDEoIDGTUe1iQ95ceE3ekCQpJuqqX1XTmTveC4VSYS0uroH3aWEEMuYkFzAaAonC7kaeZwClzJqG0Lhp9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689119586; 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=vQOeLCqoCAixLvfrJVeSHSjCQtIlfVk60x7M0IEkv/U=; b=iwWIYEz4Zen8QOibo4MvY5liU5i978GlGnaB/Ts0Alne3REqjQddIrzXS6lsO0ZblO4vdCp2a4IVdA6UonDYqZqM4FyOhMpOeYJGLVSTty68yCtn/NTiWJ6SgmXhV/JKpICc6GTHdLYVyvZoiv9u59sieilVVTgjlfdd6RutrzU= 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+106825+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689119586981683.3679951625163; Tue, 11 Jul 2023 16:53:06 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Q3I8NdOHkqim3EJjdgMoVjc/YvO4oHJaoRsgCldv3m0=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689119586; v=1; b=TKFFG+geG+/OQunUa5GeafQHcK5B7gJb+hsX6XDht47IMG8M/Mrt0FWFFtuSKZ5o7qPyzPIc 9WFE6iH/a9AHm6NdvZ/dpPTU02uSeVIhA8x8xV1K3M9CfBhfavseAnVf5eKP9kePZ+YzAJGcpBU /YNLg11LENnw0WRwtDRg4s5k= X-Received: by 127.0.0.2 with SMTP id GKD7YY1788612xmvNE9t9tHF; Tue, 11 Jul 2023 16:53:06 -0700 X-Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by mx.groups.io with SMTP id smtpd.web10.1850.1689119585215199908 for ; Tue, 11 Jul 2023 16:53:05 -0700 X-Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3a3efebcc24so3753572b6e.1 for ; Tue, 11 Jul 2023 16:53:05 -0700 (PDT) X-Gm-Message-State: QHuf55urTSCkPhTyODAxWVqWx1787277AA= X-Google-Smtp-Source: APBJJlGHheeSwAIkZ6L5M4MlQ5ujkIMUu0JfJ+MP7c8Dpu7OX8a6qFEqI3e9hyjnPJYjcgH/sScrrg== X-Received: by 2002:a05:6808:238a:b0:3a3:61fc:f913 with SMTP id bp10-20020a056808238a00b003a361fcf913mr20719402oib.0.1689119584361; Tue, 11 Jul 2023 16:53:04 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id a13-20020a62e20d000000b00660d80087a8sm2232677pfi.187.2023.07.11.16.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 16:53:04 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH 02/14] MdeModulePkg: Add MemoryProtectionHobLib Definitions and NULL Libs Date: Tue, 11 Jul 2023 16:52:39 -0700 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689119587987100005 Content-Type: text/plain; charset="utf-8" From: Taylor Beebe DxeMemoryProtectionHobLib and MmMemoryProtectionHobLib will fetch the memory protection settings HOB entry for their respective phase, validate the settings, and populate a global for access. Memory protection settings are currently dictated via FixedAtBuild PCDs where the settings needed to be masked. A future patch series will replace instances of checking the PCDs with checks to the memory protection globals populated by MemoryProtectionHobLib. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- .../Library/DxeMemoryProtectionHobLib.h | 20 +++++++++++++ .../Library/MmMemoryProtectionHobLib.h | 20 +++++++++++++ .../DxeMemoryProtectionHobLibNull.c | 13 +++++++++ .../DxeMemoryProtectionHobLibNull.inf | 28 +++++++++++++++++++ .../MmMemoryProtectionHobLibNull.c | 13 +++++++++ .../MmMemoryProtectionHobLibNull.inf | 28 +++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 8 ++++++ MdeModulePkg/MdeModulePkg.dsc | 8 ++++++ 8 files changed, 138 insertions(+) create mode 100644 MdeModulePkg/Include/Library/DxeMemoryProtectionHobLib.h create mode 100644 MdeModulePkg/Include/Library/MmMemoryProtectionHobLib.h create mode 100644 MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemo= ryProtectionHobLibNull.c create mode 100644 MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemo= ryProtectionHobLibNull.inf create mode 100644 MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemor= yProtectionHobLibNull.c create mode 100644 MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemor= yProtectionHobLibNull.inf diff --git a/MdeModulePkg/Include/Library/DxeMemoryProtectionHobLib.h b/Mde= ModulePkg/Include/Library/DxeMemoryProtectionHobLib.h new file mode 100644 index 0000000000..a6809e564c --- /dev/null +++ b/MdeModulePkg/Include/Library/DxeMemoryProtectionHobLib.h @@ -0,0 +1,20 @@ +/** @file + +Library for accessing memory protection settings. + +Copyright (C) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef DXE_MEMORY_PROTECTION_HOB_LIB_H_ +#define DXE_MEMORY_PROTECTION_HOB_LIB_H_ + +#include + +// +// The global used to access current Memory Protection Settings +// +extern DXE_MEMORY_PROTECTION_SETTINGS gDxeMps; + +#endif diff --git a/MdeModulePkg/Include/Library/MmMemoryProtectionHobLib.h b/MdeM= odulePkg/Include/Library/MmMemoryProtectionHobLib.h new file mode 100644 index 0000000000..09c25e878e --- /dev/null +++ b/MdeModulePkg/Include/Library/MmMemoryProtectionHobLib.h @@ -0,0 +1,20 @@ +/** @file + +Library for accessing memory protection settings. + +Copyright (C) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_MEMORY_PROTECTION_HOB_LIB_H_ +#define MM_MEMORY_PROTECTION_HOB_LIB_H_ + +#include + +// +// The global used to access current Memory Protection Settings +// +extern MM_MEMORY_PROTECTION_SETTINGS gMmMps; + +#endif diff --git a/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProte= ctionHobLibNull.c b/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemo= ryProtectionHobLibNull.c new file mode 100644 index 0000000000..2191a136b7 --- /dev/null +++ b/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProtectionHo= bLibNull.c @@ -0,0 +1,13 @@ +/** @file +Library defines the gDxeMps global + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +// A global variable which is uninitialized will be zero. +// The net effect is memory protections will be OFF. +DXE_MEMORY_PROTECTION_SETTINGS gDxeMps; diff --git a/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProte= ctionHobLibNull.inf b/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMe= moryProtectionHobLibNull.inf new file mode 100644 index 0000000000..65f66936e3 --- /dev/null +++ b/MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProtectionHo= bLibNull.inf @@ -0,0 +1,28 @@ +## @file +# NULL library which defines gDxeMps +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeMemoryProtectionHobLibNull + FILE_GUID =3D a35c1dc1-0769-421b-a8bc-9db69fae4334 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D DxeMemoryProtectionHobLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + DxeMemoryProtectionHobLibNull.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseMemoryLib diff --git a/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtec= tionHobLibNull.c b/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemory= ProtectionHobLibNull.c new file mode 100644 index 0000000000..6b3f6bae8d --- /dev/null +++ b/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtectionHob= LibNull.c @@ -0,0 +1,13 @@ +/** @file +Library defines the gMmMps global + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +// A global variable which is uninitialized will be zero. +// The net effect is memory protections will be OFF. +MM_MEMORY_PROTECTION_SETTINGS gMmMps; diff --git a/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtec= tionHobLibNull.inf b/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemo= ryProtectionHobLibNull.inf new file mode 100644 index 0000000000..5621ccbdb6 --- /dev/null +++ b/MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtectionHob= LibNull.inf @@ -0,0 +1,28 @@ +## @file +# NULL library which defines gMmMps +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MmMemoryProtectionHobLibNull + FILE_GUID =3D 4e3f6fd9-4ab5-4911-b80b-009d3338b4b2 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MmMemoryProtectionHobLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + MmMemoryProtectionHobLibNull.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseMemoryLib diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index f8c0fb4e93..2541b2b044 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -164,6 +164,14 @@ # VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h =20 + ## @libraryclass Provides a way to toggle DXE memory protection settings + # + DxeMemoryProtectionHobLib|Include/Library/DxeMemoryProtectionHobLib.h + + ## @libraryclass Provides a way to toggle SMM memory protection settings + # + MmMemoryProtectionHobLib|Include/Library/MmMemoryProtectionHobLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 1aedfe280a..3fad493c7f 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -107,6 +107,12 @@ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiComma= ndLibNull.inf =20 +[LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_CORE, Library= Classes.common.UEFI_APPLICATION] + DxeMemoryProtectionHobLib|MdeModulePkg/Library/MemoryProtectionHobLibNul= l/DxeMemoryProtectionHobLibNull.inf + +[LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER, Lib= raryClasses.common.MM_CORE_STANDALONE, LibraryClasses.common.MM_STANDALONE] + MmMemoryProtectionHobLib|MdeModulePkg/Library/MemoryProtectionHobLibNull= /MmMemoryProtectionHobLibNull.inf + [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf =20 @@ -231,6 +237,8 @@ MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf + MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProtectionHobLi= bNull.inf + MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtectionHobLib= Null.inf MdeModulePkg/Library/PciHostBridgeLibNull/PciHostBridgeLibNull.inf MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTa= bleLib.inf MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106825): https://edk2.groups.io/g/devel/message/106825 Mute This Topic: https://groups.io/mt/100090632/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-