diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 878a37f710f0ad..18f4a3e1f0af25 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -1455,7 +1455,15 @@ bool MemoryManager::validate_user_stack(AddressSpace& space, VirtualAddress vadd return false; auto* region = find_user_region_from_vaddr(space, vaddr); - return region && region->is_user() && region->is_stack(); + bool is_valid_user_stack = region && region->is_user() && region->is_stack(); + + // The stack pointer initially points to the exclusive end of the stack region. + if (!is_valid_user_stack) { + region = find_user_region_from_vaddr(space, vaddr.offset(-1)); + is_valid_user_stack = region && region->range().end() == vaddr && region->is_user() && region->is_stack(); + } + + return is_valid_user_stack; } void MemoryManager::unregister_kernel_region(Region& region) diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index 779c3782fd8e35..7835178b50dc1e 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -28,7 +28,7 @@ ErrorOr Process::sys$create_thread(void* (*entry)(void*), Userspace ErrorOr { - if (!MM.validate_user_stack(*space, VirtualAddress(user_sp.value() - 4))) + if (!MM.validate_user_stack(*space, VirtualAddress(user_sp.value()))) return EFAULT; return {}; }));