mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Denis Kirjanov <kda@linux-powerpc.org>
Cc: xiakaixu1987@gmail.com, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Kaixu Xia <kaixuxia@tencent.com>
Subject: Re: [PATCH] bpf: Fix unsigned 'datasec_id' compared with zero in check_pseudo_btf_id
Date: Tue, 10 Nov 2020 10:42:53 -0800	[thread overview]
Message-ID: <CAEf4BzaSXd4FSM7v+HMobCSkuvATB5mZRZ6ZPzG4PzQ959jv4w@mail.gmail.com> (raw)
In-Reply-To: <CAOJe8K2tL5x-dESsV+PFq1Gii-yB=fJh7i-=E-FbrJeioo6pqA@mail.gmail.com>

On Tue, Nov 10, 2020 at 5:02 AM Denis Kirjanov <kda@linux-powerpc.org> wrote:
>
> On 11/10/20, xiakaixu1987@gmail.com <xiakaixu1987@gmail.com> wrote:
> > From: Kaixu Xia <kaixuxia@tencent.com>
> >
> > The unsigned variable datasec_id is assigned a return value from the call
> > to check_pseudo_btf_id(), which may return negative error code.
> >
> > Fixes coccicheck warning:
> >
> > ./kernel/bpf/verifier.c:9616:5-15: WARNING: Unsigned expression compared
> > with zero: datasec_id > 0
> >
> > Reported-by: Tosk Robot <tencent_os_robot@tencent.com>
> > Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> > ---
> >  kernel/bpf/verifier.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 6200519582a6..e9d8d4309bb4 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -9572,7 +9572,7 @@ static int check_pseudo_btf_id(struct bpf_verifier_env
> > *env,
> >                              struct bpf_insn *insn,
> >                              struct bpf_insn_aux_data *aux)
> >  {
> > -     u32 datasec_id, type, id = insn->imm;
> > +     s32 datasec_id, type, id = insn->imm;
>
> but the value is passed as u32 to btf_type_by_id()...
>
> btf_find_by_name_kind() returns s32

Right, valid range of BTF type IDs are >= 0 and (significantly) less
than INT_MAX. So s32 is used to signal valid BTF ID or negative error,
but all the APIs accepting BTF ID accept it as just u32.

>
>
> >       const struct btf_var_secinfo *vsi;
> >       const struct btf_type *datasec;
> >       const struct btf_type *t;
> > --
> > 2.20.0
> >
> >

  reply	other threads:[~2020-11-10 18:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 11:50 xiakaixu1987
2020-11-10 13:02 ` Denis Kirjanov
2020-11-10 18:42   ` Andrii Nakryiko [this message]
2020-11-10 18:41 ` Andrii Nakryiko

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=CAEf4BzaSXd4FSM7v+HMobCSkuvATB5mZRZ6ZPzG4PzQ959jv4w@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kaixuxia@tencent.com \
    --cc=kda@linux-powerpc.org \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=xiakaixu1987@gmail.com \
    --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

all inboxes | Powered by JetHome®