From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.13534.1685025074169821637 for ; Thu, 25 May 2023 07:31:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MSgitQ55; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B39CB61489; Thu, 25 May 2023 14:31:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98803C433EF; Thu, 25 May 2023 14:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685025073; bh=xQ9EdR0Yac58JbK9HHlPAxrASz2crdA8nYdEalUlYO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MSgitQ55VVdXmI/rSGSporNGU6Y/gPWqQJQ327ZXVE1nnK0edV7BU2Z6amyCnFJ3u h0kervn19V74flIzYFHHRBfapBn6vDoPpM8SRoTEhsLyXgSIPC7nHoq96IqV3jUeG4 i8Pw737mx53JuLP9ndy6VrKxDKhF7HlszdUL/Slnz6R0Ih9KCNUpqLn0mTQxss34vU 6HogMMi6ve+Uiiu3kawMu16WUjzp4jcsvdoNpqwkYwJOrXu3tzTc5IXAVaPjRAXx5P RiWnjTLVqPOGdnSMDAQEx6ghK1gcMgKM2EHRicGbehNCjzxYHyz0GA67T+7S9n4OyE pNPsQ2yR0ctIA== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Sunil V L , Andrei Warkentin Subject: [RFC PATCH 05/10] MdeModulePkg: Define memory attribute PPI Date: Thu, 25 May 2023 16:30:36 +0200 Message-Id: <20230525143041.1172989-6-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525143041.1172989-1-ardb@kernel.org> References: <20230525143041.1172989-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Define a PPI interface that may be used by the PEI core or other PEIMs to manage permissions on memory ranges. This is primarily intended for restricting permissions to what is actually needed for correct execution by the code in question, and for limiting the use of memory mappings that are both writable and executable at the same time. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Ppi/MemoryAttribute.h | 78 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 + 2 files changed, 81 insertions(+) diff --git a/MdeModulePkg/Include/Ppi/MemoryAttribute.h b/MdeModulePkg/Incl= ude/Ppi/MemoryAttribute.h new file mode 100644 index 0000000000000000..5ff31185ab4183f8 --- /dev/null +++ b/MdeModulePkg/Include/Ppi/MemoryAttribute.h @@ -0,0 +1,78 @@ +/** @file=0D +=0D +Copyright (c) 2023, Google LLC. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef EDKII_MEMORY_ATTRIBUTE_PPI_H_=0D +#define EDKII_MEMORY_ATTRIBUTE_PPI_H_=0D +=0D +#include =0D +=0D +///=0D +/// Global ID for the EDKII_MEMORY_ATTRIBUTE_PPI.=0D +///=0D +#define EDKII_MEMORY_ATTRIBUTE_PPI_GUID \=0D + { \=0D + 0x1be840de, 0x2d92, 0x41ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51= , 0xfb } \=0D + }=0D +=0D +///=0D +/// Forward declaration for the EDKII_MEMORY_ATTRIBUTE_PPI.=0D +///=0D +typedef struct _EDKII_MEMORY_ATTRIBUTE_PPI EDKII_MEMORY_ATTRIBUTE_PPI;=0D +=0D +/**=0D + Set the requested memory permission attributes on a region of memory.=0D +=0D + BaseAddress and Length must be aligned to EFI_PAGE_SIZE.=0D +=0D + Both SetMask and ClearMask may contain any combination of EFI_MEMORY_RP,= =0D + EFI_MEMORY_RO and EFI_MEMORY_XP, with the following restrictions:=0D + - each constant may appear in either SetMask or ClearMask, but not in bo= th;=0D + - SetMask or ClearMask may be 0x0, but not both.=0D +=0D + @param[in] This The protocol instance pointer.=0D + @param[in] BaseAddress The physical address that is the start addre= ss of=0D + a memory region.=0D + @param[in] Length The size in bytes of the memory region.=0D + @param[in] SetMask Mask of memory attributes to set.=0D + @param[in] ClearMask Mask of memory attributes to clear.=0D +=0D + @retval EFI_SUCCESS The attributes were set for the memory reg= ion.=0D + @retval EFI_INVALID_PARAMETER Length is zero.=0D + Invalid combination of SetMask and ClearMa= sk.=0D + BaseAddress or Length is not suitably alig= ned.=0D + @retval EFI_UNSUPPORTED The processor does not support one or more= =0D + bytes of the memory resource range specifi= ed=0D + by BaseAddress and Length.=0D + The bit mask of attributes is not supporte= d for=0D + the memory resource range specified by=0D + BaseAddress and Length.=0D + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to=0D + lack of system resources.=0D +=0D +**/=0D +typedef=0D +EFI_STATUS=0D +(EFIAPI *EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS)(=0D + IN EDKII_MEMORY_ATTRIBUTE_PPI *This,=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 SetMask,=0D + IN UINT64 ClearMask=0D + );=0D +=0D +///=0D +/// This PPI contains a set of services to manage memory permission attrib= utes.=0D +///=0D +struct _EDKII_MEMORY_ATTRIBUTE_PPI {=0D + EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS SetPermissions;=0D +};=0D +=0D +extern EFI_GUID gEdkiiMemoryAttributePpiGuid;=0D +=0D +#endif=0D +=0D diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 95dd077e19b3a901..d65dae18aa81e569 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -528,6 +528,9 @@ [Ppis] gEdkiiPeiCapsuleOnDiskPpiGuid =3D { 0x71a9ea61, 0x5a35, 0x4a= 5d, { 0xac, 0xef, 0x9c, 0xf8, 0x6d, 0x6d, 0x67, 0xe0 } }=0D gEdkiiPeiBootInCapsuleOnDiskModePpiGuid =3D { 0xb08a11e4, 0xe2b7, 0x4b= 75, { 0xb5, 0x15, 0xaf, 0x61, 0x6, 0x68, 0xbf, 0xd1 } }=0D =0D + ## Include/Ppi/MemoryAttribute.h=0D + gEdkiiMemoryAttributePpiGuid =3D { 0x1be840de, 0x2d92, 0x41= ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51, 0xfb } }=0D +=0D [Protocols]=0D ## Load File protocol provides capability to load and unload EFI image i= nto memory and execute it.=0D # Include/Protocol/LoadPe32Image.h=0D --=20 2.39.2