From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail04.groups.io (mail04.groups.io [45.79.224.9]) by spool.mail.gandi.net (Postfix) with ESMTPS id A599D78003C for ; Wed, 17 Apr 2024 02:28:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ez4qidUtZpuBLEOjlrvVVONek3ZSffNN3QSs2Rp28uc=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1713320931; v=1; b=S892Wt26Qwe4Q0bk/dWGJeS0howSFP6ffuBt6Z2QYauPBxoV89fmbs4nMEeNivt72DQRy9gy vEQe93EYTOta8uUFjauOZIqQwES6Pycshiw9uGNSSH4kYKxbqinJOrBpReawrXShotw6fwWBEGX 3zvR4U8dpnPoGMAU7lAQvYtQymGMHGqd4isyxicgIp7cc0i1sjLTPplHe10fQR2UxfGb9N9KprH CP/IgxgTNs0Z6wvx3xQcEs6AZu5Dl7VjGYbTOymXI0sfsC63ldcd4GQFeINt+6n7znOehKYotmG +A8/1AVut1eQz3oeNP0cJhhpkdsQzJwjNHUfg6p4uXdoQ== X-Received: by 127.0.0.2 with SMTP id qwuAYY7687511xCsw2sbS71c; Tue, 16 Apr 2024 19:28:51 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web10.3563.1713320930471480122 for ; Tue, 16 Apr 2024 19:28:50 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e3c3aa8938so32403045ad.1 for ; Tue, 16 Apr 2024 19:28:50 -0700 (PDT) X-Gm-Message-State: Is6E0DKax0SIIsMWYr2jgj6zx7686176AA= X-Google-Smtp-Source: AGHT+IF9HVxRVdIXg0yeOqog1dp6bjiQbXVqaI4Wny7i48YGFLPmWUAKBhulcZF4wxqy3H/aE5tC6A== X-Received: by 2002:a17:903:444:b0:1e4:b1a2:b40c with SMTP id iw4-20020a170903044400b001e4b1a2b40cmr10282659plb.42.1713320929650; Tue, 16 Apr 2024 19:28:49 -0700 (PDT) X-Received: from localhost.localdomain ([4.155.48.124]) by smtp.gmail.com with ESMTPSA id m1-20020a170902768100b001e5c7d05cc2sm8109832pll.184.2024.04.16.19.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 19:28:49 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Liming Gao Subject: [edk2-devel] [PATCH v1] MdeModulePkg: Fixup MAT Attributes After Splitting EFI Memory Map Date: Tue, 16 Apr 2024 19:28:36 -0700 Message-Id: <20240417022836.1593-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 Resent-Date: Tue, 16 Apr 2024 19:28:50 -0700 Resent-From: taylor.d.beebe@gmail.com Reply-To: devel@edk2.groups.io,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=S892Wt26; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.9 as permitted sender) smtp.mailfrom=bounce@groups.io The Memory Attributes Table is generated by fetching the EFI memory map and splitting entries which contain loaded images so DATA and CODE sections have separate descriptors. The splitting is done via a call to SplitTable() which marks image DATA sections with the EFI_MEMORY_XP attribute and CODE sections with the EFI_MEMORY_RO attribute when splitting. After this process, there may still be EfiRuntimeServicesCode regions which did not have their attributes set because they are not part of loaded images. This patch updates the MAT EnforceMemoryMapAttribute logic to set the access attributes of runtime memory regions which are not part of loaded images (have not had their access attributes set). Cc: Liming Gao Signed-off-by: Taylor Beebe --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index e9343a2c4e..1d9f935db0 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -425,8 +425,8 @@ MergeMemoryMap ( } /** - Enforce memory map attributes. - This function will set EfiRuntimeServicesData/EfiMemoryMappedIO/EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP. + Walk the memory map and set EfiRuntimeServicesData/EfiMemoryMappedIO/EfiMemoryMappedIOPortSpace + to EFI_MEMORY_XP and EfiRuntimeServicesCode to EFI_MEMORY_RO. @param MemoryMap A pointer to the buffer in which firmware places the current memory map. @@ -447,18 +447,19 @@ EnforceMemoryMapAttribute ( MemoryMapEntry = MemoryMap; MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize); while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) { - switch (MemoryMapEntry->Type) { - case EfiRuntimeServicesCode: - // do nothing - break; - case EfiRuntimeServicesData: - case EfiMemoryMappedIO: - case EfiMemoryMappedIOPortSpace: - MemoryMapEntry->Attribute |= EFI_MEMORY_XP; - break; - case EfiReservedMemoryType: - case EfiACPIMemoryNVS: - break; + if ((MemoryMapEntry->Attribute & EFI_MEMORY_ACCESS_MASK) == 0) { + switch (MemoryMapEntry->Type) { + case EfiRuntimeServicesCode: + MemoryMapEntry->Attribute |= EFI_MEMORY_RO; + break; + case EfiRuntimeServicesData: + case EfiMemoryMappedIO: + case EfiMemoryMappedIOPortSpace: + MemoryMapEntry->Attribute |= EFI_MEMORY_XP; + break; + default: + break; + } } MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize); -- 2.40.1.vfs.0.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117889): https://edk2.groups.io/g/devel/message/117889 Mute This Topic: https://groups.io/mt/105570114/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-