mirror of
https://github.com/acidanthera/audk.git
synced 2025-04-08 17:05:09 +02:00
MdeModulePkg: MAT Set RO/XP on Code/Data Sections Outside Image Memory
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). The attributes of the code regions will be read-only and no-execute because the UEFI spec dictates that runtime code regions should only contain loaded EFI modules. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4832 Refs: 1. https://edk2.groups.io/g/devel/topic/patch_v1_mdemodulepkg/105570114?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,105570114 2. https://edk2.groups.io/g/devel/topic/mdemodulepkg_fix_mat/105477564?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,105477564 Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
This commit is contained in:
parent
254641f342
commit
bb248a9509
@ -447,16 +447,23 @@ 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:
|
||||
MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
|
||||
break;
|
||||
case EfiReservedMemoryType:
|
||||
case EfiACPIMemoryNVS:
|
||||
break;
|
||||
if ((MemoryMapEntry->Attribute & EFI_MEMORY_ACCESS_MASK) == 0) {
|
||||
switch (MemoryMapEntry->Type) {
|
||||
case EfiRuntimeServicesCode:
|
||||
// If at this point the attributes have not been set on an EfiRuntimeServicesCode
|
||||
// region, the memory range must not contain a loaded image. It's possible these
|
||||
// non-image EfiRuntimeServicesCode regions are part of the unused memory bucket.
|
||||
// It could also be that this region was explicitly allocated outside of the PE
|
||||
// loader but the UEFI spec requires that all EfiRuntimeServicesCode regions contain
|
||||
// EFI modules. In either case, set the attributes to RO and XP.
|
||||
MemoryMapEntry->Attribute |= (EFI_MEMORY_RO | EFI_MEMORY_XP);
|
||||
break;
|
||||
case EfiRuntimeServicesData:
|
||||
MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
|
||||
|
Loading…
x
Reference in New Issue
Block a user