From 8483681426b5a33e9d186758c47def0f1fcd86e2 Mon Sep 17 00:00:00 2001 From: Heyi Guo Date: Wed, 9 Sep 2015 13:37:50 +0000 Subject: ArmPkg/Mmu: Fix potential page table memory leak During page entry attribute update, if there are table entries between starting BlockEntry and LastBlockEntry, table entries will be set as block entries and the allocated memory of the tables will be leaked. So instead, we break the inner loop when we find a table entry and run outer loop again to step into the table by the same logic. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo Cc: Leif Lindholm [ardb: move termination condition check inside the loop] Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18425 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c index 850fe7f..df37154 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c @@ -455,6 +455,13 @@ FillTranslationTable ( RegionStart += BlockEntrySize; RemainingRegionLength -= BlockEntrySize; BlockEntry++; + + // Break the inner loop when next block is a table + // Rerun GetBlockEntryListFromAddress to avoid page table memory leak + if (TableLevel != 3 && + (*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY) { + break; + } } while ((RemainingRegionLength >= BlockEntrySize) && (BlockEntry <= LastBlockEntry)); } while (RemainingRegionLength != 0); -- cgit v1.1