This is a note to let you know that I've just added the patch titled tracing: trace_remove_event_call() should fail if call/file is in use 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-trace_remove_event_call-should-fail-if-call-file-is-in-use.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 2816c551c796ec14620325b2c9ed75b9979d3125 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov <oleg@xxxxxxxxxx> Date: Mon, 29 Jul 2013 19:50:33 +0200 Subject: tracing: trace_remove_event_call() should fail if call/file is in use From: Oleg Nesterov <oleg@xxxxxxxxxx> commit 2816c551c796ec14620325b2c9ed75b9979d3125 upstream. Change trace_remove_event_call(call) to return the error if this call is active. This is what the callers assume but can't verify outside of the tracing locks. Both trace_kprobe.c/trace_uprobe.c need the additional changes, unregister_trace_probe() should abort if trace_remove_event_call() fails. The caller is going to free this call/file so we must ensure that nobody can use them after trace_remove_event_call() succeeds. debugfs should be fine after the previous changes and event_remove() does TRACE_REG_UNREGISTER, but still there are 2 reasons why we need the additional checks: - There could be a perf_event(s) attached to this tp_event, so the patch checks ->perf_refcount. - TRACE_REG_UNREGISTER can be suppressed by FTRACE_EVENT_FL_SOFT_MODE, so we simply check FTRACE_EVENT_FL_ENABLED protected by event_mutex. Link: http://lkml.kernel.org/r/20130729175033.GB26284@xxxxxxxxxx Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx> Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- include/linux/ftrace_event.h | 2 +- kernel/trace/trace_events.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h @@ -334,7 +334,7 @@ extern int trace_define_field(struct ftr const char *name, int offset, int size, int is_signed, int filter_type); extern int trace_add_event_call(struct ftrace_event_call *call); -extern void trace_remove_event_call(struct ftrace_event_call *call); +extern int trace_remove_event_call(struct ftrace_event_call *call); #define is_signed_type(type) (((type)(-1)) < (type)1) --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -1735,16 +1735,47 @@ static void __trace_remove_event_call(st destroy_preds(call); } +static int probe_remove_event_call(struct ftrace_event_call *call) +{ + struct trace_array *tr; + struct ftrace_event_file *file; + +#ifdef CONFIG_PERF_EVENTS + if (call->perf_refcount) + return -EBUSY; +#endif + do_for_each_event_file(tr, file) { + if (file->event_call != call) + continue; + /* + * We can't rely on ftrace_event_enable_disable(enable => 0) + * we are going to do, FTRACE_EVENT_FL_SOFT_MODE can suppress + * TRACE_REG_UNREGISTER. + */ + if (file->flags & FTRACE_EVENT_FL_ENABLED) + return -EBUSY; + break; + } while_for_each_event_file(); + + __trace_remove_event_call(call); + + return 0; +} + /* Remove an event_call */ -void trace_remove_event_call(struct ftrace_event_call *call) +int trace_remove_event_call(struct ftrace_event_call *call) { + int ret; + mutex_lock(&trace_types_lock); mutex_lock(&event_mutex); down_write(&trace_event_sem); - __trace_remove_event_call(call); + ret = probe_remove_event_call(call); up_write(&trace_event_sem); mutex_unlock(&event_mutex); mutex_unlock(&trace_types_lock); + + return ret; } #define for_each_event(event, start, end) \ Patches currently in stable-queue which might be from oleg@xxxxxxxxxx are queue-3.10/tracing-introduce-trace_create_cpu_file-and.patch queue-3.10/tracing-introduce-remove_event_file_dir.patch queue-3.10/tracing-change-event_filter_read-write-to-verify-i_private-null.patch queue-3.10/tracing-change-remove_event_file_dir-to-clear-d_subdirs-i_private.patch queue-3.10/tracing-uprobes-fail-to-unregister-if-probe-event-files-are-in-use.patch queue-3.10/tracing-change-tracing_fops-snapshot_fops-to-rely-on-tracing_get_cpu.patch queue-3.10/tracing-change-tracing_buffers_fops-to-rely-on-tracing_get_cpu.patch queue-3.10/tracing-change-f_start-to-take-event_mutex-and-verify-i_private-null.patch queue-3.10/tracing-change-event_enable-disable_read-to-verify-i_private-null.patch queue-3.10/tracing-change-tracing_stats_fops-to-rely-on.patch queue-3.10/tracing-trace_remove_event_call-should-fail-if-call-file-is-in-use.patch queue-3.10/tracing-change-tracing_pipe_fops-to-rely-on-tracing_get_cpu.patch queue-3.10/tracing-change-tracing_entries_fops-to-rely-on-tracing_get_cpu.patch queue-3.10/tracing-turn-event-id-i_private-into-call-event.type.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