mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +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
|
@ -2,6 +2,7 @@
|
|||
#include <Kernel/Process.h>
|
||||
#include <Kernel/ProcessTracer.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
|
||||
extern "C" void syscall_trap_entry(RegisterDump);
|
||||
extern "C" void syscall_trap_handler();
|
||||
|
@ -91,6 +92,13 @@ int handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3)
|
|||
void syscall_trap_entry(RegisterDump regs)
|
||||
{
|
||||
auto& process = current->process();
|
||||
|
||||
if (!MM.validate_user_stack(process, VirtualAddress(regs.esp_if_crossRing))) {
|
||||
dbgprintf("Invalid stack pointer: %p\n", regs.esp_if_crossRing);
|
||||
handle_crash(regs, "Bad stack on syscall entry", SIGSTKFLT);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
process.big_lock().lock();
|
||||
u32 function = regs.eax;
|
||||
u32 arg1 = regs.edx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue