summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2022-12-07 18:49:45 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-12-08 18:09:48 +0000
commit54d81d06fc165fcb8eb832acd6a7cf644b029549 (patch)
tree07568d4a75ea5b7ede9ca7b394e8aad9d705fefa /MdeModulePkg
parent8a485e4bb8b5c5a800d6b3e1b8fa80fe27afb274 (diff)
downloadedk2-54d81d06fc165fcb8eb832acd6a7cf644b029549.tar.gz
edk2-54d81d06fc165fcb8eb832acd6a7cf644b029549.tar.bz2
edk2-54d81d06fc165fcb8eb832acd6a7cf644b029549.zip
MdeModulePkg/DxeCore: Use correct type for alignment mask
The page allocator code in CoreFindFreePagesI() uses a mask derived from its UINTN Alignment argument to align the descriptor end address of a MEMORY_MAP entry to the requested alignment, in order to check whether the descriptor covers enough sufficiently aligned area to satisfy the request. However, on 32-bit architectures, 'Alignment' is a 32-bit type, whereas DescEnd is a 64-bit type, and so the resulting operation performed on the end address comes down to masking with 0xfffff000 instead of the intended 0xffffffff_fffff000. Given the -1 at the end of the expression, the resulting address is 0xffffffff_fffffffff for any descriptor that ends on a 4G aligned boundary, and this is certainly not what was intended. So cast Alignment to UINT64 to ensure that the mask has the right size. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reported-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Page.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 160289c1f9..5903ce7ab5 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1097,7 +1097,7 @@ CoreFindFreePagesI (
DescEnd = MaxAddress;
}
- DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1;
+ DescEnd = ((DescEnd + 1) & (~((UINT64)Alignment - 1))) - 1;
// Skip if DescEnd is less than DescStart after alignment clipping
if (DescEnd < DescStart) {