In 32-bit mode, the BIOS will not create page table for memory beyond
4GB and therefore it cannot handle the attributes change request for
those memory. But current CpuDxe doesn't check this situation and still
try to complete the request, which will cause attributes of incorrect
memory address to be changed due to type cast from 64-bit to 32-bit.

This patch fixes this issue by checking the end address of input
memory block and returning EFI_UNSUPPORTED if it's out of range.

Cc: Eric Dong <eric.d...@intel.com>
Cc: Laszlo Ersek <ler...@redhat.com>
Cc: Ruiyu Ni <ruiyu...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.w...@intel.com>
---
 UefiCpuPkg/CpuDxe/CpuPageTable.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTable.c
index a9c9bc9d5e..3ad55f65c5 100644
--- a/UefiCpuPkg/CpuDxe/CpuPageTable.c
+++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c
@@ -699,6 +699,10 @@ ConvertMemoryPageAttributes (
       DEBUG ((DEBUG_ERROR, "Non-PAE Paging!\n"));
       return EFI_UNSUPPORTED;
     }
+    if ((BaseAddress + Length) > BASE_4GB) {
+      DEBUG ((DEBUG_ERROR, "Beyond 4GB memory in 32-bit mode!\n"));
+      return EFI_UNSUPPORTED;
+    }
     break;
   case IMAGE_FILE_MACHINE_X64:
     ASSERT (CurrentPagingContext.ContextData.X64.PageTableBase != 0);
-- 
2.15.1.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to