Unverified Commit da664c6d authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge patch series "Improve pid_nr_ns()"

In various places pid_nr_ns() can be called with a NULL pointer.
Fix those up and improve pid_nr_ns() callers.

Link: https://lore.kernel.org/20250802022123.3536934-1-gxxa03070307@gmail.com


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents 8f5ae30d d00f5232
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -157,13 +157,11 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
	unsigned int max_fds = 0;

	rcu_read_lock();
	ppid = pid_alive(p) ?
		task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;

	tracer = ptrace_parent(p);
	if (tracer)
		tpid = task_pid_nr_ns(tracer, ns);

	ppid = task_ppid_nr_ns(p, ns);
	tgid = task_tgid_nr_ns(p, ns);
	ngid = task_numa_group_id(p);
	cred = get_task_cred(p);
+3 −2
Original line number Diff line number Diff line
@@ -491,7 +491,7 @@ pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
	struct upid *upid;
	pid_t nr = 0;

	if (pid && ns->level <= pid->level) {
	if (pid && ns && ns->level <= pid->level) {
		upid = &pid->numbers[ns->level];
		if (upid->ns == ns)
			nr = upid->nr;
@@ -514,6 +514,7 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
	rcu_read_lock();
	if (!ns)
		ns = task_active_pid_ns(current);
	if (ns)
		nr = pid_nr_ns(rcu_dereference(*task_pid_ptr(task, type)), ns);
	rcu_read_unlock();

+1 −2
Original line number Diff line number Diff line
@@ -57,12 +57,11 @@ void bacct_add_tsk(struct user_namespace *user_ns,
	stats->ac_sched	 = tsk->policy;
	stats->ac_pid	 = task_pid_nr_ns(tsk, pid_ns);
	stats->ac_tgid   = task_tgid_nr_ns(tsk, pid_ns);
	stats->ac_ppid	 = task_ppid_nr_ns(tsk, pid_ns);
	rcu_read_lock();
	tcred = __task_cred(tsk);
	stats->ac_uid	 = from_kuid_munged(user_ns, tcred->uid);
	stats->ac_gid	 = from_kgid_munged(user_ns, tcred->gid);
	stats->ac_ppid	 = pid_alive(tsk) ?
		task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;
	rcu_read_unlock();

	task_cputime(tsk, &utime, &stime);