mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-17 05:12:58 +00:00
Kernel: Add some bits of randomness to the userspace stack pointer
This patch adds a random offset between 0 and 4096 to the initial stack pointer in new processes. Since the stack has to be 16-byte aligned, the bottom bits can't be randomized. Yet another thing to make things less predictable. :^)
This commit is contained in:
parent
4188373020
commit
e47bffdc8c
|
@ -90,7 +90,10 @@ static bool validate_stack_size(const Vector<String>& arguments, const Vector<St
|
|||
|
||||
static KResultOr<FlatPtr> make_userspace_stack_for_main_thread(Region& region, Vector<String> arguments, Vector<String> environment, Vector<ELF::AuxiliaryValue> auxiliary_values)
|
||||
{
|
||||
FlatPtr new_esp = region.vaddr().offset(Thread::default_userspace_stack_size).get();
|
||||
FlatPtr new_esp = region.range().end().get();
|
||||
|
||||
// Add some bits of randomness to the user stack pointer.
|
||||
new_esp -= round_up_to_power_of_two(get_fast_random<u32>() % 4096, 16);
|
||||
|
||||
auto push_on_new_stack = [&new_esp](u32 value) {
|
||||
new_esp -= 4;
|
||||
|
|
Loading…
Reference in a new issue