Commit a66abe7f authored by Ingo Molnar's avatar Ingo Molnar

tracing/events: Fix locking imbalance in the filter code

Américo Wang noticed that we have a locking imbalance in the
error paths of ftrace_profile_set_filter(), causing potential
leakage of event_mutex.

Also clean up other error codepaths related to event_mutex
while at it.

Plus fix an initialized variable in the subsystem filter code.
Reported-by: default avatarAmérico Wang <xiyou.wangcong@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <2375c9f90910150247u5ccb8e2at58c764e385ffa490@mail.gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent c171b552
...@@ -1230,10 +1230,10 @@ static int replace_system_preds(struct event_subsystem *system, ...@@ -1230,10 +1230,10 @@ static int replace_system_preds(struct event_subsystem *system,
struct filter_parse_state *ps, struct filter_parse_state *ps,
char *filter_string) char *filter_string)
{ {
struct event_filter *filter = system->filter;
struct ftrace_event_call *call; struct ftrace_event_call *call;
struct event_filter *filter;
int err;
bool fail = true; bool fail = true;
int err;
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
...@@ -1262,7 +1262,7 @@ static int replace_system_preds(struct event_subsystem *system, ...@@ -1262,7 +1262,7 @@ static int replace_system_preds(struct event_subsystem *system,
if (fail) { if (fail) {
parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0); parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
return err; return -EINVAL;
} }
return 0; return 0;
} }
...@@ -1281,8 +1281,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) ...@@ -1281,8 +1281,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
if (!strcmp(strstrip(filter_string), "0")) { if (!strcmp(strstrip(filter_string), "0")) {
filter_disable_preds(call); filter_disable_preds(call);
remove_filter_string(call->filter); remove_filter_string(call->filter);
mutex_unlock(&event_mutex); goto out_unlock;
return 0;
} }
err = -ENOMEM; err = -ENOMEM;
...@@ -1330,8 +1329,7 @@ int apply_subsystem_event_filter(struct event_subsystem *system, ...@@ -1330,8 +1329,7 @@ int apply_subsystem_event_filter(struct event_subsystem *system,
if (!strcmp(strstrip(filter_string), "0")) { if (!strcmp(strstrip(filter_string), "0")) {
filter_free_subsystem_preds(system); filter_free_subsystem_preds(system);
remove_filter_string(system->filter); remove_filter_string(system->filter);
mutex_unlock(&event_mutex); goto out_unlock;
return 0;
} }
err = -ENOMEM; err = -ENOMEM;
...@@ -1386,15 +1384,20 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, ...@@ -1386,15 +1384,20 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
if (call->id == event_id) if (call->id == event_id)
break; break;
} }
err = -EINVAL;
if (!call) if (!call)
return -EINVAL; goto out_unlock;
err = -EEXIST;
if (event->filter) if (event->filter)
return -EEXIST; goto out_unlock;
filter = __alloc_preds(); filter = __alloc_preds();
if (IS_ERR(filter)) if (IS_ERR(filter)) {
return PTR_ERR(filter); err = PTR_ERR(filter);
goto out_unlock;
}
err = -ENOMEM; err = -ENOMEM;
ps = kzalloc(sizeof(*ps), GFP_KERNEL); ps = kzalloc(sizeof(*ps), GFP_KERNEL);
...@@ -1419,6 +1422,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, ...@@ -1419,6 +1422,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
if (err) if (err)
__free_preds(filter); __free_preds(filter);
out_unlock:
mutex_unlock(&event_mutex); mutex_unlock(&event_mutex);
return err; return err;
......
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