Store the address of the SetMemoryAttributes() member of the CPU arch protocol in a global variable, and invoke it via this variable. This by itself should have not result in functional changes, but it permits platforms to provide an preliminary implementation of this member at link time, allowing the DXE core to enforce strict memory permissions even before dispatching the CPU arch protocol driver itself.
Signed-off-by: Ard Biesheuvel <a...@kernel.org> --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 854651556de4..c29985ad3116 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -66,6 +66,8 @@ extern LIST_ENTRY mGcdMemorySpaceMap; STATIC LIST_ENTRY mProtectedImageRecordList; +EFI_CPU_SET_MEMORY_ATTRIBUTES gCpuSetMemoryAttributes; + /** Sort code section in image record, based upon CodeSegmentBase from low to high. @@ -224,8 +226,8 @@ SetUefiImageMemoryAttributes ( DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", BaseAddress, Length, FinalAttributes)); - ASSERT (gCpu != NULL); - gCpu->SetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes); + ASSERT (gCpuSetMemoryAttributes != NULL); + gCpuSetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes); } /** @@ -408,7 +410,7 @@ ProtectUefiImage ( DEBUG ((DEBUG_INFO, "ProtectUefiImageCommon - 0x%x\n", LoadedImage)); DEBUG ((DEBUG_INFO, " - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)LoadedImage->ImageBase, LoadedImage->ImageSize)); - if (gCpu == NULL) { + if (gCpuSetMemoryAttributes == NULL) { return; } @@ -995,6 +997,8 @@ MemoryProtectionCpuArchProtocolNotify ( goto Done; } + gCpuSetMemoryAttributes = gCpu->SetMemoryAttributes; + // // Apply the memory protection policy on non-BScode/RTcode regions. // @@ -1278,7 +1282,7 @@ ApplyMemoryProtectionPolicy ( // permission attributes, and it is the job of the driver that installs this // protocol to set the permissions on existing allocations. // - if (gCpu == NULL) { + if (gCpuSetMemoryAttributes == NULL) { return EFI_SUCCESS; } @@ -1318,5 +1322,5 @@ ApplyMemoryProtectionPolicy ( // NewAttributes = GetPermissionAttributeForMemoryType (NewType); - return gCpu->SetMemoryAttributes (gCpu, Memory, Length, NewAttributes); + return gCpuSetMemoryAttributes (gCpu, Memory, Length, NewAttributes); } -- 2.39.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100094): https://edk2.groups.io/g/devel/message/100094 Mute This Topic: https://groups.io/mt/96937485/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-