LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH] kmemleak: clear stale pointers from task stacks
@ 2017-10-06 11:38 Konstantin Khlebnikov
  2017-10-06 14:02 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Khlebnikov @ 2017-10-06 11:38 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, linux-kernel, Catalin Marinas; +Cc: Andy Lutomirski

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

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
 include/linux/thread_info.h |    2 +-
 kernel/fork.c               |    4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 905d769d8ddc..5f7eeab990fe 100644
--- a/include/linux/thread_info.h
+++ b/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
diff --git a/kernel/fork.c b/kernel/fork.c
index c4ff0303b7c5..53e3b6f8a3bf 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -213,6 +213,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;
 	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] kmemleak: clear stale pointers from task stacks
  2017-10-06 11:38 [PATCH] kmemleak: clear stale pointers from task stacks Konstantin Khlebnikov
@ 2017-10-06 14:02 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2017-10-06 14:02 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: linux-mm, Andrew Morton, linux-kernel, Andy Lutomirski

On Fri, Oct 06, 2017 at 02:38:21PM +0300, Konstantin Khlebnikov wrote:
> Kmemleak considers any pointers as task stacks as references.
                                  ^^
				  on

> This patch clears newly allocated and reused vmap stacks.
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> ---
>  include/linux/thread_info.h |    2 +-
>  kernel/fork.c               |    4 ++++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
> index 905d769d8ddc..5f7eeab990fe 100644
> --- a/include/linux/thread_info.h
> +++ b/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
> diff --git a/kernel/fork.c b/kernel/fork.c
> index c4ff0303b7c5..53e3b6f8a3bf 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -213,6 +213,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;
>  	}

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 11:38 [PATCH] kmemleak: clear stale pointers from task stacks Konstantin Khlebnikov
2017-10-06 14:02 ` Catalin Marinas

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox