From: Jakub Sitnicki <jakub@cloudflare.com>
To: bpf@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Arthur Fabre <arthur@arthurfabre.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
netdev@vger.kernel.org, kernel-team@cloudflare.com
Subject: [PATCH bpf-next v4 06/16] bpf: Make bpf_skb_vlan_push helper metadata-safe
Date: Wed, 05 Nov 2025 21:19:43 +0100 [thread overview]
Message-ID: <20251105-skb-meta-rx-path-v4-6-5ceb08a9b37b@cloudflare.com> (raw)
In-Reply-To: <20251105-skb-meta-rx-path-v4-0-5ceb08a9b37b@cloudflare.com>
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..f7f34eb15e06 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_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;
--
2.43.0
next prev parent reply other threads:[~2025-11-05 20:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 20:19 [PATCH bpf-next v4 00/16] Make TC BPF helpers preserve skb metadata Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 01/16] net: Helper to move packet data and metadata after skb_push/pull Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 02/16] net: Preserve metadata on pskb_expand_head Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 03/16] bpf: Unclone skb head on bpf_dynptr_write to skb metadata Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 04/16] vlan: Make vlan_remove_tag return nothing Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 05/16] bpf: Make bpf_skb_vlan_pop helper metadata-safe Jakub Sitnicki
2025-11-05 20:19 ` Jakub Sitnicki [this message]
2025-11-05 20:19 ` [PATCH bpf-next v4 07/16] bpf: Make bpf_skb_adjust_room metadata-safe Jakub Sitnicki
2025-11-05 20:42 ` bot+bpf-ci
2025-11-10 12:17 ` Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 08/16] bpf: Make bpf_skb_change_proto helper metadata-safe Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 09/16] bpf: Make bpf_skb_change_head " Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 10/16] selftests/bpf: Verify skb metadata in BPF instead of userspace Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 11/16] selftests/bpf: Dump skb metadata on verification failure Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 12/16] selftests/bpf: Expect unclone to preserve skb metadata Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 13/16] selftests/bpf: Cover skb metadata access after vlan push/pop helper Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 14/16] selftests/bpf: Cover skb metadata access after bpf_skb_adjust_room Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 15/16] selftests/bpf: Cover skb metadata access after change_head/tail helper Jakub Sitnicki
2025-11-05 20:19 ` [PATCH bpf-next v4 16/16] selftests/bpf: Cover skb metadata access after bpf_skb_change_proto Jakub Sitnicki
2025-11-10 19:30 ` [PATCH bpf-next v4 00/16] Make TC BPF helpers preserve skb metadata patchwork-bot+netdevbpf
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=20251105-skb-meta-rx-path-v4-6-5ceb08a9b37b@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=andrii@kernel.org \
--cc=arthur@arthurfabre.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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).