bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Pedro Tammela <pctammela@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Joe Stringer <joe@cilium.io>,
	Quentin Monnet <quentin@isovalent.com>,
	"open list:BPF (Safe dynamic programs and tools)" 
	<netdev@vger.kernel.org>,
	"open list:BPF (Safe dynamic programs and tools)" 
	<bpf@vger.kernel.org>, open list <linux-kernel@vger.kernel.org>,
	Pedro Tammela <pctammela@mojatatu.com>
Subject: Re: [PATCH bpf-next v2] bpf: check flags in 'bpf_ringbuf_discard()' and 'bpf_ringbuf_submit()'
Date: Sat, 3 Apr 2021 08:53:15 -0700	[thread overview]
Message-ID: <CAEf4BzYAcUsObPj_hm3tfC-d+EHfeeHLVDD4OigPg82hiehc7A@mail.gmail.com> (raw)
In-Reply-To: <CAKY_9u3VR+B=q0rPNYV1V9sr7+DG=T7786wQwMf1jrSxsKUgfw@mail.gmail.com>

On Sat, Apr 3, 2021 at 6:29 AM Pedro Tammela <pctammela@gmail.com> wrote:
>
> Em qua., 31 de mar. de 2021 às 04:02, Andrii Nakryiko
> <andrii.nakryiko@gmail.com> escreveu:
> >
> > On Tue, Mar 30, 2021 at 4:16 PM Alexei Starovoitov
> > <alexei.starovoitov@gmail.com> wrote:
> > >
> > > On Tue, Mar 30, 2021 at 3:54 PM Pedro Tammela <pctammela@gmail.com> wrote:
> > > >
> > > >  BPF_CALL_2(bpf_ringbuf_submit, void *, sample, u64, flags)
> > > >  {
> > > > +       if (unlikely(flags & ~(BPF_RB_NO_WAKEUP | BPF_RB_FORCE_WAKEUP)))
> > > > +               return -EINVAL;
> > > > +
> > > >         bpf_ringbuf_commit(sample, flags, false /* discard */);
> > > > +
> > > >         return 0;
> > >
> > > I think ringbuf design was meant for bpf_ringbuf_submit to never fail.
> > > If we do flag validation it probably should be done at the verifier time.
> >
> > Oops, replied on another version already. But yes, BPF verifier relies
> > on it succeeding. I don't think we can do flags validation at BPF
> > verification time, though, because it is defined as non-const integer
> > and we do have valid cases where we dynamically determine whether to
> > FORCE_WAKEUP or NO_WAKEUP, based on application-driven criteria (e.g.,
> > amount of enqueued data).
>
> Then shouldn't we remove the flags check in 'bpf_ringbuf_output()'?

bpf_ringbuf_output() combines reserve + commit operations, so if it
performs checks before anything is reserved in ringbuf, it's ok for it
to fail and return error. So I don't see any problem there. But once
it internally reserves, it always proceeds to complete the commit.

      reply	other threads:[~2021-04-03 15:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 22:37 [PATCH bpf-next v2] bpf: check flags in 'bpf_ringbuf_discard()' and 'bpf_ringbuf_submit()' Pedro Tammela
2021-03-30 23:07 ` Song Liu
2021-03-30 23:16 ` Alexei Starovoitov
2021-03-31  7:02   ` Andrii Nakryiko
2021-04-03 13:28     ` Pedro Tammela
2021-04-03 15:53       ` Andrii Nakryiko [this message]

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=CAEf4BzYAcUsObPj_hm3tfC-d+EHfeeHLVDD4OigPg82hiehc7A@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joe@cilium.io \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pctammela@gmail.com \
    --cc=pctammela@mojatatu.com \
    --cc=quentin@isovalent.com \
    --cc=songliubraving@fb.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;
as well as URLs for NNTP newsgroup(s).