]> git.hungrycats.org Git - linux/commitdiff
[PATCH] fill_tgid: fix task_struct leak and possible oops
authorOleg Nesterov <oleg@tv-sign.ru>
Sat, 28 Oct 2006 17:38:49 +0000 (10:38 -0700)
committerChris Wright <chrisw@sous-sol.org>
Sat, 4 Nov 2006 01:33:50 +0000 (17:33 -0800)
1. fill_tgid() forgets to do put_task_struct(first).

2. release_task(first) can happen after fill_tgid() drops tasklist_lock,
   it is unsafe to dereference first->signal.

This is a temporary fix, imho the locking should be reworked.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Jay Lan <jlan@sgi.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
kernel/taskstats.c

index e781876573304e5350ec8c209760d4ebdc4fd266..b90b2a7ef600988dc047b81f7d725a0a88f2e75c 100644 (file)
@@ -229,14 +229,17 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk,
        } else
                get_task_struct(first);
 
-       /* Start with stats from dead tasks */
-       spin_lock_irqsave(&first->signal->stats_lock, flags);
-       if (first->signal->stats)
-               memcpy(stats, first->signal->stats, sizeof(*stats));
-       spin_unlock_irqrestore(&first->signal->stats_lock, flags);
 
        tsk = first;
        read_lock(&tasklist_lock);
+       /* Start with stats from dead tasks */
+       if (first->signal) {
+               spin_lock_irqsave(&first->signal->stats_lock, flags);
+               if (first->signal->stats)
+                       memcpy(stats, first->signal->stats, sizeof(*stats));
+               spin_unlock_irqrestore(&first->signal->stats_lock, flags);
+       }
+
        do {
                if (tsk->exit_state == EXIT_ZOMBIE && thread_group_leader(tsk))
                        continue;
@@ -256,7 +259,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk,
         * Accounting subsytems can also add calls here to modify
         * fields of taskstats.
         */
-
+       put_task_struct(first);
        return 0;
 }