From: Heyi Guo Date: Wed, 9 Sep 2015 13:37:22 +0000 (+0000) Subject: ArmPkg/Mmu: Fix page level calculation bug X-Git-Tag: edk2-stable201903~8895 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=946067bfb074962667bd61fafffd0e777242e12b ArmPkg/Mmu: Fix page level calculation bug The bug can be triggered when alignment of Base is larger than Length by 2 level of page granularity, e.g. Base is 0x4000_0000, Length is 0x1000 The original code will change 2MB page level and we will get a negative remaining length. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo Cc: Leif Lindholm Reviewed-by: Ard Biesheuvel git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18422 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c index a7f374531a..5b6c4537b5 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c @@ -314,7 +314,7 @@ GetBlockEntryListFromAddress ( // If the required size is smaller than the current block size then we need to go to the page below. // The PageLevel was calculated on the Base Address alignment but did not take in account the alignment // of the allocation size - if (*BlockEntrySize < TT_BLOCK_ENTRY_SIZE_AT_LEVEL (PageLevel)) { + while (*BlockEntrySize < TT_BLOCK_ENTRY_SIZE_AT_LEVEL (PageLevel)) { // It does not fit so we need to go a page level above PageLevel++; }