Commit dc81e5e3 authored by Yoshihiro YUNOMAE's avatar Yoshihiro YUNOMAE Committed by Steven Rostedt

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@yunodevelSigned-off-by: default avatarYoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 34839f5a
...@@ -252,6 +252,9 @@ static inline struct trace_array *top_trace_array(void) ...@@ -252,6 +252,9 @@ static inline struct trace_array *top_trace_array(void)
{ {
struct trace_array *tr; struct trace_array *tr;
if (list_empty(ftrace_trace_arrays.prev))
return NULL;
tr = list_entry(ftrace_trace_arrays.prev, tr = list_entry(ftrace_trace_arrays.prev,
typeof(*tr), list); typeof(*tr), list);
WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL)); WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
......
...@@ -574,6 +574,9 @@ int trace_set_clr_event(const char *system, const char *event, int set) ...@@ -574,6 +574,9 @@ int trace_set_clr_event(const char *system, const char *event, int set)
{ {
struct trace_array *tr = top_trace_array(); struct trace_array *tr = top_trace_array();
if (!tr)
return -ENODEV;
return __ftrace_set_clr_event(tr, NULL, system, event, set); return __ftrace_set_clr_event(tr, NULL, system, event, set);
} }
EXPORT_SYMBOL_GPL(trace_set_clr_event); EXPORT_SYMBOL_GPL(trace_set_clr_event);
...@@ -2065,6 +2068,9 @@ event_enable_func(struct ftrace_hash *hash, ...@@ -2065,6 +2068,9 @@ event_enable_func(struct ftrace_hash *hash,
bool enable; bool enable;
int ret; int ret;
if (!tr)
return -ENODEV;
/* hash funcs only work with set_ftrace_filter */ /* hash funcs only work with set_ftrace_filter */
if (!enabled || !param) if (!enabled || !param)
return -EINVAL; return -EINVAL;
...@@ -2396,6 +2402,9 @@ static __init int event_trace_enable(void) ...@@ -2396,6 +2402,9 @@ static __init int event_trace_enable(void)
char *token; char *token;
int ret; int ret;
if (!tr)
return -ENODEV;
for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
call = *iter; call = *iter;
...@@ -2442,6 +2451,8 @@ static __init int event_trace_init(void) ...@@ -2442,6 +2451,8 @@ static __init int event_trace_init(void)
int ret; int ret;
tr = top_trace_array(); tr = top_trace_array();
if (!tr)
return -ENODEV;
d_tracer = tracing_init_dentry(); d_tracer = tracing_init_dentry();
if (!d_tracer) if (!d_tracer)
...@@ -2535,6 +2546,8 @@ static __init void event_trace_self_tests(void) ...@@ -2535,6 +2546,8 @@ static __init void event_trace_self_tests(void)
int ret; int ret;
tr = top_trace_array(); tr = top_trace_array();
if (!tr)
return;
pr_info("Running tests on trace events:\n"); pr_info("Running tests on trace events:\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment