[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230902115119.676231106@goodmis.org>
Date: Sat, 02 Sep 2023 07:50:43 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: linux-kernel@...r.kernel.org
Cc: Masami Hiramatsu <mhiramat@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Valentin Schneider <vschneid@...hat.com>
Subject: [for-linus][PATCH 08/11] tracing/filters: Fix error-handling of cpulist parsing buffer
From: Valentin Schneider <vschneid@...hat.com>
parse_pred() allocates a string buffer to parse the user-provided cpulist,
but doesn't check the allocation result nor does it free the buffer once it
is no longer needed.
Add an allocation check, and free the buffer as soon as it is no longer
needed.
Link: https://lkml.kernel.org/r/20230901151039.125186-2-vschneid@redhat.com
Cc: Masami Hiramatsu <mhiramat@...nel.org>
Reported-by: Steven Rostedt <rostedt@...dmis.org>
Reported-by: Josh Poimboeuf <jpoimboe@...hat.com>
Signed-off-by: Valentin Schneider <vschneid@...hat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
---
kernel/trace/trace_events_filter.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 3a529214a21b..c06e1d596f4b 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1744,17 +1744,23 @@ static int parse_pred(const char *str, void *data,
/* Copy the cpulist between { and } */
tmp = kmalloc((i - maskstart) + 1, GFP_KERNEL);
- strscpy(tmp, str + maskstart, (i - maskstart) + 1);
+ if (!tmp)
+ goto err_mem;
+ strscpy(tmp, str + maskstart, (i - maskstart) + 1);
pred->mask = kzalloc(cpumask_size(), GFP_KERNEL);
- if (!pred->mask)
+ if (!pred->mask) {
+ kfree(tmp);
goto err_mem;
+ }
/* Now parse it */
if (cpulist_parse(tmp, pred->mask)) {
+ kfree(tmp);
parse_error(pe, FILT_ERR_INVALID_CPULIST, pos + i);
goto err_free;
}
+ kfree(tmp);
/* Move along */
i++;
--
2.40.1
Powered by blists - more mailing lists