From c1ceec3404a9578665ca12a009ff6aa7723c95fc Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Fri, 31 May 2024 13:44:25 +0300 Subject: [PATCH] sched/Kconfig: waitpid() depends on SCHED_HAVE_PARENT if BUILD_KERNEL waitpid() cannot be used in kernel mode unless SCHED_HAVE_PARENT is selected -> add dependency if BUILD_KERNEL is selected. Why? Because without SCHED_HAVE_PARENT waitpid() works in a non-standard way, meaning it does not use SIGCHLD to wake the parent, as it should. Also, returning the child status via stat_loc corrupts memory as stat_loc points to the parent's address environment: pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options) { ... group->tg_statloc = stat_loc; ... } And later when the status is returned, the child writes to tg_statloc, which points to the parent's address environment -> random memory corruption: static inline void nxtask_exitwakeup(FAR struct tcb_s *tcb, int status) { ... if (group->tg_statloc != NULL) { *group->tg_statloc = status << 8; } ... } --- sched/Kconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sched/Kconfig b/sched/Kconfig index 1877b944c4..232c009f8c 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -755,13 +755,15 @@ endif # SCHED_CHILD_STATUS config SCHED_WAITPID bool "Enable waitpid() API" default n + depends on SCHED_HAVE_PARENT || !BUILD_KERNEL ---help--- Enables the waitpid() interface in a default, non-standard mode (non-standard in the sense that the waited for PID need not be child of the caller). If SCHED_HAVE_PARENT is also defined, then this setting will modify the behavior or waitpid() (making more spec compliant) and will enable the waitid() and wait() interfaces as - well. + well. Note that SCHED_HAVE_PARENT must be defined in BUILD_KERNEL if + SCHED_WAITPID is needed. config SCHED_DUMP_LEAK bool "Enable catch task memory leak"