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;
    }
  ...
}
This commit is contained in:
Ville Juven 2024-05-31 13:44:25 +03:00 committed by Petro Karashchenko
parent 36cafbb37f
commit c1ceec3404
1 changed files with 3 additions and 1 deletions

View File

@ -755,13 +755,15 @@ endif # SCHED_CHILD_STATUS
config SCHED_WAITPID config SCHED_WAITPID
bool "Enable waitpid() API" bool "Enable waitpid() API"
default n default n
depends on SCHED_HAVE_PARENT || !BUILD_KERNEL
---help--- ---help---
Enables the waitpid() interface in a default, non-standard mode Enables the waitpid() interface in a default, non-standard mode
(non-standard in the sense that the waited for PID need not be child (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 of the caller). If SCHED_HAVE_PARENT is also defined, then this
setting will modify the behavior or waitpid() (making more spec setting will modify the behavior or waitpid() (making more spec
compliant) and will enable the waitid() and wait() interfaces as 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 config SCHED_DUMP_LEAK
bool "Enable catch task memory leak" bool "Enable catch task memory leak"