* [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c.
@ 2024-04-26 9:13 lumingyindetect
2024-04-26 15:18 ` Masami Hiramatsu
2024-04-26 15:19 ` [PATCH] tracing/probes: Fix memory leak issues " Markus Elfring
0 siblings, 2 replies; 4+ messages in thread
From: lumingyindetect @ 2024-04-26 9:13 UTC (permalink / raw)
To: linux-trace-kernel, linux-kernel
Cc: rostedt, mhiramat, mathieu.desnoyers, LuMingYin
From: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
At line 1408 of the file /linux/kernel/trace/trace_probe.c, pointer variables named code and tmp are defined. At line 1437, a new dynamic memory area is allocated using the function kcalloc. When the if statement at line 1467 evaluates to true, the program jumps to the out label at line 1469. Within this function, there are two labels: out and fail. The difference between these two labels is that fail additionally frees the dynamic memory area pointed to by the variable code. Therefore, the program should jump to the fail label instead of the out label. This commit fixes this bug.
Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.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 dfe3ee6035ec..42bc0f362226 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c.
2024-04-26 9:13 [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c lumingyindetect
@ 2024-04-26 15:18 ` Masami Hiramatsu
2024-04-26 16:45 ` tracing/probes: Fix a memory leak in traceprobe_parse_probe_arg_body() Markus Elfring
2024-04-26 15:19 ` [PATCH] tracing/probes: Fix memory leak issues " Markus Elfring
1 sibling, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2024-04-26 15:18 UTC (permalink / raw)
To: lumingyindetect
Cc: linux-trace-kernel, linux-kernel, rostedt, mhiramat,
mathieu.desnoyers, LuMingYin
Hi LuMingYin,
Thanks for finding the problem! But please make a commit message
following Documentation/process/submitting-patches.rst
On Fri, 26 Apr 2024 10:13:43 +0100
lumingyindetect@126.com wrote:
> From: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
>
> At line 1408 of the file /linux/kernel/trace/trace_probe.c, pointer variables named code and tmp are defined. At line 1437, a new dynamic memory area is allocated using the function kcalloc. When the if statement at line 1467 evaluates to true, the program jumps to the out label at line 1469. Within this function, there are two labels: out and fail. The difference between these two labels is that fail additionally frees the dynamic memory area pointed to by the variable code. Therefore, the program should jump to the fail label instead of the out label. This commit fixes this bug.
>
For example, you must line break after about 70 characters. Also,
please don't use the line number because the line number is easily
changed (function name is OK). Since this bug is very clear mistake,
so you can just explain that as following.
----
If traceprobe_parse_probe_arg_body() fails to allocate 'parg->fmt', it
jumps to 'out' instead of 'fail' by mistake. In the result, in this
case the 'tmp' buffer is not freed and leaks its memory.
Fix it by jumping to 'fail' in that case.
----
The first paragraph explains what happens, and second one to exaplain
how to fix it.
Also, please add this Fixes tag.
Fixes: 032330abd08b ("tracing/probes: Cleanup probe argument parser")
You can easily find this commit number with git blame.
Thank you,
> Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.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 dfe3ee6035ec..42bc0f362226 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
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tracing/probes: Fix memory leak issues in traceprobe_parse_probe_arg_body()
2024-04-26 9:13 [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c lumingyindetect
2024-04-26 15:18 ` Masami Hiramatsu
@ 2024-04-26 15:19 ` Markus Elfring
1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-04-26 15:19 UTC (permalink / raw)
To: lumingyindetect, linux-trace-kernel, kernel-janitors
Cc: LKML, Masami Hiramatsu, Mathieu Desnoyers, Steven Rostedt
…
> Therefore, the program should jump to the fail label instead of the out label. This commit fixes this bug.
>
> Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
Please improve your patch attempt considerably.
See also:
https://kernelnewbies.org/FirstKernelPatch
Are there further change opportunities to take better into account?
https://elixir.bootlin.com/linux/v6.9-rc5/source/kernel/trace/trace_probe.c#L1403
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: tracing/probes: Fix a memory leak in traceprobe_parse_probe_arg_body()
2024-04-26 15:18 ` Masami Hiramatsu
@ 2024-04-26 16:45 ` Markus Elfring
0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-04-26 16:45 UTC (permalink / raw)
To: Masami Hiramatsu, lumingyindetect, linux-trace-kernel,
kernel-janitors
Cc: LKML, Mathieu Desnoyers, Steven Rostedt
…
> ----
> If traceprobe_parse_probe_arg_body() fails to allocate 'parg->fmt', it
> jumps to 'out' instead of 'fail' by mistake. In the result, in this
> case the 'tmp' buffer is not freed and leaks its memory.
>
> Fix it by jumping to 'fail' in that case.
> ----
…
How do you think about another approach for a more desirable change description?
If traceprobe_parse_probe_arg_body() failed to allocate the object “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 case (so that the exception handling
will be improved another bit).
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-26 16:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 9:13 [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c lumingyindetect
2024-04-26 15:18 ` Masami Hiramatsu
2024-04-26 16:45 ` tracing/probes: Fix a memory leak in traceprobe_parse_probe_arg_body() Markus Elfring
2024-04-26 15:19 ` [PATCH] tracing/probes: Fix memory leak issues " Markus Elfring
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).