Skip to contentSkip to conversation

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

PATCH New Steven Rostedt 1 participant 1 message Jun 10, 2025 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

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

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes

Head SHA1: 8a157d8a00e815cab4432653cb50c9cedbbb4931

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

----

 kernel/trace/trace_events_filter.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
---------------------------
commit 8a157d8a00e815cab4432653cb50c9cedbbb4931
Author: Steven Rostedt <[email protected]>
Date:   Tue Jun 10 09:33:48 2025 -0400

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

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]>
Fixes a9d0aab5eb33 ("tracing: Fix regression of filter waiting a long time on RCU synchronization")
kernel/trace/trace_events_filter.c +1 -3
index ea8b364b6818..08141f105c95 100644
@@ -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);