kmemleak: clear stale pointers from task stacks
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Fri, 13 Oct 2017 22:58:22 +0000 (15:58 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 13 Oct 2017 23:18:33 +0000 (16:18 -0700)
Kmemleak considers any pointers on task stacks as references.  This
patch clears newly allocated and reused vmap stacks.

Link: http://lkml.kernel.org/r/150728990124.744199.8403409836394318684.stgit@buzz
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/thread_info.h
kernel/fork.c

index 905d769d8ddcfdbf9657371dda29744bcedb53f5..5f7eeab990fe7eb2fa9a3ce16821f574eeee8f94 100644 (file)
@@ -42,7 +42,7 @@ enum {
 #define THREAD_ALIGN   THREAD_SIZE
 #endif
 
-#ifdef CONFIG_DEBUG_STACK_USAGE
+#if IS_ENABLED(CONFIG_DEBUG_STACK_USAGE) || IS_ENABLED(CONFIG_DEBUG_KMEMLEAK)
 # define THREADINFO_GFP                (GFP_KERNEL_ACCOUNT | __GFP_NOTRACK | \
                                 __GFP_ZERO)
 #else
index e702cb9ffbd85ab7ff388c17654f729614d0b296..07cc743698d3668ef7fb4442c6de0e12de7f02f5 100644 (file)
@@ -215,6 +215,10 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
                if (!s)
                        continue;
 
+#ifdef CONFIG_DEBUG_KMEMLEAK
+               /* Clear stale pointers from reused stack. */
+               memset(s->addr, 0, THREAD_SIZE);
+#endif
                tsk->stack_vm_area = s;
                return s->addr;
        }