Skip to contentSkip to conversation

libbpf: fix memory leak in attach_tp for target-less tracepoint program

PATCH Applied Andrii Nakryiko 3 participants 3 messages May 16, 2022

Subsystems (2)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: fix memory leak in attach_tp for target-less tracepoint program

Fix sec_name memory leak if user defines target-less SEC("tp").

Fixes 9af8efc45eb1 ("libbpf: Allow "incomplete" basic tracing SEC() definitions")
---
 tools/lib/bpf/libbpf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/lib/bpf/libbpf.c +4 -4
index 9aae886cbabf..ef7f302e542f 100644
@@ -11592,16 +11592,16 @@ static int attach_tp(const struct bpf_program *prog, long cookie, struct bpf_lin
 {
 	char *sec_name, *tp_cat, *tp_name;
 
-	sec_name = strdup(prog->sec_name);
-	if (!sec_name)
-		return -ENOMEM;
-
 	*link = NULL;
 
 	/* no auto-attach for SEC("tp") or SEC("tracepoint") */
 	if (strcmp(prog->sec_name, "tp") == 0 || strcmp(prog->sec_name, "tracepoint") == 0)
 		return 0;
 
+	sec_name = strdup(prog->sec_name);
+	if (!sec_name)
+		return -ENOMEM;
+
 	/* extract "tp/<category>/<name>" or "tracepoint/<category>/<name>" */
 	if (str_has_pfx(prog->sec_name, "tp/"))
 		tp_cat = sec_name + sizeof("tp/") - 1;
Signature · 1 line
2.30.2
#2 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 7 lines · On Mon, 16 May 2022 11:45:47 -0700 you wrote:

Fix sec_name memory leak if user defines target-less SEC("tp").

Fixes 9af8efc45eb1 ("libbpf: Allow "incomplete" basic tracing SEC() definitions")
---
 tools/lib/bpf/libbpf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Here is the summary with links:
- [bpf-next] libbpf: fix memory leak in attach_tp for target-less tracepoint program

    https://git.kernel.org/bpf/bpf-next/c/ac6a65868a5a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html