latencytop: fix kernel panic while reading latency proc file
authorHiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Thu, 14 Feb 2008 18:26:24 +0000 (10:26 -0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 25 Feb 2008 15:34:17 +0000 (16:34 +0100)
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: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
fs/proc/base.c

index 96ee899d65020e76e5c0c8d49b0683c74214ebed..989e3078d7af5344fcbd2e65dd09b2d46e4fee63 100644 (file)
@@ -350,6 +350,8 @@ static int lstats_open(struct inode *inode, struct file *file)
        struct seq_file *m;
        struct task_struct *task = get_proc_task(inode);
 
+       if (!task)
+               return -ENOENT;
        ret = single_open(file, lstats_show_proc, NULL);
        if (!ret) {
                m = file->private_data;