From: Ard Biesheuvel Date: Fri, 4 Jan 2019 18:04:32 +0000 (+0100) Subject: ArmPkg/ArmMmuLib ARM: fix thinko in second level page table handling X-Git-Tag: edk2-stable201903~377 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=28ce4cb3590bc3aaa91c3be75429d4e8722415e2 ArmPkg/ArmMmuLib ARM: fix thinko in second level page table handling PopulateLevel2PageTable () is invoked for [parts of] mappings that start or end on a non-1 MB aligned address (or both). The size of the mapping depends on both the start address modulo 1 MB and the length of the mapping, but the logic that calculates this size is flawed: subtracting 'start address modulo 1 MB' could result in a negative value for the remaining length, which is obviously wrong. So instead, take either RemainLength, or the rest of the 1 MB block, whichever is smaller. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Tested-by: Eugene Cohen --- diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c index b237321a8d..3b3b20aa9b 100644 --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c @@ -294,8 +294,8 @@ FillTranslationTable ( PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE; RemainLength -= TT_DESCRIPTOR_SECTION_SIZE; } else { - PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE) - - (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE); + PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE - + (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE)); // Case: Physical address aligned on the Section Size (1MB) && the length // does not fill a section