Skip to content

Commit

Permalink
mm: avoid null-pointer deref in sync_mm_rss()
Browse files Browse the repository at this point in the history
- We weren't zeroing p->rss_stat[] at fork()

- Consequently sync_mm_rss() was dereferencing tsk->mm for kernel
  threads and was oopsing.

- Make __sync_task_rss_stat() static, too.

Addresses https://bugzilla.kernel.org/show_bug.cgi?id=15648

[[email protected]: remove the BUG_ON(!mm->rss)]
Reported-by: Troels Liebe Bentsen <[email protected]>
Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
"Michael S. Tsirkin" <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Minchan Kim <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hkamezawa authored and torvalds committed Apr 7, 2010
1 parent b01d094 commit a3a2e76
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ NORET_TYPE void do_exit(long code)

acct_update_integrals(tsk);
/* sync mm's RSS info before statistics gathering */
sync_mm_rss(tsk, tsk->mm);
if (tsk->mm)
sync_mm_rss(tsk, tsk->mm);
group_dead = atomic_dec_and_test(&tsk->signal->live);
if (group_dead) {
hrtimer_cancel(&tsk->signal->real_timer);
Expand Down
3 changes: 3 additions & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
p->prev_utime = cputime_zero;
p->prev_stime = cputime_zero;
#endif
#if defined(SPLIT_RSS_COUNTING)
memset(&p->rss_stat, 0, sizeof(p->rss_stat));
#endif

p->default_timer_slack_ns = current->timer_slack_ns;

Expand Down
3 changes: 1 addition & 2 deletions mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,12 @@ core_initcall(init_zero_pfn);

#if defined(SPLIT_RSS_COUNTING)

void __sync_task_rss_stat(struct task_struct *task, struct mm_struct *mm)
static void __sync_task_rss_stat(struct task_struct *task, struct mm_struct *mm)
{
int i;

for (i = 0; i < NR_MM_COUNTERS; i++) {
if (task->rss_stat.count[i]) {
BUG_ON(!mm);
add_mm_counter(mm, i, task->rss_stat.count[i]);
task->rss_stat.count[i] = 0;
}
Expand Down

0 comments on commit a3a2e76

Please sign in to comment.