From: Eric Dumazet skb_unset_mac_header() marks the mac header as unset but leaves skb->mac_len alone, so an skb can end up with no mac header and a non-zero mac_len. Code that uses mac_len to decide whether a mac header is present is then misled. end_dt_vrf_rcv() (SRv6 End.DT4/End.DT6) unsets the mac header of the decapsulated packet so that the VRF device can rebuild it. The VRF device only does so when a packet sniffer is attached, so without one the skb continues up the stack with mac_len == 14. In xfrm4_remove_tunnel_encap() and xfrm6_remove_tunnel_encap(), skb_mac_header_rebuild() is a no-op for such an skb, and the following if (skb->mac_len) eth_hdr(skb)->h_proto = skb->protocol; writes two bytes at skb->head + 0xffff + offsetof(struct ethhdr, h_proto): BUG: KASAN: slab-out-of-bounds in xfrm4_remove_tunnel_encap+0x17d/0x220 Write of size 2 at addr ffff88805f85800b by task syz-executor/10831 xfrm4_remove_tunnel_encap xfrm_input xfrm4_esp_rcv ip_protocol_deliver_rcu ip_local_deliver_finish seg6_local_input_core lwtunnel_input __netif_receive_skb netif_receive_skb tun_rx_batched tun_get_user __input_process_payload() in net/xfrm/xfrm_iptfs.c has the same three lines and reported as a use-after-free rather than an out-of-bounds. The address written is fixed relative to skb->head, so what it lands in is whatever the allocator placed sixteen pages past the skb: a live object gives slab-out-of-bounds, a freed one or a page back on the buddy free list gives use-after-free, and a different live object gives no report at all. Clearing mac_len at the source makes the guard false at all three sites. Clear mac_len in skb_unset_mac_header() so that all callers leave the skb in a consistent state, and remove the now redundant assignment in skb_carve_reset_headers(). The other callers are on egress paths (__bpf_redirect_neigh(), bpf_lwt_push_ip_encap()) or only reach the helper when the mac header was already unset (bpf_update_srh_state()), and do not read mac_len afterwards. vrf_prepare_mac_header(), the rebuild end_dt_vrf_rcv() unsets the header for, pushes ETH_HLEN and then calls skb_reset_mac_header() and skb_reset_mac_len(), so it recomputes mac_len itself and never reads the stale value. The issue was reported on the list by Piyus Kedia and Kapil Vaswani, who found it by fuzzing with AI assistance and reproduced the KASAN splat on v7.4-rc3. Their reproducer was not published. Fixes: 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior") Reported-by: Piyus Kedia Reported-by: Kapil Vaswani Closes: https://lore.kernel.org/netdev/20261116174531.2540348-2-piyus@iiitd.ac.in/ Suggested-by: Kapil Vaswani Suggested-by: Piyus Kedia Tested-by: Piyus Kedia Signed-off-by: Eric Dumazet Signed-off-by: Piyus Kedia --- v3: use the generic fix Eric suggested - clear mac_len where it is left stale, instead of guarding each place that reads it. v1 and v2 added a skb_mac_header_was_set() test at each reader. Authorship is Eric's. v1: https://lore.kernel.org/r/20261116174531.2540348-2-piyus@iiitd.ac.in include/linux/skbuff.h | 1 + net/core/skbuff.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 6787fcf6ac3e..9cd8eff0309c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3186,6 +3186,7 @@ static inline u32 skb_mac_header_len(const struct sk_buff *skb) static inline void skb_unset_mac_header(struct sk_buff *skb) { skb->mac_header = (typeof(skb->mac_header))~0U; + skb->mac_len = 0; } static inline void skb_reset_mac_header(struct sk_buff *skb) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1ac1e327ac4c..8fe0938d6131 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6984,7 +6984,6 @@ static void skb_carve_reset_headers(struct sk_buff *skb) skb_unset_mac_header(skb); skb_unset_transport_header(skb); skb_reset_network_header(skb); - skb->mac_len = 0; /* Inner offsets have no "unset" marker, zero them so that * skb_inner_network_header_was_set() becomes false and no