Skip to content

Commit abdfd49

Browse files
oleg-nesterovbrauner
authored andcommitted
pid: make __task_pid_nr_ns(ns => NULL) safe for zombie callers
task_pid_vnr(another_task) will crash if the caller was already reaped. The pid_alive(current) check can't really help, the parent/debugger can call release_task() right after this check. This also means that even task_ppid_nr_ns(current, NULL) is not safe, pid_alive() only ensures that it is safe to dereference ->real_parent. Change __task_pid_nr_ns() to ensure ns != NULL. Originally-by: 高翔 <gaoxiang17@xiaomi.com> Link: https://lore.kernel.org/all/20250802022123.3536934-1-gxxa03070307@gmail.com/ Signed-off-by: Oleg Nesterov <oleg@redhat.com> Link: https://lore.kernel.org/20250810173604.GA19991@redhat.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 006568a commit abdfd49

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

kernel/pid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
514514
rcu_read_lock();
515515
if (!ns)
516516
ns = task_active_pid_ns(current);
517-
nr = pid_nr_ns(rcu_dereference(*task_pid_ptr(task, type)), ns);
517+
if (ns)
518+
nr = pid_nr_ns(rcu_dereference(*task_pid_ptr(task, type)), ns);
518519
rcu_read_unlock();
519520

520521
return nr;

0 commit comments

Comments
 (0)