diff mbox series

[v3] tracing/probes: Fix memory leak in traceprobe_parse_probe_arg_body()

Message ID 20240427072347.1421053-1-lumingyindetect@126.com (mailing list archive)
State Accepted
Commit dce3696271af7765f04428ec31b1b87dc7d016c6
Headers show
Series [v3] tracing/probes: Fix memory leak in traceprobe_parse_probe_arg_body() | expand

Commit Message

lumingyindetect@126.com April 27, 2024, 7:23 a.m. UTC
From: LuMingYin <lumingyindetect@126.com>

If traceprobe_parse_probe_arg_body() failed to allocate 'parg->fmt',
it jumps to the label 'out' instead of 'fail' by mistake.In the result,
the buffer 'tmp' is not freed in this case and leaks its memory.

Thus jump to the label 'fail' in that error case.

Fixes: 032330abd08b ("tracing/probes: Cleanup probe argument parser")
Signed-off-by: LuMingYin <lumingyindetect@126.com>
---
 kernel/trace/trace_probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Markus Elfring April 27, 2024, 9:11 a.m. UTC | #1
>                                             … by mistake.In the result,
…

I propose once more to start the second sentence of this change description
on a subsequent line.

> ---
> kernel/trace/trace_probe.c | 2 +-
…

Unfortunately, you overlooked to add patch version descriptions behind the marker line.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc5#n713

Regards,
Markus
Masami Hiramatsu (Google) April 29, 2024, 1:29 p.m. UTC | #2
Hi LuMing,

On Sat, 27 Apr 2024 08:23:47 +0100
lumingyindetect@126.com wrote:

> From: LuMingYin <lumingyindetect@126.com>
> 
> If traceprobe_parse_probe_arg_body() failed to allocate 'parg->fmt',
> it jumps to the label 'out' instead of 'fail' by mistake.In the result,
> the buffer 'tmp' is not freed in this case and leaks its memory.
> 
> Thus jump to the label 'fail' in that error case.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>


Thank you!

> Fixes: 032330abd08b ("tracing/probes: Cleanup probe argument parser")
> Signed-off-by: LuMingYin <lumingyindetect@126.com>
> ---
>  kernel/trace/trace_probe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index c09fa6fc636e..81c319b92038 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -1466,7 +1466,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
>  		parg->fmt = kmalloc(len, GFP_KERNEL);
>  		if (!parg->fmt) {
>  			ret = -ENOMEM;
> -			goto out;
> +			goto fail;
>  		}
>  		snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
>  			 parg->count);
> -- 
> 2.25.1
> 
>
Markus Elfring April 29, 2024, 1:55 p.m. UTC | #3
> > it jumps to the label 'out' instead of 'fail' by mistake.In the result,>
> Looks good to me.

* Do you care for a typo in this change description?

* Would you like to read any improved (patch) version descriptions (or changelogs)?

Regards,
Markus
Masami Hiramatsu (Google) May 2, 2024, 1:37 a.m. UTC | #4
On Mon, 29 Apr 2024 15:55:09 +0200
Markus Elfring <Markus.Elfring@web.de> wrote:

> …
> > > it jumps to the label 'out' instead of 'fail' by mistake.In the result,
> …
> >
> > Looks good to me.
> 
> * Do you care for a typo in this change description?
> 
> * Would you like to read any improved (patch) version descriptions (or changelogs)?

Thanks, but those are nitpicks and I don't mind it.

Thank you,

> 
> Regards,
> Markus
diff mbox series

Patch

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index c09fa6fc636e..81c319b92038 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -1466,7 +1466,7 @@  static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
 		parg->fmt = kmalloc(len, GFP_KERNEL);
 		if (!parg->fmt) {
 			ret = -ENOMEM;
-			goto out;
+			goto fail;
 		}
 		snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
 			 parg->count);