diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2006-10-28 13:38:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-10-28 14:30:54 -0400 |
commit | fca178c0c6e8d52a1875be36b070f30884ebfae9 (patch) | |
tree | 4bce17647edd3fae6b0ba96407cd1c02037b11d1 /kernel/taskstats.c | |
parent | 6e6d9fa6f95e382bb2d5725dda18b9e811418e79 (diff) |
[PATCH] fill_tgid: fix task_struct leak and possible oops
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>
Diffstat (limited to 'kernel/taskstats.c')
-rw-r--r-- | kernel/taskstats.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 5d6a8c54ee85..9aeee511a463 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
@@ -237,14 +237,17 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, | |||
237 | } else | 237 | } else |
238 | get_task_struct(first); | 238 | get_task_struct(first); |
239 | 239 | ||
240 | /* Start with stats from dead tasks */ | ||
241 | spin_lock_irqsave(&first->signal->stats_lock, flags); | ||
242 | if (first->signal->stats) | ||
243 | memcpy(stats, first->signal->stats, sizeof(*stats)); | ||
244 | spin_unlock_irqrestore(&first->signal->stats_lock, flags); | ||
245 | 240 | ||
246 | tsk = first; | 241 | tsk = first; |
247 | read_lock(&tasklist_lock); | 242 | read_lock(&tasklist_lock); |
243 | /* Start with stats from dead tasks */ | ||
244 | if (first->signal) { | ||
245 | spin_lock_irqsave(&first->signal->stats_lock, flags); | ||
246 | if (first->signal->stats) | ||
247 | memcpy(stats, first->signal->stats, sizeof(*stats)); | ||
248 | spin_unlock_irqrestore(&first->signal->stats_lock, flags); | ||
249 | } | ||
250 | |||
248 | do { | 251 | do { |
249 | if (tsk->exit_state == EXIT_ZOMBIE && thread_group_leader(tsk)) | 252 | if (tsk->exit_state == EXIT_ZOMBIE && thread_group_leader(tsk)) |
250 | continue; | 253 | continue; |
@@ -264,7 +267,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, | |||
264 | * Accounting subsytems can also add calls here to modify | 267 | * Accounting subsytems can also add calls here to modify |
265 | * fields of taskstats. | 268 | * fields of taskstats. |
266 | */ | 269 | */ |
267 | 270 | put_task_struct(first); | |
268 | return 0; | 271 | return 0; |
269 | } | 272 | } |
270 | 273 | ||