kmemleak: clear stale pointers from task stacks
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Fri, 13 Oct 2017 22:58:22 +0000 (15:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Aug 2018 10:18:00 +0000 (12:18 +0200)
commit ca182551857cc2c1e6a2b7f1e72090a137a15008 upstream.

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>
[ Srivatsa: Backported to 4.9.y ]
Signed-off-by: Srivatsa S. Bhat <srivatsa@csail.mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/thread_info.h
kernel/fork.c

index 2873baf5372a7b1484888566725e2c4dc7368d26..cf87c162f4eb75b623a836e34813cbf23286934e 100644 (file)
@@ -59,7 +59,7 @@ extern long do_no_restart_syscall(struct restart_block *parm);
 
 #ifdef __KERNEL__
 
-#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 70e10cb49be0ff861bd379ac6cfec3561764e156..c19e6d48d57dbeeec020ead938aa437b147557f0 100644 (file)
@@ -184,6 +184,10 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
                        continue;
                this_cpu_write(cached_stacks[i], NULL);
 
+#ifdef CONFIG_DEBUG_KMEMLEAK
+               /* Clear stale pointers from reused stack. */
+               memset(s->addr, 0, THREAD_SIZE);
+#endif
                tsk->stack_vm_area = s;
                local_irq_enable();
                return s->addr;