From: Jakub Sitnicki <jakub@cloudflare.com>
To: Jason Xing <kerneljasonxing@gmail.com>
Cc: Stanislav Fomichev <sdf.kernel@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
kernel-team@cloudflare.com, Jakub Kicinski <kuba@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>
Subject: Re: [PATCH RFC net-next 3/6] bpf: Allow skb extensions to survive packet scrubbing
Date: Mon, 20 Jul 2026 13:39:01 +0200 [thread overview]
Message-ID: <875x2951re.fsf@cloudflare.com> (raw)
In-Reply-To: <CAL+tcoBPv2_yMZrrvgNT7kkL9tCmAfUZmsr7+0qYukRmYJb6gQ@mail.gmail.com> (Jason Xing's message of "Fri, 17 Jul 2026 19:30:12 +0200")
On Fri, Jul 17, 2026 at 07:30 PM +02, Jason Xing wrote:
> On Thu, Jul 16, 2026 at 5:06 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
>>
>> On Thu, Jul 16, 2026 at 3:00 PM Jakub Sitnicki <jakub@cloudflare.com> wrote:
>> >
>> > On Thu, Jul 16, 2026 at 05:11 AM -07, Stanislav Fomichev wrote:
>> > > On 07/14, Jakub Sitnicki wrote:
>> > >> skb_scrub_packet() drops all skb extensions unconditionally via
>> > >> skb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,
>> > >> vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).
>> > >>
>> > >> This makes it impossible for a BPF program to pass metadata via
>> > >> bpf_skb_ext through a tunnel or across a netns boundary. The extension
>> > >> is always lost at the scrub point.
>> > >>
>> > >> Introduce skb_ext_scrub() which consults each active extension before
>> > >> discarding it. Extensions that request preservation are kept while the
>> > >> rest are torn down. When the extension slab is shared with clones, COW
>> > >> ensures isolation. Replace the skb_ext_reset() call in
>> > >> skb_scrub_packet() with skb_ext_scrub().
>> > >>
>> > >> Expose the opt-in mechanism to BPF via the BPF_SKB_EXT_F_NO_SCRUB flag
>> > >> for bpf_dynptr_from_skb_ext(). A program that sets this flag when
>> > >> creating the extension signals that its metadata should survive
>> > >> scrubbing.
>> > >>
>> > >> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
>> > >> ---
>> > >> include/linux/bpf.h | 1 +
>> > >> include/linux/skbuff.h | 2 ++
>> > >> include/uapi/linux/bpf.h | 3 +-
>> > >> net/core/filter.c | 11 +++++--
>> > >> net/core/skbuff.c | 82 ++++++++++++++++++++++++++++++++++++++++++------
>> > >> net/ipv4/udp.c | 2 +-
>> > >> 6 files changed, 86 insertions(+), 15 deletions(-)
>> > >>
>> > >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>> > >> index 6b918a5b61bf..a46ca53c5b27 100644
>> > >> --- a/include/linux/bpf.h
>> > >> +++ b/include/linux/bpf.h
>> > >> @@ -4214,6 +4214,7 @@ static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 all
>> > >> #ifdef CONFIG_BPF_SKB_EXT
>> > >>
>> > >> struct bpf_skb_ext {
>> > >> + u64 flags;
>> > >> u8 buf[CONFIG_BPF_SKB_EXT_SIZE] __aligned(8);
>> > >> };
>> > >>
>> > >> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
>> > >> index 584d8440d352..66afa5489007 100644
>> > >> --- a/include/linux/skbuff.h
>> > >> +++ b/include/linux/skbuff.h
>> > >> @@ -5063,6 +5063,7 @@ void *__skb_ext_set(struct sk_buff *skb, enum skb_ext_id id,
>> > >> void *skb_ext_add(struct sk_buff *skb, enum skb_ext_id id);
>> > >> void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id);
>> > >> void __skb_ext_put(struct skb_ext *ext);
>> > >> +void skb_ext_scrub(struct sk_buff *skb);
>> > >>
>> > >> static inline void skb_ext_put(struct sk_buff *skb)
>> > >> {
>> > >> @@ -5132,6 +5133,7 @@ static inline bool skb_has_extensions(struct sk_buff *skb)
>> > >> static inline void __skb_ext_put(struct skb_ext *ext) {}
>> > >> static inline void skb_ext_put(struct sk_buff *skb) {}
>> > >> static inline void skb_ext_reset(struct sk_buff *skb) {}
>> > >> +static inline void skb_ext_scrub(struct sk_buff *skb) {}
>> > >> static inline void skb_ext_del(struct sk_buff *skb, int unused) {}
>> > >> static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {}
>> > >> static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {}
>> > >> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> > >> index 3eee4467422d..02da170205de 100644
>> > >> --- a/include/uapi/linux/bpf.h
>> > >> +++ b/include/uapi/linux/bpf.h
>> > >> @@ -7734,7 +7734,8 @@ struct bpf_insn_array_value {
>> > >>
>> > >> /* Flags to control bpf_dynptr_from_skb_ext() behavior. */
>> > >> enum {
>> > >> - BPF_SKB_EXT_F_CREATE = (1ULL << 0),
>> > >> + BPF_SKB_EXT_F_CREATE = (1ULL << 0),
>> > >> + BPF_SKB_EXT_F_NO_SCRUB = (1ULL << 1),
>> > >
>> > > Do I understand correctly that you do prefer the NO_SCRUB mode? Any reason
>> > > we need to have scrub mode? If it's all produced/consumed by bpf, maybe
>> > > we can just carry this data unconditionally instead of having a SCRUB/NO_SCRUB
>> > > option?
>
> After giving it more thought, I vote for only no_scrub mode because I
> don't see any reason why we still use scrub mode. But it's just my
> opinion.
>
> My question is if we in the future really need the scrub mode, it's
> still possible to add this option, right?
Sorry for the delayed response. Took some time off after the conference.
I will make the bpf skb ext contents survive skb scrubbing in v1.
It seems to suit everyone we've heard from and it is consistent with the
existing bpf_redirect_peer behavior wrt xdp/skb metadata.
next prev parent reply other threads:[~2026-07-20 11:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 17:48 [PATCH RFC net-next 0/6] skb extension for BPF metadata Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 1/6] bpf: Introduce per-packet metadata storage for BPF programs Jakub Sitnicki
2026-07-16 12:10 ` Stanislav Fomichev
2026-07-16 12:35 ` Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 2/6] bpf: Allow access to bpf_sock_ops_kern->skb Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 3/6] bpf: Allow skb extensions to survive packet scrubbing Jakub Sitnicki
2026-07-16 12:11 ` Stanislav Fomichev
2026-07-16 12:59 ` Jakub Sitnicki
2026-07-16 15:06 ` Jason Xing
2026-07-17 17:30 ` Jason Xing
2026-07-20 11:39 ` Jakub Sitnicki [this message]
2026-07-14 17:48 ` [PATCH RFC net-next 4/6] selftests/bpf: Add tests for bpf_dynptr_from_skb_ext Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 5/6] selftests/bpf: Test skb_ext scrubbing across tunnels and veths Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 6/6] selftests/bpf: Use non-trivial test payload in xdp_context tests 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=875x2951re.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=sdf.kernel@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