Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
tracing: Fix possible double free in event_enable_trigger_func()
Browse files Browse the repository at this point in the history
commit 15cc78644d0075e76d59476a4467e7143860f660 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/[email protected]

Cc: [email protected]
Fixes: 7862ad1 ("tracing: Add 'enable_event' and 'disable_event' event trigger commands")
Reivewed-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rostedt authored and gregkh committed Aug 3, 2018
1 parent 2a0ce1f commit a9737bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kernel/trace/trace_events_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,9 @@ int event_enable_trigger_func(struct event_command *cmd_ops,
goto out;
}

/* Up the trigger_data count to make sure nothing frees it on failure */
event_trigger_init(trigger_ops, trigger_data);

if (trigger) {
number = strsep(&trigger, ":");

Expand Down Expand Up @@ -1439,6 +1442,7 @@ int event_enable_trigger_func(struct event_command *cmd_ops,
goto out_disable;
/* Just return zero, not the number of enabled functions */
ret = 0;
event_trigger_free(trigger_ops, trigger_data);
out:
return ret;

Expand All @@ -1449,7 +1453,7 @@ int event_enable_trigger_func(struct event_command *cmd_ops,
out_free:
if (cmd_ops->set_filter)
cmd_ops->set_filter(NULL, trigger_data, NULL);
kfree(trigger_data);
event_trigger_free(trigger_ops, trigger_data);
kfree(enable_data);
goto out;
}
Expand Down

0 comments on commit a9737bb

Please sign in to comment.