From 41b4600c308d13fc90cef308c8fbb8f0e15f4e5f Mon Sep 17 00:00:00 2001 From: Jian J Wang Date: Fri, 15 Dec 2017 10:25:12 +0800 Subject: [PATCH] MdeModulePkg/DxeIplPeim: fix incorrect page table split during protecting The root cause of this issue is that, during splitting page table, the page size should be the value of next level (smaller one) instead of current level. The wrong page size will then cause wrong page table introduced, which will break the normal boot. Validation works include booting to Windows 10 and Fedora 26 on real Intel platform and OVMF emulated platform in addition to manual checks on page table with JTAG tool. Cc: Ruiyu Ni Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang Reviewed-by: Star Zeng --- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index 26116e420c..bbdfa2bb8e 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -472,6 +472,8 @@ SetPageTablePoolReadOnly ( // // The smaller granularity of page must be needed. // + ASSERT (Level > 1); + NewPageTable = AllocatePageTableMemory (1); ASSERT (NewPageTable != NULL); @@ -481,10 +483,10 @@ SetPageTablePoolReadOnly ( ++EntryIndex) { NewPageTable[EntryIndex] = PhysicalAddress | AddressEncMask | IA32_PG_P | IA32_PG_RW; - if (Level > 1) { + if (Level > 2) { NewPageTable[EntryIndex] |= IA32_PG_PS; } - PhysicalAddress += LevelSize[Level]; + PhysicalAddress += LevelSize[Level - 1]; } PageTable[Index] = (UINT64)(UINTN)NewPageTable | AddressEncMask | -- 2.39.2