From: Jakub Sitnicki <jakub@cloudflare.com>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, kernel-team@cloudflare.com
Subject: Re: [PATCH RFC bpf-next 5/9] bpf: Make bpf_skb_vlan_push helper metadata-safe
Date: Fri, 03 Oct 2025 14:03:48 +0200 [thread overview]
Message-ID: <87cy742nvf.fsf@cloudflare.com> (raw)
In-Reply-To: <20250929-skb-meta-rx-path-v1-5-de700a7ab1cb@cloudflare.com> (Jakub Sitnicki's message of "Mon, 29 Sep 2025 16:09:10 +0200")
On Mon, Sep 29, 2025 at 04:09 PM +02, Jakub Sitnicki wrote:
> Use the metadata-aware helper to move packet bytes after skb_push(),
> ensuring metadata remains valid after calling the BPF helper.
>
> Also, take care to reserve sufficient headroom for metadata to fit.
>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> ---
> include/linux/if_vlan.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
> index 4ecc2509b0d4..b0e1f57d51aa 100644
> --- a/include/linux/if_vlan.h
> +++ b/include/linux/if_vlan.h
> @@ -355,16 +355,17 @@ static inline int __vlan_insert_inner_tag(struct sk_buff *skb,
> __be16 vlan_proto, u16 vlan_tci,
> unsigned int mac_len)
> {
> + const u8 meta_len = mac_len > ETH_HLEN ? skb_metadata_len(skb) : 0;
This is a typo. Should be:
+ const u8 meta_len = mac_len > ETH_TLEN ? skb_metadata_len(skb) : 0;
^^^^^^^^
> struct vlan_ethhdr *veth;
>
> - if (skb_cow_head(skb, VLAN_HLEN) < 0)
> + if (skb_cow_head(skb, meta_len + VLAN_HLEN) < 0)
> return -ENOMEM;
>
> skb_push(skb, VLAN_HLEN);
>
> /* Move the mac header sans proto to the beginning of the new header. */
> if (likely(mac_len > ETH_TLEN))
> - memmove(skb->data, skb->data + VLAN_HLEN, mac_len - ETH_TLEN);
> + skb_postpush_data_move(skb, VLAN_HLEN, mac_len - ETH_TLEN);
> if (skb_mac_header_was_set(skb))
> skb->mac_header -= VLAN_HLEN;
next prev parent reply other threads:[~2025-10-03 12:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 14:09 [PATCH RFC bpf-next 0/9] Make TC BPF helpers preserve skb metadata Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 1/9] net: Preserve metadata on pskb_expand_head Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 2/9] net: Helper to move packet data and metadata after skb_push/pull Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 3/9] vlan: Make vlan_remove_tag return nothing Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 4/9] bpf: Make bpf_skb_vlan_pop helper metadata-safe Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 5/9] bpf: Make bpf_skb_vlan_push " Jakub Sitnicki
2025-10-03 12:03 ` Jakub Sitnicki [this message]
2025-09-29 14:09 ` [PATCH RFC bpf-next 6/9] bpf: Make bpf_skb_adjust_room metadata-safe Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 7/9] bpf: Make bpf_skb_change_proto helper metadata-safe Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 8/9] bpf: Make bpf_skb_change_head " Jakub Sitnicki
2025-09-29 14:09 ` [PATCH RFC bpf-next 9/9] selftests/bpf: Expect unclone to preserve metadata 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=87cy742nvf.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=netdev@vger.kernel.org \
/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).