Commit ae002786 authored by Hiroshi Shimamoto's avatar Hiroshi Shimamoto Committed by Ingo Molnar

latencytop: fix kernel panic while reading latency proc file

Reading /proc/<pid>/latency or /proc/<pid>/task/<tid>/latency could cause
NULL pointer dereference.

In lstats_open(), get_proc_task() can return NULL, in which case the kernel
will oops at lstats_show_proc() because m->private is NULL.

When get_proc_task() returns NULL, the kernel should return -ENOENT.

This can be reproduced by the following script.
while :
do
        date
        bash -c 'ls > ls.$$' &
        pid=$!
        cat /proc/$pid/latency &
        cat /proc/$pid/latency &
        cat /proc/$pid/latency &
        cat /proc/$pid/latency
done
Signed-off-by: default avatarHiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 2d07b255
...@@ -350,6 +350,8 @@ static int lstats_open(struct inode *inode, struct file *file) ...@@ -350,6 +350,8 @@ static int lstats_open(struct inode *inode, struct file *file)
struct seq_file *m; struct seq_file *m;
struct task_struct *task = get_proc_task(inode); struct task_struct *task = get_proc_task(inode);
if (!task)
return -ENOENT;
ret = single_open(file, lstats_show_proc, NULL); ret = single_open(file, lstats_show_proc, NULL);
if (!ret) { if (!ret) {
m = file->private_data; m = file->private_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment