]> Git Repo - J-linux.git/commitdiff
libbpf: Fix memory leak in bpf_program__attach_uprobe_multi
authorJiri Olsa <[email protected]>
Fri, 15 Nov 2024 11:58:43 +0000 (12:58 +0100)
committerAndrii Nakryiko <[email protected]>
Fri, 15 Nov 2024 19:29:12 +0000 (11:29 -0800)
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 <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
tools/lib/bpf/libbpf.c

index 07d5de81dd38f334ee220d89978ab545757d8543..66173ddb5a2df3ebe181f17ed299f9ebc5c78eb5 100644 (file)
@@ -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;
This page took 0.068061 seconds and 4 git commands to generate.