netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Jakub Sitnicki <jakub@cloudflare.com>, bpf@vger.kernel.org
Cc: "Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Arthur Fabre" <arthur@arthurfabre.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Jesse Brandeburg" <jbrandeburg@cloudflare.com>,
	"Joanne Koong" <joannelkoong@gmail.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Toke Høiland-Jørgensen" <thoiland@redhat.com>,
	"Yan Zhai" <yan@cloudflare.com>,
	kernel-team@cloudflare.com, netdev@vger.kernel.org,
	"Stanislav Fomichev" <sdf@fomichev.me>
Subject: Re: [PATCH bpf-next v3 01/10] bpf: Add dynptr type for skb metadata
Date: Tue, 22 Jul 2025 11:46:24 -0700	[thread overview]
Message-ID: <83977f81df181ba05a6388f3f542ec027ff44189.camel@gmail.com> (raw)
In-Reply-To: <20250721-skb-metadata-thru-dynptr-v3-1-e92be5534174@cloudflare.com>

On Mon, 2025-07-21 at 12:52 +0200, Jakub Sitnicki wrote:
> Add a dynptr type, similar to skb dynptr, but for the skb metadata access.
> 
> The dynptr provides an alternative to __sk_buff->data_meta for accessing
> the custom metadata area allocated using the bpf_xdp_adjust_meta() helper.
> 
> More importantly, it abstracts away the fact where the storage for the
> custom metadata lives, which opens up the way to persist the metadata by
> relocating it as the skb travels through the network stack layers.
> 
> A notable difference between the skb and the skb_meta dynptr is that writes
> to the skb_meta dynptr don't invalidate either skb or skb_meta dynptr
> slices, since they cannot lead to a skb->head reallocation.
> 
> skb_meta dynptr ops are stubbed out and implemented by subsequent changes.
> 
> Only the program types which can access __sk_buff->data_meta today are
> allowed to create a dynptr for skb metadata at the moment. We need to
> modify the network stack to persist the metadata across layers before
> opening up access to other BPF hooks.
> 
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>


> @@ -2274,7 +2278,8 @@ static bool reg_is_pkt_pointer_any(const struct bpf_reg_state *reg)
>  static bool reg_is_dynptr_slice_pkt(const struct bpf_reg_state *reg)
>  {
>  	return base_type(reg->type) == PTR_TO_MEM &&
> -		(reg->type & DYNPTR_TYPE_SKB || reg->type & DYNPTR_TYPE_XDP);
> +	       (reg->type &
> +		(DYNPTR_TYPE_SKB | DYNPTR_TYPE_XDP | DYNPTR_TYPE_SKB_META));
>  }

Note: This function is used to identify pointers to packet data that
      might be stale after call to one of the functions in list [1].
      Once such pointers are identified, verifier would disallow
      access through these pointers.
      dynptr_from_skb_meta() is implemented as:

        bpf_dynptr_init(ptr, skb, BPF_DYNPTR_TYPE_SKB_META, 0, skb_metadata_len(skb));

      here any read or write goes through skb object, not a pointer derived from it.
      Given above, is it still necessary to list DYNPTR_FROM_SKB_META here?
      Or some functions from [1] can change skb_metadata_len(skb)?

[1] https://elixir.bootlin.com/linux/v6.15.7/source/net/core/filter.c#L7989

[...]

  reply	other threads:[~2025-07-22 18:46 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-21 10:52 [PATCH bpf-next v3 00/10] Add a dynptr type for skb metadata for TC BPF Jakub Sitnicki
2025-07-21 10:52 ` [PATCH bpf-next v3 01/10] bpf: Add dynptr type for skb metadata Jakub Sitnicki
2025-07-22 18:46   ` Eduard Zingerman [this message]
2025-07-22 19:10     ` Eduard Zingerman
2025-07-23  0:37   ` Martin KaFai Lau
2025-07-23  9:02     ` Jakub Sitnicki
2025-07-21 10:52 ` [PATCH bpf-next v3 02/10] bpf: Enable read access to skb metadata with bpf_dynptr_read Jakub Sitnicki
2025-07-22 18:49   ` Eduard Zingerman
2025-07-23 16:50     ` Jakub Sitnicki
2025-07-21 10:52 ` [PATCH bpf-next v3 03/10] bpf: Enable write access to skb metadata with bpf_dynptr_write Jakub Sitnicki
2025-07-21 10:52 ` [PATCH bpf-next v3 04/10] bpf: Enable read-write access to skb metadata with dynptr slice Jakub Sitnicki
2025-07-21 10:52 ` [PATCH bpf-next v3 05/10] selftests/bpf: Cover verifier checks for skb_meta dynptr type Jakub Sitnicki
2025-07-22 19:22   ` Eduard Zingerman
2025-07-21 10:52 ` [PATCH bpf-next v3 06/10] selftests/bpf: Pass just bpf_map to xdp_context_test helper Jakub Sitnicki
2025-07-22 20:24   ` Eduard Zingerman
2025-07-21 10:52 ` [PATCH bpf-next v3 07/10] selftests/bpf: Parametrize test_xdp_context_tuntap Jakub Sitnicki
2025-07-22 20:24   ` Eduard Zingerman
2025-07-21 10:52 ` [PATCH bpf-next v3 08/10] selftests/bpf: Cover read access to skb metadata via dynptr Jakub Sitnicki
2025-07-22 20:24   ` Eduard Zingerman
2025-07-21 10:52 ` [PATCH bpf-next v3 09/10] selftests/bpf: Cover write " Jakub Sitnicki
2025-07-22 20:25   ` Eduard Zingerman
2025-07-21 10:52 ` [PATCH bpf-next v3 10/10] selftests/bpf: Cover read/write to skb metadata at an offset Jakub Sitnicki
2025-07-22 20:26   ` Eduard Zingerman
2025-07-22 20:30   ` Eduard Zingerman
2025-07-23  9:09     ` Jakub Sitnicki

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=83977f81df181ba05a6388f3f542ec027ff44189.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=arthur@arthurfabre.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=jbrandeburg@cloudflare.com \
    --cc=joannelkoong@gmail.com \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=thoiland@redhat.com \
    --cc=yan@cloudflare.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).