]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tracing: Fix filter logic error
authorEdward Adam Davis <eadavis@qq.com>
Tue, 24 Jun 2025 06:38:46 +0000 (14:38 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Fri, 27 Jun 2025 19:51:36 +0000 (15:51 -0400)
If the processing of the tr->events loop fails, the filter that has been
added to filter_head will be released twice in free_filter_list(&head->rcu)
and __free_filter(filter).

After adding the filter of tr->events, add the filter to the filter_head
process to avoid triggering uaf.

Link: https://lore.kernel.org/tencent_4EF87A626D702F816CD0951CE956EC32CD0A@qq.com
Fixes: a9d0aab5eb33 ("tracing: Fix regression of filter waiting a long time on RCU synchronization")
Reported-by: syzbot+daba72c4af9915e9c894@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=daba72c4af9915e9c894
Tested-by: syzbot+daba72c4af9915e9c894@syzkaller.appspotmail.com
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_events_filter.c

index 08141f105c95473f3621b7ab1a18a5a464a3dffe..3885aadc434d9320a2252f1bbff769fb35dbeb25 100644 (file)
@@ -1436,13 +1436,6 @@ static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
 
        INIT_LIST_HEAD(&head->list);
 
-       item = kmalloc(sizeof(*item), GFP_KERNEL);
-       if (!item)
-               goto free_now;
-
-       item->filter = filter;
-       list_add_tail(&item->list, &head->list);
-
        list_for_each_entry(file, &tr->events, list) {
                if (file->system != dir)
                        continue;
@@ -1454,6 +1447,13 @@ static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
                event_clear_filter(file);
        }
 
+       item = kmalloc(sizeof(*item), GFP_KERNEL);
+       if (!item)
+               goto free_now;
+
+       item->filter = filter;
+       list_add_tail(&item->list, &head->list);
+
        delay_free_filter(head);
        return;
  free_now: