linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Yonghong Song <yhs@fb.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	bpf@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: re: bpf: Implement minimal BPF perf link
Date: Tue, 17 Aug 2021 18:36:28 +0100	[thread overview]
Message-ID: <342670fc-948a-a76e-5a47-b3d44e3e3926@canonical.com> (raw)

Hi,

Static analysis with Coverity on linux-next has detected a potential
issue with the following commit:

commit b89fbfbb854c9afc3047e8273cc3a694650b802e
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Sun Aug 15 00:05:57 2021 -0700

    bpf: Implement minimal BPF perf link

The analysis is as follows:

2936 static int bpf_perf_link_attach(const union bpf_attr *attr, struct
bpf_prog *prog)
2937 {

    1. var_decl: Declaring variable link_primer without initializer.

2938        struct bpf_link_primer link_primer;
2939        struct bpf_perf_link *link;
2940        struct perf_event *event;
2941        struct file *perf_file;
2942        int err;
2943

    2. Condition attr->link_create.flags, taking false branch.

2944        if (attr->link_create.flags)
2945                return -EINVAL;
2946
2947        perf_file = perf_event_get(attr->link_create.target_fd);

    3. Condition IS_ERR(perf_file), taking false branch.

2948        if (IS_ERR(perf_file))
2949                return PTR_ERR(perf_file);
2950
2951        link = kzalloc(sizeof(*link), GFP_USER);

    4. Condition !link, taking false branch.

2952        if (!link) {
2953                err = -ENOMEM;
2954                goto out_put_file;
2955        }
2956        bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT,
&bpf_perf_link_lops, prog);
2957        link->perf_file = perf_file;
2958
2959        err = bpf_link_prime(&link->link, &link_primer);

    5. Condition err, taking false branch.

2960        if (err) {
2961                kfree(link);
2962                goto out_put_file;
2963        }
2964
2965        event = perf_file->private_data;
2966        err = perf_event_set_bpf_prog(event, prog,
attr->link_create.perf_event.bpf_cookie);

    6. Condition err, taking true branch.
2967        if (err) {
    7. uninit_use_in_call: Using uninitialized value link_primer.fd when
calling bpf_link_cleanup.
    8. uninit_use_in_call: Using uninitialized value link_primer.file
when calling bpf_link_cleanup.
    9. uninit_use_in_call: Using uninitialized value link_primer.id when
calling bpf_link_cleanup.

   Uninitialized pointer read (UNINIT)
   10. uninit_use_in_call: Using uninitialized value link_primer.link
when calling bpf_link_cleanup.

2968                bpf_link_cleanup(&link_primer);
2969                goto out_put_file;
2970        }
2971        /* perf_event_set_bpf_prog() doesn't take its own refcnt on
prog */
2972        bpf_prog_inc(prog);

I'm not 100% sure if these are false-positives, but I thought I should
report the issues as potentially there is a pointer access on an
uninitialized pointer on line 2968.

Colin

             reply	other threads:[~2021-08-17 17:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 17:36 Colin Ian King [this message]
2021-08-17 18:57 ` bpf: Implement minimal BPF perf link Andrii Nakryiko
2021-08-17 20:34   ` Colin Ian King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=342670fc-948a-a76e-5a47-b3d44e3e3926@canonical.com \
    --to=colin.king@canonical.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).