From: Valentin Schneider <vschneid@redhat.com>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: Steven Rostedt <rostedt@goodmis.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Masami Hiramatsu <mhiramat@kernel.org>
Subject: [PATCH 1/4] tracing/filters: Fix error-handling of cpulist parsing buffer
Date: Fri, 1 Sep 2023 17:10:36 +0200 [thread overview]
Message-ID: <20230901151039.125186-2-vschneid@redhat.com> (raw)
In-Reply-To: <20230901151039.125186-1-vschneid@redhat.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.
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
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 3a529214a21b7..c06e1d596f4b9 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.31.1
next prev parent reply other threads:[~2023-09-01 15:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 15:10 [PATCH 0/4] Minor v6.6 trace_events_filter fixes Valentin Schneider
2023-09-01 15:10 ` Valentin Schneider [this message]
2023-09-01 15:10 ` [PATCH 2/4] tracing/filters: Fix double-free of struct filter_pred.mask Valentin Schneider
2023-09-01 15:10 ` [PATCH 3/4] tracing/filters: Change parse_pred() cpulist ternary into an if block Valentin Schneider
2023-09-01 15:10 ` [PATCH 4/4] tracing/filters: Fix coding style issues Valentin Schneider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230901151039.125186-2-vschneid@redhat.com \
--to=vschneid@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).