bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: track contents of read-only maps as scalars
Date: Tue, 8 Oct 2019 16:41:50 -0700	[thread overview]
Message-ID: <CAEf4BzbeW-H1geNZ1EBvQrfhaG-FkWKNouLen3YCNEXzKEE4dg@mail.gmail.com> (raw)
In-Reply-To: <20191008212945.GG27307@pc-66.home>

On Tue, Oct 8, 2019 at 2:29 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On Tue, Oct 08, 2019 at 12:45:47PM -0700, Andrii Nakryiko wrote:
> > Maps that are read-only both from BPF program side and user space side
> > have their contents constant, so verifier can track referenced values
> > precisely and use that knowledge for dead code elimination, branch
> > pruning, etc. This patch teaches BPF verifier how to do this.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  kernel/bpf/verifier.c | 58 +++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 56 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index ffc3e53f5300..1e4e4bd64ca5 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -2739,6 +2739,42 @@ static void coerce_reg_to_size(struct bpf_reg_state *reg, int size)
> >       reg->smax_value = reg->umax_value;
> >  }
> >
> > +static bool bpf_map_is_rdonly(const struct bpf_map *map)
> > +{
> > +     return (map->map_flags & BPF_F_RDONLY_PROG) &&
> > +            ((map->map_flags & BPF_F_RDONLY) || map->frozen);
>
> This is definitely buggy. Testing for 'map->map_flags & BPF_F_RDONLY'
> to assume it's RO from user space side is not correct as it's just
> related to the current fd, but not the map itself. So the second part
> definitely /must/ only be: && map->frozen

Yep, you are right, map->frozen and BPF_F_RDONLY_PROG only.

>
> Thanks,
> Daniel

  reply	other threads:[~2019-10-08 23:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 19:45 [PATCH bpf-next 0/2] Track read-only map contents as known scalars in BPF verifiers Andrii Nakryiko
2019-10-08 19:45 ` [PATCH bpf-next 1/2] bpf: track contents of read-only maps as scalars Andrii Nakryiko
2019-10-08 21:29   ` Daniel Borkmann
2019-10-08 23:41     ` Andrii Nakryiko [this message]
2019-10-08 21:53   ` Martin Lau
2019-10-08 23:49     ` Andrii Nakryiko
2019-10-09  0:34       ` Martin Lau
2019-10-09  2:48         ` Andrii Nakryiko
2019-10-08 19:45 ` [PATCH bpf-next 2/2] selftests/bpf: add read-only map values propagation tests 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=CAEf4BzbeW-H1geNZ1EBvQrfhaG-FkWKNouLen3YCNEXzKEE4dg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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).