public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	stable@kernel.org,
	"Luis Claudio R. Goncalves" <lclaudio@uudg.org>,
	Oleg Nesterov <oleg@tv-sign.ru>
Subject: [PATCH 1/3] function-graph: only allocate init tasks if it was not already done
Date: Tue, 02 Jun 2009 14:30:37 -0400	[thread overview]
Message-ID: <20090602184600.925026719@goodmis.org> (raw)
In-Reply-To: 20090602183036.621443366@goodmis.org

[-- Attachment #1: 0001-function-graph-only-allocate-init-tasks-if-it-was-no.patch --]
[-- Type: text/plain, Size: 1351 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

When the function graph tracer is enabled, it calls the initialization
needed for the init tasks that would be called on all created tasks.

The problem is that this is called every time the function graph tracer
is enabled, and the ret_stack is allocated for the idle tasks each time.
Thus, the old ret_stack is lost and a memory leak is created.

This is also dangerous because if an interrupt happened on another CPU
with the init task and the ret_stack is replaced, we then lose all the
return pointers for the interrupt, and a crash would take place.

[ Impact: fix memory leak and possible crash due to race ]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index f1ed080..ebff62e 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2643,8 +2643,10 @@ static int start_graph_tracing(void)
 		return -ENOMEM;
 
 	/* The cpu_boot init_task->ret_stack will never be freed */
-	for_each_online_cpu(cpu)
-		ftrace_graph_init_task(idle_task(cpu));
+	for_each_online_cpu(cpu) {
+		if (!idle_task(cpu)->ret_stack)
+			ftrace_graph_init_task(idle_task(cpu));
+	}
 
 	do {
 		ret = alloc_retstack_tasklist(ret_stack_list);
-- 
1.6.3.1

-- 

  reply	other threads:[~2009-06-02 18:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 18:30 [PATCH 0/3] [GIT PULL][urgent] function-graph: memory leak and race fixes Steven Rostedt
2009-06-02 18:30 ` Steven Rostedt [this message]
2009-06-02 18:30 ` [PATCH 2/3] function-graph: enable the stack after initialization of other variables Steven Rostedt
2009-06-02 19:02   ` Frederic Weisbecker
2009-06-02 19:30     ` Steven Rostedt
2009-06-03 15:35       ` Paul E. McKenney
2009-06-02 18:30 ` [PATCH 3/3] function-graph: add memory barriers for accessing tasks ret_stack Steven Rostedt

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=20090602184600.925026719@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=lclaudio@uudg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    --cc=stable@kernel.org \
    /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