BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, kkd@meta.com,
	Alexei Starovoitov <ast@kernel.org>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau	 <martin.lau@kernel.org>,
	kernel-team@fb.com
Subject: Re: [PATCH bpf-next v3 4/7] bpf: Introduce support for bpf_local_irq_{save,restore}
Date: Wed, 27 Nov 2024 23:26:53 -0800	[thread overview]
Message-ID: <3587e5033070486ac4351f7be2a5f4428fd7a633.camel@gmail.com> (raw)
In-Reply-To: <CAP01T75nGn+sXDoa6N8yj_prtaYZemdCZtm_sNOzE7KvZzzpOQ@mail.gmail.com>

On Thu, 2024-11-28 at 05:39 +0100, Kumar Kartikeya Dwivedi wrote:

[...]

> > > +static bool is_irq_flag_reg_valid_uninit(struct bpf_verifier_env *env, struct bpf_reg_state *reg)
> > > +{
> > > +     struct bpf_func_state *state = func(env, reg);
> > > +     struct bpf_stack_state *slot;
> > > +     int spi, i;
> > > +
> > > +     /* For -ERANGE (i.e. spi not falling into allocated stack slots), we
> > > +      * will do check_mem_access to check and update stack bounds later, so
> > > +      * return true for that case.
> > > +      */
> > > +     spi = irq_flag_get_spi(env, reg);
> > > +     if (spi == -ERANGE)
> > > +             return true;
> > 
> > Nit: is it possible to swap is_irq_flag_reg_valid_uninit() and
> >      check_mem_access(), so that ERANGE special case would be not needed?
> > 
> 
> I don't think so. For dynptr, iter, irq, ERANGE indicates stack needs
> to be grown, so check_mem_access will naturally do that when writing.
> When not ERANGE, we need to catch cases where we have a bad slot_type.
> If we overwrote it with check_mem_access, then it would scrub the slot
> type as well.
> 
> When I fixed this stuff for dynptr, we had to additionally
> destroy_if_dynptr_stack_slot because it wasn't required to 'release' a
> dynptr when overwriting it.
> Andrii made sure this was necessary for iters so now slot_type ==
> STACK_ITER is just rejected instead of overwrite without a destroy
> operation.
> Similar idea is followed for irq flag.
> 
> Just paging in context for all this, but I may be missing if you have
> something in mind.

I see, makes sense. And is_dynptr_reg_valid_uninit() has the same check.
Thank you for explaining.

> > > +     if (spi < 0)
> > > +             return false;
> > > +
> > > +     slot = &state->stack[spi];
> > > +
> > > +     for (i = 0; i < BPF_REG_SIZE; i++)
> > > +             if (slot->slot_type[i] == STACK_IRQ_FLAG)
> > > +                     return false;
> > > +     return true;
> > > +}
> > 
> > [...]
> > 



  reply	other threads:[~2024-11-28  7:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-27 16:58 [PATCH bpf-next v3 0/7] IRQ save/restore Kumar Kartikeya Dwivedi
2024-11-27 16:58 ` [PATCH bpf-next v3 1/7] bpf: Consolidate locks and reference state in verifier state Kumar Kartikeya Dwivedi
2024-11-28  2:39   ` Eduard Zingerman
2024-11-28  2:54     ` Kumar Kartikeya Dwivedi
2024-11-28  3:03       ` Eduard Zingerman
2024-11-28  3:18         ` Kumar Kartikeya Dwivedi
2024-11-28  3:22           ` Eduard Zingerman
2024-11-28  3:32             ` Kumar Kartikeya Dwivedi
2024-11-27 16:58 ` [PATCH bpf-next v3 2/7] bpf: Refactor {acquire,release}_reference_state Kumar Kartikeya Dwivedi
2024-11-28  4:13   ` Eduard Zingerman
2024-11-28  4:30     ` Kumar Kartikeya Dwivedi
2024-11-28  4:36       ` Eduard Zingerman
2024-11-27 16:58 ` [PATCH bpf-next v3 3/7] bpf: Refactor mark_{dynptr,iter}_read Kumar Kartikeya Dwivedi
2024-11-27 16:58 ` [PATCH bpf-next v3 4/7] bpf: Introduce support for bpf_local_irq_{save,restore} Kumar Kartikeya Dwivedi
2024-11-28  4:31   ` Eduard Zingerman
2024-11-28  4:39     ` Kumar Kartikeya Dwivedi
2024-11-28  7:26       ` Eduard Zingerman [this message]
2024-11-27 16:58 ` [PATCH bpf-next v3 5/7] bpf: Improve verifier log for resource leak on exit Kumar Kartikeya Dwivedi
2024-11-28  4:34   ` Eduard Zingerman
2024-11-27 16:58 ` [PATCH bpf-next v3 6/7] selftests/bpf: Expand coverage of preempt tests to sleepable kfunc Kumar Kartikeya Dwivedi
2024-11-27 16:58 ` [PATCH bpf-next v3 7/7] selftests/bpf: Add IRQ save/restore tests Kumar Kartikeya Dwivedi

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=3587e5033070486ac4351f7be2a5f4428fd7a633.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.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