From e050577f0a1729a0d34287ed990c1fab19a072e7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Feb 2021 19:07:47 +0100 Subject: [PATCH] Kernel: Make MAP_RANDOMIZED honor alignment requests Previously, we only cared about the alignment on the fallback path. --- Kernel/VM/RangeAllocator.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index a3168cf1f33..c481ddfa4a4 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -104,8 +104,7 @@ Optional RangeAllocator::allocate_randomized(size_t size, size_t alignmen // FIXME: I'm sure there's a smarter way to do this. static constexpr size_t maximum_randomization_attempts = 1000; for (size_t i = 0; i < maximum_randomization_attempts; ++i) { - VirtualAddress random_address { get_good_random() }; - random_address.mask(PAGE_MASK); + VirtualAddress random_address { round_up_to_power_of_two(get_good_random(), alignment) }; if (!m_total_range.contains(random_address, size)) continue;