tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
authorSteven Rostedt <rostedt@goodmis.org>
Thu, 30 Jun 2016 00:55:59 +0000 (19:55 -0500)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 2 Aug 2016 19:16:02 +0000 (15:16 -0400)
While running tools/testing/selftests test suite with KASAN, Dmitry
Vyukov hit the following use-after-free report:

  ==================================================================
  BUG: KASAN: use-after-free in hist_unreg_all+0x1a1/0x1d0 at addr
  ffff880031632cc0
  Read of size 8 by task ftracetest/7413
  ==================================================================
  BUG kmalloc-128 (Not tainted): kasan: bad access detected
  ------------------------------------------------------------------

This fixes the problem, along with the same problem in
hist_enable_unreg_all().

Link: http://lkml.kernel.org/r/c3d05b79e42555b6e36a3a99aae0e37315ee5304.1467247517.git.tom.zanussi@linux.intel.com
Cc: Dmitry Vyukov <dvyukov@google.com>
[Copied Steve's hist_enable_unreg_all() fix to hist_unreg_all()]
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_events_hist.c

index 0c05b8a9980646adcf61c8cbc13355b535334f72..19ae135120a3d1c7ac3f264bd158d78c95aecc79 100644 (file)
@@ -1500,9 +1500,9 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops,
 
 static void hist_unreg_all(struct trace_event_file *file)
 {
-       struct event_trigger_data *test;
+       struct event_trigger_data *test, *n;
 
-       list_for_each_entry_rcu(test, &file->triggers, list) {
+       list_for_each_entry_safe(test, n, &file->triggers, list) {
                if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
                        list_del_rcu(&test->list);
                        trace_event_trigger_enable_disable(file, 0);
@@ -1699,9 +1699,9 @@ hist_enable_get_trigger_ops(char *cmd, char *param)
 
 static void hist_enable_unreg_all(struct trace_event_file *file)
 {
-       struct event_trigger_data *test;
+       struct event_trigger_data *test, *n;
 
-       list_for_each_entry_rcu(test, &file->triggers, list) {
+       list_for_each_entry_safe(test, n, &file->triggers, list) {
                if (test->cmd_ops->trigger_type == ETT_HIST_ENABLE) {
                        list_del_rcu(&test->list);
                        update_cond_flag(file);