[PATCH 2/2] function-graph: always initialize task ret_stack



From: Steven Rostedt <srostedt@xxxxxxxxxx>

On creating a new task while running the function graph tracer, if
we fail to allocate the ret_stack, and then fail the fork, the
code will free the parent ret_stack. This is because the child
duplicated the parent and currently points to the parent's ret_stack.

This patch always initializes the task's ret_stack to NULL.

[ Impact: prevent crash of parent on low memory during fork ]

Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
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 1664d3f..bb081f3 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2738,6 +2738,9 @@ void unregister_ftrace_graph(void)
/* Allocate a return stack for newly created task */
void ftrace_graph_init_task(struct task_struct *t)
{
+ /* Make sure we do not use the parent ret_stack */
+ t->ret_stack = NULL;
+
if (atomic_read(&ftrace_graph_active)) {
struct ftrace_ret_stack *ret_stack;

@@ -2753,8 +2756,7 @@ void ftrace_graph_init_task(struct task_struct *t)
/* make curr_ret_stack visable before we add the ret_stack */
smp_wmb();
t->ret_stack = ret_stack;
- } else
- t->ret_stack = NULL;
+ }
}

void ftrace_graph_exit_task(struct task_struct *t)
--
1.6.3.1

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: [fork]wait possible problem
    ... 1.in what case a fork can fail. ... EAGAIN fork cannot allocate sufficient memory to copy the ... for the child. ... and the errno global variable (in the parent) will be set to contain ...
    (comp.os.linux.development.apps)
  • trying to understand fork and wait
    ... I would really appreciate some feedback on a Perl program I'm trying ... My plan is to have a single Perl script running while the ... I still do not understand how to use fork and wait ... } #end parent while loop ...
    (comp.lang.perl.misc)
  • Re: Broken steel road bike fork
    ... that the fork was "rideable" for a while even though ... don't fail, so that brings us back to an initial assembly ... significant until full failure. ... aluminum part that was cracked halfway around probably ...
    (rec.bicycles.tech)
  • Re: Broken steel road bike fork
    ... that the fork was "rideable" for a while even though ... don't fail, so that brings us back to an initial assembly ... significant until full failure. ... aluminum part that was cracked halfway around probably ...
    (rec.bicycles.tech)
  • Re: timing a fork
    ... if ($kid) { ... That is why I want the child process to be detached. ... But, I'm new to modperl, and I think a fork doesn't copy the ... What it does is say that the parent isn't interested in ...
    (perl.beginners)