]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Make bpf_skb_change_proto helper metadata-safe
authorJakub Sitnicki <jakub@cloudflare.com>
Wed, 5 Nov 2025 20:19:45 +0000 (21:19 +0100)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 10 Nov 2025 18:52:32 +0000 (10:52 -0800)
bpf_skb_change_proto reuses the same headroom operations as
bpf_skb_adjust_room, already updated to handle metadata safely.

The remaining step is to ensure that there is sufficient headroom to
accommodate metadata on skb_push().

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-8-5ceb08a9b37b@cloudflare.com
net/core/filter.c

index 297f0ae9dc1fe5c939683c7707b649b8121beded..50775c01c4567b42f3b8e37f479c54b76869d2c0 100644 (file)
@@ -3326,10 +3326,11 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len)
 static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
 {
        const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr);
+       const u8 meta_len = skb_metadata_len(skb);
        u32 off = skb_mac_header_len(skb);
        int ret;
 
-       ret = skb_cow(skb, len_diff);
+       ret = skb_cow(skb, meta_len + len_diff);
        if (unlikely(ret < 0))
                return ret;