From 9c3792718ce2e9f0b4ed8c752acc07c04a630a49 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 30 Oct 2022 19:24:56 +0100 Subject: [PATCH] Kernel: Remove waitpid() debug messages and add more checks --- kernel/src/thread/Scheduler.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 37d838a6..ac5f9168 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -510,10 +510,16 @@ void sys_waitpid(Context* context, long pid, int* wstatus, child = Scheduler::find_by_pid(pid); if (!child) { - context->rax = -ESRCH; + context->rax = -ECHILD; return; } } + if (child->ppid != sched_current_task->id) + { + // We are trying to call waitpid() on a task that isn't a child of ours. This is not allowed. + context->rax = -ECHILD; + return; + } if (child->state != child->Dying) { if (options & WNOHANG) @@ -531,7 +537,6 @@ void sys_waitpid(Context* context, long pid, int* wstatus, return; } } - kdbgln("blocking wait on pid %ld", pid); sched_current_task->state = sched_current_task->Blocking; sched_current_task->block_reason = BlockReason::Waiting; sched_current_task->blocking_wait_info.wait_pid = pid; @@ -583,6 +588,8 @@ bool Task::is_wait_still_blocking() else { child = Scheduler::find_by_pid(blocking_wait_info.wait_pid); + ASSERT(child); // since sys_waitpid should have validated this child, and the only way for it to disappear from + // the process list is for someone to wait for it, this should be pretty safe. if (child->state != child->Dying) return true; else return false; @@ -596,8 +603,6 @@ void Task::resume_wait() Task* child = Scheduler::find_by_pid(blocking_wait_info.wait_pid); ASSERT(child); // This should also already have been validated. - kdbgln("resuming wait on child %ld", child->id); - if (blocking_wait_info.wstatus) { *blocking_wait_info.wstatus = (int)(child->exit_status & 0xff);