aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2015-11-24 14:39:54 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-24 15:03:55 -0500
commit81b1a832d79749058863cffe2c0ed4ef40f6e6ec (patch)
tree122c100882d738e0d08d377e9780a1d38ea70352
parent4ce01c518ebf6e3818abf5f4a9e1a1ef9d52f232 (diff)
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>
-rw-r--r--kernel/pid.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/pid.c b/kernel/pid.c
index ca368793808e..78b3d9f80d44 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -467,7 +467,7 @@ struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
467 rcu_read_lock(); 467 rcu_read_lock();
468 if (type != PIDTYPE_PID) 468 if (type != PIDTYPE_PID)
469 task = task->group_leader; 469 task = task->group_leader;
470 pid = get_pid(task->pids[type].pid); 470 pid = get_pid(rcu_dereference(task->pids[type].pid));
471 rcu_read_unlock(); 471 rcu_read_unlock();
472 return pid; 472 return pid;
473} 473}
@@ -528,7 +528,7 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
528 if (likely(pid_alive(task))) { 528 if (likely(pid_alive(task))) {
529 if (type != PIDTYPE_PID) 529 if (type != PIDTYPE_PID)
530 task = task->group_leader; 530 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);
532 } 532 }
533 rcu_read_unlock(); 533 rcu_read_unlock();
534 534