Image protection in DXE pertains to the memory permission attributes
used at boot time, when the page size is guaranteed to be 4k. Whether or
not the minimum section alignment is even higher when running under the
OS is not relevant here, so just use the EFI page size as the minimum
section alignment directly.

Signed-off-by: Ard Biesheuvel <a...@kernel.org>
---
 MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 49 +-------------------
 1 file changed, 1 insertion(+), 48 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c 
b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
index 85c5a6a7c758..045e2f391bc0 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
@@ -304,51 +304,6 @@ SetUefiImageProtectionAttributes (
   return;
 }
 
-/**
-  Return if the PE image section is aligned.
-
-  @param[in]  SectionAlignment    PE/COFF section alignment
-  @param[in]  MemoryType          PE/COFF image memory type
-
-  @retval TRUE  The PE image section is aligned.
-  @retval FALSE The PE image section is not aligned.
-**/
-BOOLEAN
-IsMemoryProtectionSectionAligned (
-  IN UINT32           SectionAlignment,
-  IN EFI_MEMORY_TYPE  MemoryType
-  )
-{
-  UINT32  PageAlignment;
-
-  switch (MemoryType) {
-    case EfiRuntimeServicesCode:
-    case EfiACPIMemoryNVS:
-      PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
-      break;
-    case EfiRuntimeServicesData:
-    case EfiACPIReclaimMemory:
-      ASSERT (FALSE);
-      PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
-      break;
-    case EfiBootServicesCode:
-    case EfiLoaderCode:
-    case EfiReservedMemoryType:
-      PageAlignment = EFI_PAGE_SIZE;
-      break;
-    default:
-      ASSERT (FALSE);
-      PageAlignment = EFI_PAGE_SIZE;
-      break;
-  }
-
-  if ((SectionAlignment & (PageAlignment - 1)) != 0) {
-    return FALSE;
-  } else {
-    return TRUE;
-  }
-}
-
 /**
   Free Image record.
 
@@ -404,7 +359,6 @@ ProtectUefiImage (
   IMAGE_PROPERTIES_RECORD               *ImageRecord;
   CHAR8                                 *PdbPointer;
   IMAGE_PROPERTIES_RECORD_CODE_SECTION  *ImageRecordCodeSection;
-  BOOLEAN                               IsAligned;
   UINT32                                ProtectionPolicy;
 
   DEBUG ((DEBUG_INFO, "ProtectUefiImageCommon - 0x%x\n", LoadedImage));
@@ -470,8 +424,7 @@ ProtectUefiImage (
     SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
   }
 
-  IsAligned = IsMemoryProtectionSectionAligned (SectionAlignment, 
LoadedImage->ImageCodeType);
-  if (!IsAligned) {
+  if (SectionAlignment >= EFI_PAGE_SIZE) {
     DEBUG ((
       DEBUG_VERBOSE,
       "!!!!!!!!  ProtectUefiImageCommon - Section Alignment(0x%x) is incorrect 
 !!!!!!!!\n",
-- 
2.39.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101137): https://edk2.groups.io/g/devel/message/101137
Mute This Topic: https://groups.io/mt/97586054/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to