Skip to content

Commit 81b1a83

Browse files
edumazettorvalds
authored andcommitted
pidns: fix NULL dereference in __task_pid_nr_ns()
I got a crash during a "perf top" session that was caused by a race in __task_pid_nr_ns() : pid_nr_ns() was inlined, but apparently compiler chose to read task->pids[type].pid twice, and the pid->level dereference crashed because we got a NULL pointer at the second read : if (pid && ns->level <= pid->level) { // CRASH Just use RCU API properly to solve this race, and not worry about "perf top" crashing hosts :( get_task_pid() can benefit from same fix. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4ce01c5 commit 81b1a83

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/pid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
467467
rcu_read_lock();
468468
if (type != PIDTYPE_PID)
469469
task = task->group_leader;
470-
pid = get_pid(task->pids[type].pid);
470+
pid = get_pid(rcu_dereference(task->pids[type].pid));
471471
rcu_read_unlock();
472472
return pid;
473473
}
@@ -528,7 +528,7 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
528528
if (likely(pid_alive(task))) {
529529
if (type != PIDTYPE_PID)
530530
task = task->group_leader;
531-
nr = pid_nr_ns(task->pids[type].pid, ns);
531+
nr = pid_nr_ns(rcu_dereference(task->pids[type].pid), ns);
532532
}
533533
rcu_read_unlock();
534534

0 commit comments

Comments
 (0)