From nobody Mon Sep 16 19:39:39 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+105305+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+105305+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685025075; cv=none; d=zohomail.com; s=zohoarc; b=e0raf/B92R7vEichUL7N32BzJS2+ysu+MtpPKMmpvcpeZlftbatbXMlhhkXwum70msfnAi0AykkpTUmLnJGX01xfJCSqLWKbl+JLB9zqgcm7CO599jnxnASAJILNoMT6/sb8hyB9oSupWCWQMwgJToJ0wSooYNzHcXJFCfTxzes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685025075; 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=l7kEuTSaaXba6zL7IrEebTY44FuNDBQNmyqs/am9voA=; b=bLo9jmy8l5iqqpXEuT53rRevuxpjPAjMCBGKbgMxluxjlMTqXuSptYmSgeerlAxdg94iPs+HIaNBmDjiZuq3k8KuN4qkSXYRM+P1eb6fkkD6XOKY8/1I+/vRdIjPVFslq0G17w3qhEGcbtdNv79n9Wfx6VRZfuGH688lS68hlPw= 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+105305+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 1685025075070915.8731589632764; Thu, 25 May 2023 07:31:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id blDzYY1788612xTgSesBMd5J; Thu, 25 May 2023 07:31:14 -0700 X-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 X-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) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98803C433EF; Thu, 25 May 2023 14:31:10 +0000 (UTC) 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: [edk2-devel] [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> In-Reply-To: <20230525143041.1172989-1-ardb@kernel.org> References: <20230525143041.1172989-1-ardb@kernel.org> 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,ardb@kernel.org X-Gm-Message-State: CjOVyNdj2KEeaq3PsLzwN1jVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685025074; bh=3+Ydrhw9Y2QuLRzty6lTsvLETB3ITW2t2IdsjBR7DBw=; h=Cc:Date:From:Reply-To:Subject:To; b=aT7Sb8W7a8IDuWDHPB7aa/MXvYMtai8HFb0ZxEmJvjrx+trKhslQB3JyEpruh/uW8iZ CegEararaiN+faEmu6xC2gBIZtM/Q4Auivhrrb6FBbnt669nMov3dxow6Qlm3FTBiNro3 Pr27iRyn/WOQOEzrbgPYmlR8L6sQMqu62C8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685025075863100005 Content-Type: text/plain; charset="utf-8" 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 + +Copyright (c) 2023, Google LLC. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_MEMORY_ATTRIBUTE_PPI_H_ +#define EDKII_MEMORY_ATTRIBUTE_PPI_H_ + +#include + +/// +/// Global ID for the EDKII_MEMORY_ATTRIBUTE_PPI. +/// +#define EDKII_MEMORY_ATTRIBUTE_PPI_GUID \ + { \ + 0x1be840de, 0x2d92, 0x41ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51= , 0xfb } \ + } + +/// +/// Forward declaration for the EDKII_MEMORY_ATTRIBUTE_PPI. +/// +typedef struct _EDKII_MEMORY_ATTRIBUTE_PPI EDKII_MEMORY_ATTRIBUTE_PPI; + +/** + Set the requested memory permission attributes on a region of memory. + + BaseAddress and Length must be aligned to EFI_PAGE_SIZE. + + Both SetMask and ClearMask may contain any combination of EFI_MEMORY_RP, + EFI_MEMORY_RO and EFI_MEMORY_XP, with the following restrictions: + - each constant may appear in either SetMask or ClearMask, but not in bo= th; + - SetMask or ClearMask may be 0x0, but not both. + + @param[in] This The protocol instance pointer. + @param[in] BaseAddress The physical address that is the start addre= ss of + a memory region. + @param[in] Length The size in bytes of the memory region. + @param[in] SetMask Mask of memory attributes to set. + @param[in] ClearMask Mask of memory attributes to clear. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER Length is zero. + Invalid combination of SetMask and ClearMa= sk. + BaseAddress or Length is not suitably alig= ned. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specifi= ed + by BaseAddress and Length. + The bit mask of attributes is not supporte= d for + the memory resource range specified by + BaseAddress and Length. + @retval EFI_OUT_OF_RESOURCES Requested attributes cannot be applied due= to + lack of system resources. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS)( + IN EDKII_MEMORY_ATTRIBUTE_PPI *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 SetMask, + IN UINT64 ClearMask + ); + +/// +/// This PPI contains a set of services to manage memory permission attrib= utes. +/// +struct _EDKII_MEMORY_ATTRIBUTE_PPI { + EDKII_MEMORY_ATTRIBUTE_SET_PERMISSIONS SetPermissions; +}; + +extern EFI_GUID gEdkiiMemoryAttributePpiGuid; + +#endif + 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 } } gEdkiiPeiBootInCapsuleOnDiskModePpiGuid =3D { 0xb08a11e4, 0xe2b7, 0x4b= 75, { 0xb5, 0x15, 0xaf, 0x61, 0x6, 0x68, 0xbf, 0xd1 } } =20 + ## Include/Ppi/MemoryAttribute.h + gEdkiiMemoryAttributePpiGuid =3D { 0x1be840de, 0x2d92, 0x41= ec, { 0xb6, 0xd3, 0x19, 0x64, 0x13, 0x50, 0x51, 0xfb } } + [Protocols] ## Load File protocol provides capability to load and unload EFI image i= nto memory and execute it. # Include/Protocol/LoadPe32Image.h --=20 2.39.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 (#105305): https://edk2.groups.io/g/devel/message/105305 Mute This Topic: https://groups.io/mt/99131184/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-