projects/linux·commit 8a157d8a

tracing: Do not free "head" on error path of filter_free_subsystem_filters()

8a157d8a · Steven Rostedt <[email protected]> · 2025-06-10 09:33:48 -04:00

The variable "head" is allocated and initialized as a list before
allocating the first "item" for the list. If the allocation of "item"
fails, it frees "head" and then jumps to the label "free_now" which will
process head and free it.

This will cause a UAF of "head", and it doesn't need to free it before
jumping to the "free_now" label as that code will free it.

Cc: Masami Hiramatsu <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Link: https://lore.kernel.org/[email protected]
Fixes: a9d0aab5eb33 ("tracing: Fix regression of filter waiting a long time on RCU synchronization")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]/
Signed-off-by: Steven Rostedt (Google) <[email protected]>
Commit
8a157d8a00e815cab4432653cb50c9cedbbb4931
Parents
19272b37

Changes

1 files changed · +1 −3

FileStatusAddDelContent
kernel/trace/trace_events_filter.cmodified+1−3View file

kernel/trace/trace_events_filter.c

View file
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index ea8b364..08141f1 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1437,10 +1437,8 @@ static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
INIT_LIST_HEAD(&head->list);
item = kmalloc(sizeof(*item), GFP_KERNEL);
- if (!item) {
- kfree(head);
+ if (!item)
goto free_now;
- }
item->filter = filter;
list_add_tail(&item->list, &head->list);