mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
Kernel: Add some bits of randomness to kernel stack pointers
Since kernel stacks are much smaller (64 KiB) than userspace stacks, we only add a small bit of randomness here (0-256 bytes, 16b aligned.) This makes the location of the task context switch buffer not be 100% predictable. Note that we still also add extra randomness upon syscall entry, so this patch primarily affects context switching.
This commit is contained in:
parent
e47bffdc8c
commit
0e92a80434
1 changed files with 4 additions and 0 deletions
|
@ -1405,6 +1405,10 @@ u32 Processor::init_context(Thread& thread, bool leave_crit)
|
|||
}
|
||||
|
||||
u32 kernel_stack_top = thread.kernel_stack_top();
|
||||
|
||||
// Add a random offset between 0-256 (16-byte aligned)
|
||||
kernel_stack_top -= round_up_to_power_of_two(get_fast_random<u8>(), 16);
|
||||
|
||||
u32 stack_top = kernel_stack_top;
|
||||
|
||||
// TODO: handle NT?
|
||||
|
|
Loading…
Add table
Reference in a new issue