summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/waitid.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-09-15 15:42:45 +0300
committerAndreas Kling <kling@serenityos.org>2021-09-16 23:47:46 +0200
commitbb1ad759c552aa9b767c67a16705e7a08234567a (patch)
treedbeb854ac0420183f6dcc98b5b8cec5b67fd36a9 /Kernel/Syscalls/waitid.cpp
parent6b4777c5584295cc1ca7a4bb9a7c316fd9e987c4 (diff)
downloadserenity-bb1ad759c552aa9b767c67a16705e7a08234567a.zip
Kernel: Allow calling sys$waitid on traced, non-child processes
Previously, attempting to call sys$waitid on non-child processes returned ECHILD. That prevented debugging non-child processes by attaching to them during runtime (as opposed to forking and debugging the child, which is what was previously supported). We now allow calling sys$waitid on a any process that is being traced by us, even if it's not our child.
Diffstat (limited to 'Kernel/Syscalls/waitid.cpp')
-rw-r--r--Kernel/Syscalls/waitid.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Kernel/Syscalls/waitid.cpp b/Kernel/Syscalls/waitid.cpp
index de0948745e..f94025d917 100644
--- a/Kernel/Syscalls/waitid.cpp
+++ b/Kernel/Syscalls/waitid.cpp
@@ -32,9 +32,12 @@ KResultOr<FlatPtr> Process::sys$waitid(Userspace<const Syscall::SC_waitid_params
break;
case P_PID: {
auto waitee_process = Process::from_pid(params.id);
- if (!waitee_process || waitee_process->ppid() != Process::current().pid()) {
+ if (!waitee_process)
+ return ECHILD;
+ bool waitee_is_child = waitee_process->ppid() == Process::current().pid();
+ bool waitee_is_our_tracee = waitee_process->has_tracee_thread(Process::current().pid());
+ if (!waitee_is_child && !waitee_is_our_tracee)
return ECHILD;
- }
waitee = waitee_process.release_nonnull();
break;
}