mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: "Amery Hung" <ameryhung@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Nicholas Carlini" <npc@anthropic.com>, <bpf@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <kernel-team@meta.com>
Subject: Re: [PATCH bpf-next v2 00/11] bpf: Scope callback arguments to their frame
Date: Thu, 22 Oct 2026 04:46:35 +0000	[thread overview]
Message-ID: <DMB3EIGZSALV.3C9PAPO7TB923@gmail.com> (raw)
In-Reply-To: <d2369629-846e-4fd8-b567-a0fd8863256c@linux.dev>

On Tue, Oct 20, 2026 at 11:32 AM Ihor Solodrai <ihor.solodrai@linux.dev> wrote:
> Slices are not reached. A slice's parent_id is the dynptr id, and the
> walk from frame_id finds that id only while the dynptr is still in a
> register or a stack slot. R1 is caller-saved, so the bpf_dynptr_data()
> call that creates the slice usually clobbers it.
>
> This can be fixed in your diff with:
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index bc12df55d2e2..57859c3baeeb 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -11470,6 +11470,7 @@ void mark_frame_scoped_arg(struct bpf_verifier_env *env, struct bpf_func_state *
>  {
>  	if (!callee->frame_id)
>  		callee->frame_id = ++env->id_gen;
> +	callee->regs[regno].id = callee->frame_id;
>  	callee->regs[regno].parent_id = callee->frame_id;
>  }
>
> i.e. the reg is its own parent again.

got it. you're right. Let's take your one-liner.
I think the reg->id != id hunk can still stay out. The reg is
invalidated in the same pass, so the second pop of frame_id in
invalidate_reference() finds nothing and the loop ends.

> I don't quite understand the concern with the series as is.
> I'm guessing a new weird REF_TYPE in refs[] which is not an actual
> acquirable object gives an ick. Or is it the plumbing?
> I take it you agree that we need some kind of frame-tied lifetime
> tracking, right?

Yes, we need it. I guess it's the plumbing that bothers me a bit.
The id belongs to the frame, but refs[] is in bpf_verifier_state and
the callback runs in a pushed state. That's why setters had to move
out of setup_func_entry(), take a state argument and handle errors,
and why refsafe() and check_reference_leak() need REF_TYPE_FRAME
cases. A u32 in the frame needs none of that.

> I added some refactoring patches in attempt to avoid growing
> bpf_func_state vs v1 (Eduard mentioned we create a lot of these
> objects), and that is what you've just suggested.

Right, it grows. With padding that's 8 bytes on a 960 byte struct,
880 of which is regs[]. I feel it's cheaper than patches 1-3,
but I don't insist.

      reply	other threads:[~2026-10-22  4:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 20:27 Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 01/11] bpf: Set up callee state outside of setup_func_entry() Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 02/11] bpf: Pass the owning verifier state to callback setters Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 03/11] bpf: Append complete reference states Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 04/11] bpf: Separate reference removal from descendant invalidation Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 05/11] bpf: Share map-backed callback register setup Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 06/11] bpf: Rely on callback frame initialization defaults Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 07/11] bpf: Introduce REF_TYPE_FRAME in the verifier Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 08/11] bpf: Scope the bpf_user_ringbuf_drain() dynptr to its callback frame Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 09/11] selftests/bpf: Cover the user ringbuf callback dynptr lifetime Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 10/11] bpf: Scope the bpf_for_each_map_elem() array key to the callback frame Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 11/11] selftests/bpf: Cover callback-frame map key lifetime Ihor Solodrai
2026-10-16 16:42 ` [PATCH bpf-next v2 00/11] bpf: Scope callback arguments to their frame Alexei Starovoitov
2026-10-20 18:32   ` Ihor Solodrai
2026-10-22  4:46     ` Alexei Starovoitov [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=DMB3EIGZSALV.3C9PAPO7TB923@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=npc@anthropic.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®