tracing: Add rcu dereference annotation for test func that touches filter->prog
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 5 Apr 2018 19:20:26 +0000 (15:20 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Fri, 6 Apr 2018 12:56:54 +0000 (08:56 -0400)
A boot up test function update_pred_fn() dereferences filter->prog without
the proper rcu annotation.

To do this, we must also take the event_mutex first. Normally, this isn't
needed because this test function can not race with other use cases that
touch the event filters (it is disabled if any events are enabled).

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Fixes: 80765597bc587 ("tracing: Rewrite filter logic to be simpler and faster")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/trace_events_filter.c

index cf8460caa95cbe95f21d96aaf579da1bd424b02b..1bda4ec95e1819d9fade7de8684f16dc0425dde5 100644 (file)
@@ -2155,7 +2155,8 @@ static int test_pred_visited_fn(struct filter_pred *pred, void *event)
 
 static void update_pred_fn(struct event_filter *filter, char *fields)
 {
-       struct prog_entry *prog = filter->prog;
+       struct prog_entry *prog = rcu_dereference_protected(filter->prog,
+                                               lockdep_is_held(&event_mutex));
        int i;
 
        for (i = 0; prog[i].pred; i++) {
@@ -2197,6 +2198,8 @@ static __init int ftrace_test_event_filter(void)
                        break;
                }
 
+               /* Needed to dereference filter->prog */
+               mutex_lock(&event_mutex);
                /*
                 * The preemption disabling is not really needed for self
                 * tests, but the rcu dereference will complain without it.
@@ -2209,6 +2212,8 @@ static __init int ftrace_test_event_filter(void)
                err = filter_match_preds(filter, &d->rec);
                preempt_enable();
 
+               mutex_unlock(&event_mutex);
+
                __free_filter(filter);
 
                if (test_pred_visited) {