Kernel: Make MAP_RANDOMIZED honor alignment requests

Previously, we only cared about the alignment on the fallback path.
This commit is contained in:
Andreas Kling 2021-02-12 19:07:47 +01:00
parent 4e2802bf91
commit e050577f0a
Notes: sideshowbarker 2024-07-18 22:24:01 +09:00

View File

@ -104,8 +104,7 @@ Optional<Range> 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<FlatPtr>() };
random_address.mask(PAGE_MASK);
VirtualAddress random_address { round_up_to_power_of_two(get_good_random<FlatPtr>(), alignment) };
if (!m_total_range.contains(random_address, size))
continue;