diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index edefb7702e..3c00acc880 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -46,12 +46,12 @@ KResultOr Process::sys$create_thread(void* (*entry)(void*), Userspace::addition_would_overflow((FlatPtr)params.m_stack_location, stack_size)) + auto user_esp = Checked((FlatPtr)params.m_stack_location); + user_esp += stack_size; + if (user_esp.has_overflow()) return EOVERFLOW; - auto user_stack_address = (u8*)params.m_stack_location + stack_size; - - if (!MM.validate_user_stack(*this, VirtualAddress(user_stack_address - 4))) + if (!MM.validate_user_stack(*this, VirtualAddress(user_esp.value() - 4))) return EFAULT; // FIXME: return EAGAIN if Thread::all_threads().size() is greater than PTHREAD_THREADS_MAX @@ -83,7 +83,7 @@ KResultOr Process::sys$create_thread(void* (*entry)(void*), Userspacemake_thread_specific_region({}); if (tsr_result.is_error())