aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>2014-06-05 18:35:17 -0400
committerSteven Rostedt <rostedt@goodmis.org>2014-06-06 04:47:46 -0400
commitdc81e5e3abb9f98a3cb6f269c0bee595b2c1235d (patch)
tree7a61f4727ce4bcee34e8ec808b5c51e2510d9a9a
parent34839f5a69989c0ee48386a788fba37eb75910f7 (diff)
tracing: Return error if ftrace_trace_arrays list is empty
ftrace_trace_arrays links global_trace.list. However, global_trace is not added to ftrace_trace_arrays if trace_alloc_buffers() failed. As the result, ftrace_trace_arrays becomes an empty list. If ftrace_trace_arrays is an empty list, current top_trace_array() returns an invalid pointer. As the result, the kernel can induce memory corruption or panic. Current implementation does not check whether ftrace_trace_arrays is empty list or not. So, in this patch, if ftrace_trace_arrays is empty list, top_trace_array() returns NULL. Moreover, this patch makes all functions calling top_trace_array() handle it appropriately. Link: http://lkml.kernel.org/p/20140605223517.32311.99233.stgit@yunodevel Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel/trace/trace.h3
-rw-r--r--kernel/trace/trace_events.c13
2 files changed, 16 insertions, 0 deletions
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 217207ad60b3..9e82551dd566 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -252,6 +252,9 @@ static inline struct trace_array *top_trace_array(void)
252{ 252{
253 struct trace_array *tr; 253 struct trace_array *tr;
254 254
255 if (list_empty(ftrace_trace_arrays.prev))
256 return NULL;
257
255 tr = list_entry(ftrace_trace_arrays.prev, 258 tr = list_entry(ftrace_trace_arrays.prev,
256 typeof(*tr), list); 259 typeof(*tr), list);
257 WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL)); 260 WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 3ddfd8f62c05..f99e0b3bca8c 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -574,6 +574,9 @@ int trace_set_clr_event(const char *system, const char *event, int set)
574{ 574{
575 struct trace_array *tr = top_trace_array(); 575 struct trace_array *tr = top_trace_array();
576 576
577 if (!tr)
578 return -ENODEV;
579
577 return __ftrace_set_clr_event(tr, NULL, system, event, set); 580 return __ftrace_set_clr_event(tr, NULL, system, event, set);
578} 581}
579EXPORT_SYMBOL_GPL(trace_set_clr_event); 582EXPORT_SYMBOL_GPL(trace_set_clr_event);
@@ -2065,6 +2068,9 @@ event_enable_func(struct ftrace_hash *hash,
2065 bool enable; 2068 bool enable;
2066 int ret; 2069 int ret;
2067 2070
2071 if (!tr)
2072 return -ENODEV;
2073
2068 /* hash funcs only work with set_ftrace_filter */ 2074 /* hash funcs only work with set_ftrace_filter */
2069 if (!enabled || !param) 2075 if (!enabled || !param)
2070 return -EINVAL; 2076 return -EINVAL;
@@ -2396,6 +2402,9 @@ static __init int event_trace_enable(void)
2396 char *token; 2402 char *token;
2397 int ret; 2403 int ret;
2398 2404
2405 if (!tr)
2406 return -ENODEV;
2407
2399 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { 2408 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
2400 2409
2401 call = *iter; 2410 call = *iter;
@@ -2442,6 +2451,8 @@ static __init int event_trace_init(void)
2442 int ret; 2451 int ret;
2443 2452
2444 tr = top_trace_array(); 2453 tr = top_trace_array();
2454 if (!tr)
2455 return -ENODEV;
2445 2456
2446 d_tracer = tracing_init_dentry(); 2457 d_tracer = tracing_init_dentry();
2447 if (!d_tracer) 2458 if (!d_tracer)
@@ -2535,6 +2546,8 @@ static __init void event_trace_self_tests(void)
2535 int ret; 2546 int ret;
2536 2547
2537 tr = top_trace_array(); 2548 tr = top_trace_array();
2549 if (!tr)
2550 return;
2538 2551
2539 pr_info("Running tests on trace events:\n"); 2552 pr_info("Running tests on trace events:\n");
2540 2553