[for-linus][PATCH 09/11] tracing/filters: Fix double-free of struct filter_pred.mask

From: Steven Rostedt
Date: Sat Sep 02 2023 - 07:51:22 EST


From: Valentin Schneider <vschneid@xxxxxxxxxx>

When a cpulist filter is found to contain a single CPU, that CPU is saved
as a scalar and the backing cpumask storage is freed.

Also NULL the mask to avoid a double-free once we get down to
free_predicate().

Link: https://lkml.kernel.org/r/20230901151039.125186-3-vschneid@xxxxxxxxxx

Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Reported-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
Signed-off-by: Valentin Schneider <vschneid@xxxxxxxxxx>
Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
kernel/trace/trace_events_filter.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index c06e1d596f4b..eb331e8b00b6 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1773,6 +1773,7 @@ static int parse_pred(const char *str, void *data,
if (single) {
pred->val = cpumask_first(pred->mask);
kfree(pred->mask);
+ pred->mask = NULL;
}

if (field->filter_type == FILTER_CPUMASK) {
--
2.40.1