Skip to content

Commit 0b3dec0

Browse files
committed
tracing: Enforce passing in filter=NULL to create_filter()
There's some inconsistency with what to set the output parameter filterp when passing to create_filter(..., struct event_filter **filterp). Whatever filterp points to, should be NULL when calling this function. The create_filter() calls create_filter_start() with a pointer to a local "filter" variable that is set to NULL. The create_filter_start() has a WARN_ON() if the passed in pointer isn't pointing to a value set to NULL. Ideally, create_filter() should pass the filterp variable it received to create_filter_start() and not hide it as with a local variable, this allowed create_filter() to fail, and not update the passed in filter, and the caller of create_filter() then tried to free filter, which was never initialized to anything, causing memory corruption. Link: http://lkml.kernel.org/r/[email protected] Fixes: 8076559 ("tracing: Rewrite filter logic to be simpler and faster") Reported-by: [email protected] Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent a64b2c0 commit 0b3dec0

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,18 +1704,16 @@ static int create_filter(struct trace_event_call *call,
17041704
struct event_filter **filterp)
17051705
{
17061706
struct filter_parse_error *pe = NULL;
1707-
struct event_filter *filter = NULL;
17081707
int err;
17091708

1710-
err = create_filter_start(filter_string, set_str, &pe, &filter);
1709+
err = create_filter_start(filter_string, set_str, &pe, filterp);
17111710
if (err)
17121711
return err;
17131712

1714-
err = process_preds(call, filter_string, filter, pe);
1713+
err = process_preds(call, filter_string, *filterp, pe);
17151714
if (err && set_str)
1716-
append_filter_err(pe, filter);
1715+
append_filter_err(pe, *filterp);
17171716

1718-
*filterp = filter;
17191717
return err;
17201718
}
17211719

@@ -1739,32 +1737,30 @@ static int create_system_filter(struct trace_subsystem_dir *dir,
17391737
struct trace_array *tr,
17401738
char *filter_str, struct event_filter **filterp)
17411739
{
1742-
struct event_filter *filter = NULL;
17431740
struct filter_parse_error *pe = NULL;
17441741
int err;
17451742

1746-
err = create_filter_start(filter_str, true, &pe, &filter);
1743+
err = create_filter_start(filter_str, true, &pe, filterp);
17471744
if (!err) {
17481745
err = process_system_preds(dir, tr, pe, filter_str);
17491746
if (!err) {
17501747
/* System filters just show a default message */
1751-
kfree(filter->filter_string);
1752-
filter->filter_string = NULL;
1748+
kfree((*filterp)->filter_string);
1749+
(*filterp)->filter_string = NULL;
17531750
} else {
1754-
append_filter_err(pe, filter);
1751+
append_filter_err(pe, *filterp);
17551752
}
17561753
}
17571754
create_filter_finish(pe);
17581755

1759-
*filterp = filter;
17601756
return err;
17611757
}
17621758

17631759
/* caller must hold event_mutex */
17641760
int apply_event_filter(struct trace_event_file *file, char *filter_string)
17651761
{
17661762
struct trace_event_call *call = file->event_call;
1767-
struct event_filter *filter;
1763+
struct event_filter *filter = NULL;
17681764
int err;
17691765

17701766
if (!strcmp(strstrip(filter_string), "0")) {
@@ -1817,7 +1813,7 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
18171813
{
18181814
struct event_subsystem *system = dir->subsystem;
18191815
struct trace_array *tr = dir->tr;
1820-
struct event_filter *filter;
1816+
struct event_filter *filter = NULL;
18211817
int err = 0;
18221818

18231819
mutex_lock(&event_mutex);
@@ -2024,7 +2020,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
20242020
char *filter_str)
20252021
{
20262022
int err;
2027-
struct event_filter *filter;
2023+
struct event_filter *filter = NULL;
20282024
struct trace_event_call *call;
20292025

20302026
mutex_lock(&event_mutex);

0 commit comments

Comments
 (0)