Skip to contentSkip to conversation

libbpf: Fix memory leak in bpf_program__attach_uprobe_multi

PATCH Applied Jiri Olsa 2 participants 2 messages Nov 15, 2024

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 libbpf: Fix memory leak in bpf_program__attach_uprobe_multi

Andrii reported memory leak detected by Coverity on error path in bpf_program__attach_uprobe_multi. Fixing that by moving the check earlier before the offsets allocations.

---
 tools/lib/bpf/libbpf.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
tools/lib/bpf/libbpf.c +5 -6
index 07d5de81dd38..66173ddb5a2d 100644
@@ -12006,6 +12006,8 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
 	ref_ctr_offsets = OPTS_GET(opts, ref_ctr_offsets, NULL);
 	cookies = OPTS_GET(opts, cookies, NULL);
 	cnt = OPTS_GET(opts, cnt, 0);
+	retprobe = OPTS_GET(opts, retprobe, false);
+	session  = OPTS_GET(opts, session, false);
 
 	/*
 	 * User can specify 2 mutually exclusive set of inputs:
@@ -12034,6 +12036,9 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
 			return libbpf_err_ptr(-EINVAL);
 	}
 
+	if (retprobe && session)
+		return libbpf_err_ptr(-EINVAL);
+
 	if (func_pattern) {
 		if (!strchr(path, '/')) {
 			err = resolve_full_path(path, full_path, sizeof(full_path));
@@ -12057,12 +12062,6 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
 		offsets = resolved_offsets;
 	}
 
-	retprobe = OPTS_GET(opts, retprobe, false);
-	session  = OPTS_GET(opts, session, false);
-
-	if (retprobe && session)
-		return libbpf_err_ptr(-EINVAL);
-
 	attach_type = session ? BPF_TRACE_UPROBE_SESSION : BPF_TRACE_UPROBE_MULTI;
 
 	lopts.uprobe_multi.path = path;
Signature · 1 line
2.47.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

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

Quoted 8 lines · On Fri, 15 Nov 2024 12:58:43 +0100 you wrote:

Andrii reported memory leak detected by Coverity on error path in bpf_program__attach_uprobe_multi. Fixing that by moving the check earlier before the offsets allocations.

[...]

Here is the summary with links:
- [bpf-next] libbpf: Fix memory leak in bpf_program__attach_uprobe_multi

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

You are awesome, thank you!

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