Re: [PATCH] pid: Add a judgment for ns null in pid_nr_ns

From: Oleg Nesterov
Date: Tue Aug 19 2025 - 10:28:07 EST


On 08/19, Christian Brauner wrote:
>
> On Sat, 02 Aug 2025 10:21:23 +0800, Xiang Gao wrote:
> > __task_pid_nr_ns
> > ns = task_active_pid_ns(current);
> > pid_nr_ns(rcu_dereference(*task_pid_ptr(task, type)), ns);
> > if (pid && ns->level <= pid->level) {
> >
> > Sometimes null is returned for task_active_pid_ns. Then it will trigger kernel panic in pid_nr_ns.
> >
> > [...]
>
> Applied to the vfs-6.18.pidfs branch of the vfs/vfs.git tree.
> Patches in the vfs-6.18.pidfs branch should appear in linux-next soon.
>
> Please report any outstanding bugs that were missed during review in a
> new review to the original patch series allowing us to drop it.
>
> It's encouraged to provide Acked-bys and Reviewed-bys even though the
> patch has now been applied. If possible patch trailers will be updated.
>
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs-6.18.pidfs
>
> [1/1] pid: Add a judgment for ns null in pid_nr_ns
> https://git.kernel.org/vfs/vfs/c/006568ab4c5c
> [1/4] pid: make __task_pid_nr_ns(ns => NULL) safe for zombie callers
> https://git.kernel.org/vfs/vfs/c/abdfd4948e45
> [3/4] pid: change bacct_add_tsk() to use task_ppid_nr_ns()
> https://git.kernel.org/vfs/vfs/c/b1afcaddd6c8
> [4/4] pid: change task_state() to use task_ppid_nr_ns()
> https://git.kernel.org/vfs/vfs/c/d00f5232851c

Hmm. The 1st patch adds the ns != NULL check into pid_nr_ns().

This means that "[1/4] pid: make __task_pid_nr_ns(ns => NULL) safe for zombie callers"
(commit abdfd4948e45c51b19 in vfs-6.18.pidfs) is not needed.

OTOH... You didn't take

[PATCH 2/4] pid: introduce task_ppid_vnr()
https://lore.kernel.org/all/20250810173610.GA19995@xxxxxxxxxx/

currently in -mm tree. It is purely cosmetic, but imo makes sense.

Oleg.