Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Luis Henriques <lhenriques@suse.com>
To: Andy Lutomirski <luto@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Eric W . Biederman" <ebiederm@xmission.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Mateusz Guzik <mguzik@redhat.com>,
	linux-kernel@vger.kernel.org,
	Luis Henriques <lhenriques@suse.com>,
	stable@vger.kernel.org
Subject: [PATCH] fork: fix kmemleak false positive due to thread stacks caching
Date: Fri, 26 May 2017 14:49:49 +0100	[thread overview]
Message-ID: <20170526134949.3045-1-lhenriques@suse.com> (raw)

kmemleak has been reporting memory leaks since commit ac496bf48d97 ("fork:
Optimize task creation by caching two thread stacks per CPU if
CONFIG_VMAP_STACK=y"):

unreferenced object 0xffffc900002b0000 (size 16384):
  comm "init", pid 147, jiffies 4294893306 (age 11.292s)
  hex dump (first 32 bytes):
    9d 6e ac 57 00 00 00 00 00 00 00 00 00 00 00 00  .n.W............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<ffffffff815b481e>] kmemleak_alloc+0x4e/0xb0
    [<ffffffff8112a8b0>] __vmalloc_node_range+0x160/0x240
    [<ffffffff8104a328>] copy_process.part.8+0x478/0x1630
    [<ffffffff8104b69a>] _do_fork+0xca/0x330
    [<ffffffff8104b9a9>] SyS_clone+0x19/0x20
    [<ffffffff8100199c>] do_syscall_64+0x4c/0xb0
    [<ffffffff815b8d06>] return_from_SYSCALL_64+0x0/0x6a
    [<ffffffffffffffff>] 0xffffffffffffffff

This is because this commit started caching 2 thread stacks per CPU, and
kmemleak assumes its memory is never freed.  Report these stacks as not
being memory leaks using kmemleak_not_leak().

Cc: stable@vger.kernel.org
Fixes: ac496bf48d97 ("fork: Optimize task creation by caching two thread stacks per CPU if CONFIG_VMAP_STACK=y")
Signed-off-by: Luis Henriques <lhenriques@suse.com>
---
 kernel/fork.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/fork.c b/kernel/fork.c
index aa1076c5e4a9..c4d79ad0f5bc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -255,6 +255,7 @@ static inline void free_thread_stack(struct task_struct *tsk)
 
 			this_cpu_write(cached_stacks[i], tsk->stack_vm_area);
 			local_irq_restore(flags);
+			kmemleak_not_leak(tsk->stack);
 			return;
 		}
 		local_irq_restore(flags);

             reply	other threads:[~2017-05-26 13:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 13:49 Luis Henriques [this message]
2017-05-26 14:22 ` [PATCH] fork: fix kmemleak false positive due to thread stacks caching Catalin Marinas
2017-05-26 15:06   ` Luis Henriques

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170526134949.3045-1-lhenriques@suse.com \
    --to=lhenriques@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mguzik@redhat.com \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox