Skip to content

Commit

Permalink
mm: kmemleak: ensure that the task stack is not freed during scanning
Browse files Browse the repository at this point in the history
Commit 68f24b0 ("sched/core: Free the stack early if
CONFIG_THREAD_INFO_IN_TASK") may cause the task->stack to be freed
during kmemleak_scan() execution, leading to either a NULL pointer fault
(if task->stack is NULL) or kmemleak accessing already freed memory.

This patch uses the new try_get_task_stack() API to ensure that the task
stack is not freed during kmemleak stack scanning.

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

Fixes: 68f24b0 ("sched/core: Free the stack early if CONFIG_THREAD_INFO_IN_TASK")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Catalin Marinas <[email protected]>
Reported-by: CAI Qian <[email protected]>
Tested-by: CAI Qian <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: CAI Qian <[email protected]>
Cc: Hillf Danton <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ctmarinas authored and torvalds committed Oct 28, 2016
1 parent 02754e0 commit 37df49f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,11 @@ static void kmemleak_scan(void)

read_lock(&tasklist_lock);
do_each_thread(g, p) {
scan_block(task_stack_page(p), task_stack_page(p) +
THREAD_SIZE, NULL);
void *stack = try_get_task_stack(p);
if (stack) {
scan_block(stack, stack + THREAD_SIZE, NULL);
put_task_stack(p);
}
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
}
Expand Down

0 comments on commit 37df49f

Please sign in to comment.