diff mbox series

[1/8] tracing: tprobe-events: Fix a memory leak when tprobe with $retval

Message ID 174055072650.4079315.3063014346697447838.stgit@mhiramat.tok.corp.google.com (mailing list archive)
State Queued
Commit ac965d7d88fc36fb42e3d50225c0a44dd8326da4
Headers show
Series tracing: probes: Fixes and enhancing error logs | expand

Commit Message

Masami Hiramatsu (Google) Feb. 26, 2025, 6:18 a.m. UTC
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Fix a memory leak when a tprobe is defined with $retval. This
combination is not allowed, but the parse_symbol_and_return() does
not free the *symbol which should not be used if it returns the error.
Thus, it leaks the *symbol memory in that error path.

Fixes: ce51e6153f77 ("tracing: fprobe-event: Fix to check tracepoint event and return")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: stable@vger.kernel.org
---
 kernel/trace/trace_fprobe.c |    2 ++
 1 file changed, 2 insertions(+)

Comments

Steven Rostedt Feb. 26, 2025, 3:09 p.m. UTC | #1
On Wed, 26 Feb 2025 15:18:46 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Fix a memory leak when a tprobe is defined with $retval. This
> combination is not allowed, but the parse_symbol_and_return() does
> not free the *symbol which should not be used if it returns the error.
> Thus, it leaks the *symbol memory in that error path.
> 
> Fixes: ce51e6153f77 ("tracing: fprobe-event: Fix to check tracepoint event and return")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> Cc: stable@vger.kernel.org

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

> ---
>  kernel/trace/trace_fprobe.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c
> index b8f3c4ba309b..8826f44f69a4 100644
> --- a/kernel/trace/trace_fprobe.c
> +++ b/kernel/trace/trace_fprobe.c
> @@ -1056,6 +1056,8 @@ static int parse_symbol_and_return(int argc, const char *argv[],
>  			if (is_tracepoint) {
>  				trace_probe_log_set_index(i);
>  				trace_probe_log_err(tmp - argv[i], RETVAL_ON_PROBE);
> +				kfree(*symbol);
> +				*symbol = NULL;
>  				return -EINVAL;
>  			}
>  			*is_return = true;
diff mbox series

Patch

diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c
index b8f3c4ba309b..8826f44f69a4 100644
--- a/kernel/trace/trace_fprobe.c
+++ b/kernel/trace/trace_fprobe.c
@@ -1056,6 +1056,8 @@  static int parse_symbol_and_return(int argc, const char *argv[],
 			if (is_tracepoint) {
 				trace_probe_log_set_index(i);
 				trace_probe_log_err(tmp - argv[i], RETVAL_ON_PROBE);
+				kfree(*symbol);
+				*symbol = NULL;
 				return -EINVAL;
 			}
 			*is_return = true;