From 357ddd393ebd38321f8bc02274942fcad29a1ac9 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 18 Jul 2021 02:48:35 +0200 Subject: [PATCH] Kernel: Make allocate_randomized() work for 64-bit addresses The odds of finding a suitable address in 1000 attempts were not in our favor given the size of the 64-bit address space. --- Kernel/VM/RangeAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index 29d9350483..3ab88abdea 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -67,7 +67,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 { round_up_to_power_of_two(get_fast_random(), alignment) }; + VirtualAddress random_address { round_up_to_power_of_two(get_fast_random() % m_total_range.end().get(), alignment) }; if (!m_total_range.contains(random_address, size)) continue;