Skip to contentSkip to conversation

kmemleak: clear stale pointers from task stacks

PATCH New [email protected] 1 participant 1 message Oct 13, 2017

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 16/18 kmemleak: clear stale pointers from task stacks

From: Konstantin Khlebnikov <[email protected]>
Subject: kmemleak: clear stale pointers from task stacks

Kmemleak considers any pointers on task stacks as references. This patch clears newly allocated and reused vmap stacks.

---

 include/linux/thread_info.h |    2 +-
 kernel/fork.c               |    4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/thread_info.h renamed from include/linux/thread_info.h~kmemleak-clear-stale-pointers-from-task-stacks +1 -1
diff -puN include/linux/thread_info.h~kmemleak-clear-stale-pointers-from-task-stacks include/linux/thread_info.h
@@ -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
kernel/fork.c renamed from kernel/fork.c~kmemleak-clear-stale-pointers-from-task-stacks +4 -0
diff -puN kernel/fork.c~kmemleak-clear-stale-pointers-from-task-stacks kernel/fork.c
@@ -215,6 +215,10 @@ static unsigned long *alloc_thread_stack
 		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;
 	}

_