Skip to content

Commit

Permalink
[PATCH] fill_tgid: fix task_struct leak and possible oops
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Shailabh Nagar <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Jay Lan <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Oct 28, 2006
1 parent 6e6d9fa commit fca178c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,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;
Expand All @@ -264,7 +267,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;
}

Expand Down

0 comments on commit fca178c

Please sign in to comment.