* [PATCH RESEND] tracing: uprobes: Fix incorrect __free function that frees an error value in __trace_uprobe_create()
@ 2026-08-17 8:30 Ella Ma
2026-09-02 1:36 ` Masami Hiramatsu
0 siblings, 1 reply; 2+ messages in thread
From: Ella Ma @ 2026-08-17 8:30 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: linux-trace-kernel, linux-kernel, julia.lawall, Ella Ma
Before applying the __free annotation, the original version goes to
label `fail_address_parse`, and does not call function
`free_trace_uprobe` on pointer `tu`. However, after the change, the
function will be called whenever the function returns. This makes the
error value returned by `alloc_trace_uprobe` get freed.
This patch fixes this issue by adding the check for error value in the
__free function definition.
Found by Clang Static Analyzer (my own development fork
https://github.com/Snape3058/llvm-patch-revision/tree/cleanup).
warning: Argument to 'kfree()' is a constant address
(18446744073709551604), which is not memory allocated by
'malloc()' [unix.Malloc]
Fixes: 8b658df20658 ("tracing: uprobes: Cleanup __trace_uprobe_create() with __free()")
Signed-off-by: Ella Ma <alansnape3058@gmail.com>
---
kernel/trace/trace_uprobe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index c274346853d1..ccbdc96e5578 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -533,7 +533,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
return ret;
}
-DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_uprobe(_T))
+DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (!IS_ERR_OR_NULL(_T)) free_trace_uprobe(_T))
/*
* Argument syntax:
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH RESEND] tracing: uprobes: Fix incorrect __free function that frees an error value in __trace_uprobe_create()
2026-08-17 8:30 [PATCH RESEND] tracing: uprobes: Fix incorrect __free function that frees an error value in __trace_uprobe_create() Ella Ma
@ 2026-09-02 1:36 ` Masami Hiramatsu
0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2026-09-02 1:36 UTC (permalink / raw)
To: Ella Ma
Cc: rostedt, mathieu.desnoyers, linux-trace-kernel, linux-kernel,
julia.lawall
On Mon, 17 Aug 2026 10:30:14 +0200
Ella Ma <alansnape3058@gmail.com> wrote:
> Before applying the __free annotation, the original version goes to
> label `fail_address_parse`, and does not call function
> `free_trace_uprobe` on pointer `tu`. However, after the change, the
> function will be called whenever the function returns. This makes the
> error value returned by `alloc_trace_uprobe` get freed.
>
> This patch fixes this issue by adding the check for error value in the
> __free function definition.
>
> Found by Clang Static Analyzer (my own development fork
> https://github.com/Snape3058/llvm-patch-revision/tree/cleanup).
>
> warning: Argument to 'kfree()' is a constant address
> (18446744073709551604), which is not memory allocated by
> 'malloc()' [unix.Malloc]
>
Ah, thanks for the patch. Actually Andi sent the similar fix.
https://lore.kernel.org/all/20260831150651.1134594-2-ak@kernel.org/
which is more optimized one (remove redundant NULL check and
allow passing ERRPTR to free_trace_uprobe().)
Thanks,
> Fixes: 8b658df20658 ("tracing: uprobes: Cleanup __trace_uprobe_create() with __free()")
> Signed-off-by: Ella Ma <alansnape3058@gmail.com>
> ---
> kernel/trace/trace_uprobe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index c274346853d1..ccbdc96e5578 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -533,7 +533,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
> return ret;
> }
>
> -DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_uprobe(_T))
> +DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (!IS_ERR_OR_NULL(_T)) free_trace_uprobe(_T))
>
> /*
> * Argument syntax:
> --
> 2.34.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-02 1:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 8:30 [PATCH RESEND] tracing: uprobes: Fix incorrect __free function that frees an error value in __trace_uprobe_create() Ella Ma
2026-09-02 1:36 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox