This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3b793c0a5c273d1cf07cc79e8c180c026215fd9c Author: yushuailong <[email protected]> AuthorDate: Tue Oct 13 20:48:23 2026 +0800 fix(sched/task): reject invalid grandparent reparenting Reject task_reparent(0, child) when the current parent has no valid parent process. PID zero resolves to the idle task group, which would otherwise move the child into the kernel-thread group and discard its child status. Apply the validation to both task-group configurations. Assisted-by: OpenAI:Codex Signed-off-by: yushuailong <[email protected]> --- sched/task/task_reparent.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index 5cfe4a99d26..6c678db56d9 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -113,6 +113,12 @@ int task_reparent(pid_t ppid, pid_t chpid) /* Get the grandparent task's task group (pgrp) */ ppid = ogrp->tg_ppid; + if (ppid <= 0) + { + ret = -ESRCH; + goto errout_with_ints; + } + pgrp = task_getgroup(ppid); } else @@ -241,6 +247,11 @@ int task_reparent(pid_t ppid, pid_t chpid) if (ppid == 0) { ppid = otcb->group->tg_ppid; + if (ppid <= 0) + { + ret = -ESRCH; + goto errout_with_ints; + } } /* Get the new parent task's TCB (ptcb) */
