diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-17 12:11:43 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-17 12:15:43 +0100 |
commit | 794758df3ace052c1d2f0d90dc99e6154e90be9d (patch) | |
tree | 99fdc414d7a50bed086fed34260e41bd74b75810 /Kernel/Thread.cpp | |
parent | 197ed1bb2a56677c6311d440d6246c9cd4b0a767 (diff) | |
download | serenity-794758df3ace052c1d2f0d90dc99e6154e90be9d.zip |
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! :^)
Diffstat (limited to 'Kernel/Thread.cpp')
-rw-r--r-- | Kernel/Thread.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 4e4f8fae14..f1034e61e4 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -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. |