Commit 1a7f63b2 authored by Steven Rostedt (VMware)'s avatar Steven Rostedt (VMware) Committed by Greg Kroah-Hartman

tracing: Fix possible double free in event_enable_trigger_func()

commit 15cc7864 upstream.

There was a case that triggered a double free in event_trigger_callback()
due to the called reg() function freeing the trigger_data and then it
getting freed again by the error return by the caller. The solution there
was to up the trigger_data ref count.

Code inspection found that event_enable_trigger_func() has the same issue,
but is not as easy to trigger (requires harder to trigger failures). It
needs to be solved slightly different as it needs more to clean up when the
reg() function fails.

Link: http://lkml.kernel.org/r/20180725124008.7008e586@gandalf.local.home

Cc: stable@vger.kernel.org
Fixes: 7862ad18 ("tracing: Add 'enable_event' and 'disable_event' event trigger commands")
Reivewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b80091b0
...@@ -1231,6 +1231,9 @@ event_enable_trigger_func(struct event_command *cmd_ops, ...@@ -1231,6 +1231,9 @@ event_enable_trigger_func(struct event_command *cmd_ops,
goto out; goto out;
} }
/* Up the trigger_data count to make sure nothing frees it on failure */
event_trigger_init(trigger_ops, trigger_data);
if (trigger) { if (trigger) {
number = strsep(&trigger, ":"); number = strsep(&trigger, ":");
...@@ -1281,6 +1284,7 @@ event_enable_trigger_func(struct event_command *cmd_ops, ...@@ -1281,6 +1284,7 @@ event_enable_trigger_func(struct event_command *cmd_ops,
goto out_disable; goto out_disable;
/* Just return zero, not the number of enabled functions */ /* Just return zero, not the number of enabled functions */
ret = 0; ret = 0;
event_trigger_free(trigger_ops, trigger_data);
out: out:
return ret; return ret;
...@@ -1291,7 +1295,7 @@ event_enable_trigger_func(struct event_command *cmd_ops, ...@@ -1291,7 +1295,7 @@ event_enable_trigger_func(struct event_command *cmd_ops,
out_free: out_free:
if (cmd_ops->set_filter) if (cmd_ops->set_filter)
cmd_ops->set_filter(NULL, trigger_data, NULL); cmd_ops->set_filter(NULL, trigger_data, NULL);
kfree(trigger_data); event_trigger_free(trigger_ops, trigger_data);
kfree(enable_data); kfree(enable_data);
goto out; goto out;
} }
......
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