mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-06 00:29:07 +08:00
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
This commit is contained in:
committed by
Andrii Nakryiko
parent
d22e0d8721
commit
05333afec1
11
src/libbpf.c
11
src/libbpf.c
@@ -12006,6 +12006,8 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
|
|||||||
ref_ctr_offsets = OPTS_GET(opts, ref_ctr_offsets, NULL);
|
ref_ctr_offsets = OPTS_GET(opts, ref_ctr_offsets, NULL);
|
||||||
cookies = OPTS_GET(opts, cookies, NULL);
|
cookies = OPTS_GET(opts, cookies, NULL);
|
||||||
cnt = OPTS_GET(opts, cnt, 0);
|
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:
|
* 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);
|
return libbpf_err_ptr(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (retprobe && session)
|
||||||
|
return libbpf_err_ptr(-EINVAL);
|
||||||
|
|
||||||
if (func_pattern) {
|
if (func_pattern) {
|
||||||
if (!strchr(path, '/')) {
|
if (!strchr(path, '/')) {
|
||||||
err = resolve_full_path(path, full_path, sizeof(full_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;
|
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;
|
attach_type = session ? BPF_TRACE_UPROBE_SESSION : BPF_TRACE_UPROBE_MULTI;
|
||||||
|
|
||||||
lopts.uprobe_multi.path = path;
|
lopts.uprobe_multi.path = path;
|
||||||
|
|||||||
Reference in New Issue
Block a user