Skip to content

Commit fab974e

Browse files
olsajirianakryiko
authored andcommitted
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. Reported-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241115115843.694337-1-jolsa@kernel.org
1 parent 96a30e4 commit fab974e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12006,6 +12006,8 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
1200612006
ref_ctr_offsets = OPTS_GET(opts, ref_ctr_offsets, NULL);
1200712007
cookies = OPTS_GET(opts, cookies, NULL);
1200812008
cnt = OPTS_GET(opts, cnt, 0);
12009+
retprobe = OPTS_GET(opts, retprobe, false);
12010+
session = OPTS_GET(opts, session, false);
1200912011

1201012012
/*
1201112013
* User can specify 2 mutually exclusive set of inputs:
@@ -12034,6 +12036,9 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
1203412036
return libbpf_err_ptr(-EINVAL);
1203512037
}
1203612038

12039+
if (retprobe && session)
12040+
return libbpf_err_ptr(-EINVAL);
12041+
1203712042
if (func_pattern) {
1203812043
if (!strchr(path, '/')) {
1203912044
err = resolve_full_path(path, full_path, sizeof(full_path));
@@ -12057,12 +12062,6 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
1205712062
offsets = resolved_offsets;
1205812063
}
1205912064

12060-
retprobe = OPTS_GET(opts, retprobe, false);
12061-
session = OPTS_GET(opts, session, false);
12062-
12063-
if (retprobe && session)
12064-
return libbpf_err_ptr(-EINVAL);
12065-
1206612065
attach_type = session ? BPF_TRACE_UPROBE_SESSION : BPF_TRACE_UPROBE_MULTI;
1206712066

1206812067
lopts.uprobe_multi.path = path;

0 commit comments

Comments
 (0)