This is a note to let you know that I've just added the patch titled tracing: Protect ftrace_trace_arrays list in trace_events.c to the 3.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: tracing-protect-ftrace_trace_arrays-list-in-trace_events.c.patch and it can be found in the queue-3.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From a82274151af2b075163e3c42c828529dee311487 Mon Sep 17 00:00:00 2001 From: Alexander Z Lam <azl@xxxxxxxxxx> Date: Mon, 1 Jul 2013 19:37:54 -0700 Subject: tracing: Protect ftrace_trace_arrays list in trace_events.c From: Alexander Z Lam <azl@xxxxxxxxxx> commit a82274151af2b075163e3c42c828529dee311487 upstream. There are multiple places where the ftrace_trace_arrays list is accessed in trace_events.c without the trace_types_lock held. Link: http://lkml.kernel.org/r/1372732674-22726-1-git-send-email-azl@xxxxxxxxxx Signed-off-by: Alexander Z Lam <azl@xxxxxxxxxx> Cc: Vaibhav Nagarnaik <vnagarnaik@xxxxxxxxxx> Cc: David Sharp <dhsharp@xxxxxxxxxx> Cc: Alexander Z Lam <lambchop468@xxxxxxxxx> Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -240,7 +240,7 @@ static struct tracer *trace_types __rea /* * trace_types_lock is used to protect the trace_types list. */ -static DEFINE_MUTEX(trace_types_lock); +DEFINE_MUTEX(trace_types_lock); /* * serialize the access of the ring buffer --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -224,6 +224,8 @@ enum { extern struct list_head ftrace_trace_arrays; +extern struct mutex trace_types_lock; + /* * The global tracer (top) should be the first trace array added, * but we check the flag anyway. --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -1011,6 +1011,7 @@ static int subsystem_open(struct inode * int ret; /* Make sure the system still exists */ + mutex_lock(&trace_types_lock); mutex_lock(&event_mutex); list_for_each_entry(tr, &ftrace_trace_arrays, list) { list_for_each_entry(dir, &tr->systems, list) { @@ -1026,6 +1027,7 @@ static int subsystem_open(struct inode * } exit_loop: mutex_unlock(&event_mutex); + mutex_unlock(&trace_types_lock); if (!system) return -ENODEV; @@ -1620,6 +1622,7 @@ static void __add_event_to_tracers(struc int trace_add_event_call(struct ftrace_event_call *call) { int ret; + mutex_lock(&trace_types_lock); mutex_lock(&event_mutex); ret = __register_event(call, NULL); @@ -1627,11 +1630,13 @@ int trace_add_event_call(struct ftrace_e __add_event_to_tracers(call, NULL); mutex_unlock(&event_mutex); + mutex_unlock(&trace_types_lock); return ret; } /* - * Must be called under locking both of event_mutex and trace_event_sem. + * Must be called under locking of trace_types_lock, event_mutex and + * trace_event_sem. */ static void __trace_remove_event_call(struct ftrace_event_call *call) { @@ -1643,11 +1648,13 @@ static void __trace_remove_event_call(st /* Remove an event_call */ void trace_remove_event_call(struct ftrace_event_call *call) { + mutex_lock(&trace_types_lock); mutex_lock(&event_mutex); down_write(&trace_event_sem); __trace_remove_event_call(call); up_write(&trace_event_sem); mutex_unlock(&event_mutex); + mutex_unlock(&trace_types_lock); } #define for_each_event(event, start, end) \ @@ -1791,6 +1798,7 @@ static int trace_module_notify(struct no { struct module *mod = data; + mutex_lock(&trace_types_lock); mutex_lock(&event_mutex); switch (val) { case MODULE_STATE_COMING: @@ -1801,6 +1809,7 @@ static int trace_module_notify(struct no break; } mutex_unlock(&event_mutex); + mutex_unlock(&trace_types_lock); return 0; } Patches currently in stable-queue which might be from azl@xxxxxxxxxx are queue-3.10/tracing-get-trace_array-ref-counts-when-accessing-trace-files.patch queue-3.10/tracing-add-trace_array_get-put-to-event-handling.patch queue-3.10/tracing-protect-ftrace_trace_arrays-list-in-trace_events.c.patch queue-3.10/tracing-make-trace_marker-use-the-correct-per-instance-buffer.patch queue-3.10/tracing-add-trace_array_get-put-to-handle-instance-refs-better.patch -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html