Skip to content

Commit e571372

Browse files
committed
Merge tag 'vfs-6.18-rc1.pidfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull pidfs updates from Christian Brauner: "This just contains a few changes to pid_nr_ns() to make it more robust and cleans up or improves a few users that ab- or misuse it currently" * tag 'vfs-6.18-rc1.pidfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: pid: change task_state() to use task_ppid_nr_ns() pid: change bacct_add_tsk() to use task_ppid_nr_ns() pid: make __task_pid_nr_ns(ns => NULL) safe for zombie callers pid: Add a judgment for ns null in pid_nr_ns
2 parents 029a4eb + da664c6 commit e571372

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

fs/proc/array.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,11 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
157157
unsigned int max_fds = 0;
158158

159159
rcu_read_lock();
160-
ppid = pid_alive(p) ?
161-
task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
162-
163160
tracer = ptrace_parent(p);
164161
if (tracer)
165162
tpid = task_pid_nr_ns(tracer, ns);
166163

164+
ppid = task_ppid_nr_ns(p, ns);
167165
tgid = task_tgid_nr_ns(p, ns);
168166
ngid = task_numa_group_id(p);
169167
cred = get_task_cred(p);

kernel/pid.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
491491
struct upid *upid;
492492
pid_t nr = 0;
493493

494-
if (pid && ns->level <= pid->level) {
494+
if (pid && ns && ns->level <= pid->level) {
495495
upid = &pid->numbers[ns->level];
496496
if (upid->ns == ns)
497497
nr = upid->nr;
@@ -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;

kernel/tsacct.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ void bacct_add_tsk(struct user_namespace *user_ns,
5757
stats->ac_sched = tsk->policy;
5858
stats->ac_pid = task_pid_nr_ns(tsk, pid_ns);
5959
stats->ac_tgid = task_tgid_nr_ns(tsk, pid_ns);
60+
stats->ac_ppid = task_ppid_nr_ns(tsk, pid_ns);
6061
rcu_read_lock();
6162
tcred = __task_cred(tsk);
6263
stats->ac_uid = from_kuid_munged(user_ns, tcred->uid);
6364
stats->ac_gid = from_kgid_munged(user_ns, tcred->gid);
64-
stats->ac_ppid = pid_alive(tsk) ?
65-
task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;
6665
rcu_read_unlock();
6766

6867
task_cputime(tsk, &utime, &stime);

0 commit comments

Comments
 (0)