summaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_output.h
diff options
context:
space:
mode:
authorLai Jiangshan <laijs@cn.fujitsu.com>2009-05-18 19:35:34 +0800
committerFrederic Weisbecker <fweisbec@gmail.com>2009-05-25 23:53:41 +0200
commit4f5359685af6de7dca101393dc606620adbe963f (patch)
tree1f9dc3fb9299008daa6a5fb6f03945008ea4a4f9 /kernel/trace/trace_output.h
parent5537937696c55530447c20aa27daccb8d0d29b33 (diff)
downloadlinux-4f5359685af6de7dca101393dc606620adbe963f.tar.gz
linux-4f5359685af6de7dca101393dc606620adbe963f.tar.bz2
linux-4f5359685af6de7dca101393dc606620adbe963f.zip
tracing: add trace_event_read_lock()
I found that there is nothing to protect event_hash in ftrace_find_event(). Rcu protects the event hashlist but not the event itself while we use it after its extraction through ftrace_find_event(). This lack of a proper locking in this spot opens a race window between any event dereferencing and module removal. Eg: --Task A-- print_trace_line(trace) { event = find_ftrace_event(trace) --Task B-- trace_module_remove_events(mod) { list_trace_events_module(ev, mod) { unregister_ftrace_event(ev->event) { hlist_del(ev->event->node) list_del(....) } } } |--> module removed, the event has been dropped --Task A-- event->print(trace); // Dereferencing freed memory If the event retrieved belongs to a module and this module is concurrently removed, we may end up dereferencing a data from a freed module. RCU could solve this, but it would add latency to the kernel and forbid tracers output callbacks to call any sleepable code. So this fix converts 'trace_event_mutex' to a read/write semaphore, and adds trace_event_read_lock() to protect ftrace_find_event(). [ Impact: fix possible freed memory dereference in ftrace ] Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> LKML-Reference: <4A114806.7090302@cn.fujitsu.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'kernel/trace/trace_output.h')
-rw-r--r--kernel/trace/trace_output.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index 6e220a8e5706..ac240e76eb01 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -20,6 +20,8 @@ extern int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
extern int trace_print_context(struct trace_iterator *iter);
extern int trace_print_lat_context(struct trace_iterator *iter);
+extern void trace_event_read_lock(void);
+extern void trace_event_read_unlock(void);
extern struct trace_event *ftrace_find_event(int type);
extern enum print_line_t trace_nop_print(struct trace_iterator *iter,