mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:45:09 +00:00
Kernel: Implement some basic stack pointer validation
VM regions can now be marked as stack regions, which is then validated on syscall, and on page fault. If a thread is caught with its stack pointer pointing into anything that's *not* a Region with its stack bit set, we'll crash the whole process with SIGSTKFLT. Userspace must now allocate custom stacks by using mmap() with the new MAP_STACK flag. This mechanism was first introduced in OpenBSD, and now we have it too, yay! :^)
This commit is contained in:
parent
197ed1bb2a
commit
794758df3a
12 changed files with 101 additions and 5 deletions
|
@ -569,6 +569,7 @@ void Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vect
|
|||
{
|
||||
auto* region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, "Stack (Main thread)", PROT_READ | PROT_WRITE, false);
|
||||
ASSERT(region);
|
||||
region->set_stack(true);
|
||||
m_tss.esp = region->vaddr().offset(default_userspace_stack_size).get();
|
||||
|
||||
char* stack_base = (char*)region->vaddr().get();
|
||||
|
@ -604,6 +605,7 @@ void Thread::make_userspace_stack_for_secondary_thread(void* argument)
|
|||
{
|
||||
m_userspace_stack_region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, String::format("Stack (Thread %d)", tid()), PROT_READ | PROT_WRITE, false);
|
||||
ASSERT(m_userspace_stack_region);
|
||||
m_userspace_stack_region->set_stack(true);
|
||||
m_tss.esp = m_userspace_stack_region->vaddr().offset(default_userspace_stack_size).get();
|
||||
|
||||
// NOTE: The stack needs to be 16-byte aligned.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue