]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Make bpf_skb_vlan_push helper metadata-safe
authorJakub Sitnicki <jakub@cloudflare.com>
Wed, 5 Nov 2025 20:19:43 +0000 (21:19 +0100)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 10 Nov 2025 18:52:31 +0000 (10:52 -0800)
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>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20251105-skb-meta-rx-path-v4-6-5ceb08a9b37b@cloudflare.com
include/linux/if_vlan.h

index 4ecc2509b0d431d5bc92c41cadf0ef1d0ba45c83..f7f34eb15e068785e464303b60f2f050b3bec0ec 100644 (file)
@@ -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;