seg6: Fix unset mac header in SRv6 End.DT VRF decapsulation
Subsystems (3)
PATCH v2 1/1 seg6: Fix unset mac header in SRv6 End.DT VRF decapsulation
SRv6 End.DT4/End.DT6 VRF decapsulation unsets the mac header in end_dt_vrf_rcv() so that the VRF device can rebuild it for packet sniffers. The VRF rx handler only performs the rebuild when a sniffer is actually attached to the VRF device (ptype_all non-empty); otherwise the packet continues up the stack with mac_header == 0xffff.
Every other receive path delivers packets with a valid mac header:
NIC drivers set it in eth_type_trans(), and tunnels without an L2 header (ipip, sit, gre, tun) reset it to the network header after decapsulation. skb_mac_header() even warns on the unset state with DEBUG_NET_WARN_ON_ONCE().
If the decapsulated packet is an unexpected UDP GSO packet, udp_queue_rcv_skb() re-segments it after restoring skb->data to the mac header with __skb_push(skb, -skb_mac_offset(skb)). With the mac header unset, skb_mac_offset() returns a large positive value, which the unsigned __skb_push() argument turns into a huge length:skb->data moves far outside the buffer and skb->len is corrupted, so segmentation reads out of bounds:
BUG: KASAN: slab-out-of-bounds in inet_gso_segment (net/ipv4/af_inet.c:1383)
Read of size 1 at addr ffff88800da7ffff by task exploit/149
Call Trace:
inet_gso_segment (net/ipv4/af_inet.c:1383)
skb_mac_gso_segment (net/core/gso.c:53)
__skb_gso_segment (net/core/gso.c:124)
udp_queue_rcv_skb (net/ipv4/udp.c:2476 net/ipv4/udp.c:2466)
udp_unicast_rcv_skb (net/ipv4/udp.c:2620)
ip_local_deliver (net/ipv4/ip_input.c:262)
seg6_local_input_core (net/ipv6/seg6_local.c:1640)
lwtunnel_input (net/core/lwtunnel.c:465)
ipv6_rcv (net/ipv6/ip6_input.c:351)Restore a valid mac header, pointing at the network header, once the VRF rx handler returns. The sniffer rebuild happens inside the handler while the header is still unset, so tap behavior is unchanged; when no rebuild happened, the packet now carries the same mac header state as any packet received on an L3 device.
---
v2:
- Move the fix from the UDP GSO path to seg6local.
- Restore the mac header after the VRF rx handler returns, preserving the VRF sniffer behavior.
- Verify the original reproducer, datagram delivery, and VRF sniffer output under QEMU.
v1: https://lore.kernel.org/netdev/[email protected]/
net/ipv6/seg6_local.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/ipv6/seg6_local.c +8 -0
@@ -1113,6 +1113,14 @@ static struct sk_buff *end_dt_vrf_rcv(struct sk_buff *skb, u16 family,/* the skb buffer was consumed by the handler */ return NULL ; +/* the VRF device had its chance to rebuild the mac header for +* sniffers; restore a valid one pointing at the network header, +* like any L3 device without an L2 header, before the packet +* continues up the stack. +*/ +if (!skb_mac_header_was_set (skb)) +skb_reset_mac_header (skb); +/* when a packet is received by a VRF or by one of its slaves, the * master device reference is set into the skb. */
Signature · 1 line
2.43.0
Quoted 44 lines · Boyan Liu
SRv6 End.DT4/End.DT6 VRF decapsulation unsets the mac header in
end_dt_vrf_rcv()so that the VRF device can rebuild it for packet sniffers. The VRF rx handler only performs the rebuild when a sniffer is actually attached to the VRF device (ptype_allnon-empty); otherwise the packet continues up the stack withmac_header==0xffff.Every other receive path delivers packets with a valid mac header:
NIC drivers set it ineth_type_trans(), and tunnels without an L2 header (ipip, sit, gre, tun) reset it to the network header after decapsulation.skb_mac_header()even warns on the unset state withDEBUG_NET_WARN_ON_ONCE().If the decapsulated packet is an unexpected UDP GSO packet,
udp_queue_rcv_skb()re-segments it after restoringskb->datato the mac header with__skb_push(skb, -skb_mac_offset(skb)). With the mac header unset,skb_mac_offset()returns a large positive value, which the unsigned__skb_push()argument turns into a huge length:skb->datamoves far outside the buffer andskb->lenis corrupted, so segmentation reads out of bounds:BUG: KASAN: slab-out-of-bounds in inet_gso_segment (net/ipv4/af_inet.c:1383) Read of size 1 at addr ffff88800da7ffff by task exploit/149 Call Trace: inet_gso_segment (net/ipv4/af_inet.c:1383) skb_mac_gso_segment (net/core/gso.c:53) __skb_gso_segment (net/core/gso.c:124) udp_queue_rcv_skb (net/ipv4/udp.c:2476 net/ipv4/udp.c:2466) udp_unicast_rcv_skb (net/ipv4/udp.c:2620) ip_local_deliver (net/ipv4/ip_input.c:262) seg6_local_input_core (net/ipv6/seg6_local.c:1640) lwtunnel_input (net/core/lwtunnel.c:465) ipv6_rcv (net/ipv6/ip6_input.c:351)Restore a valid mac header, pointing at the network header, once the VRF rx handler returns. The sniffer rebuild happens inside the handler while the header is still unset, so tap behavior is unchanged; when no rebuild happened, the packet now carries the same mac header state as any packet received on an L3 device.
Fixes 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior")Reported-by [email protected]Signed-off-by Boyan Liu <[email protected]>
Quoted 8 lines
---
v2:
- Move the fix from the UDP GSO path to seg6local.
- Restore the mac header after the VRF rx handler returns, preserving the VRF sniffer behavior.
- Verify the original reproducer, datagram delivery, and VRF sniffer output under QEMU.
v1: https://lore.kernel.org/netdev/[email protected]/
Thanks. As discussed in v1, this sounds the better approach to me too. But it would be better to get the opinion of experts on VRF and SRv6.
Thanks, Willem.
Andrea, David Ahern, could you share your thoughts on the v2 approach? In particular, does restoring the mac header after l3mdev_l3_rcv() returns properly fix the issue without introducing any regressions, especially in the VRF sniffer path?
Thanks,
Boyan
Quoted 57 lines · Willem de Bruijn <[email protected]> 于2026年10月17日周六 23:57写道:
Quoted 44 lines · Boyan Liu
SRv6 End.DT4/End.DT6 VRF decapsulation unsets the mac header in
end_dt_vrf_rcv()so that the VRF device can rebuild it for packet sniffers. The VRF rx handler only performs the rebuild when a sniffer is actually attached to the VRF device (ptype_allnon-empty); otherwise the packet continues up the stack withmac_header==0xffff.Every other receive path delivers packets with a valid mac header:
NIC drivers set it ineth_type_trans(), and tunnels without an L2 header (ipip, sit, gre, tun) reset it to the network header after decapsulation.skb_mac_header()even warns on the unset state withDEBUG_NET_WARN_ON_ONCE().If the decapsulated packet is an unexpected UDP GSO packet,
udp_queue_rcv_skb()re-segments it after restoringskb->datato the mac header with__skb_push(skb, -skb_mac_offset(skb)). With the mac header unset,skb_mac_offset()returns a large positive value, which the unsigned__skb_push()argument turns into a huge length:skb->datamoves far outside the buffer andskb->lenis corrupted, so segmentation reads out of bounds:BUG: KASAN: slab-out-of-bounds in inet_gso_segment (net/ipv4/af_inet.c:1383) Read of size 1 at addr ffff88800da7ffff by task exploit/149 Call Trace: inet_gso_segment (net/ipv4/af_inet.c:1383) skb_mac_gso_segment (net/core/gso.c:53) __skb_gso_segment (net/core/gso.c:124) udp_queue_rcv_skb (net/ipv4/udp.c:2476 net/ipv4/udp.c:2466) udp_unicast_rcv_skb (net/ipv4/udp.c:2620) ip_local_deliver (net/ipv4/ip_input.c:262) seg6_local_input_core (net/ipv6/seg6_local.c:1640) lwtunnel_input (net/core/lwtunnel.c:465) ipv6_rcv (net/ipv6/ip6_input.c:351)Restore a valid mac header, pointing at the network header, once the VRF rx handler returns. The sniffer rebuild happens inside the handler while the header is still unset, so tap behavior is unchanged; when no rebuild happened, the packet now carries the same mac header state as any packet received on an L3 device.
Fixes 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior")Reported-by [email protected]Signed-off-by Boyan Liu <[email protected]>Quoted 8 lines
---
v2:
- Move the fix from the UDP GSO path to seg6local.
- Restore the mac header after the VRF rx handler returns, preserving the VRF sniffer behavior.
- Verify the original reproducer, datagram delivery, and VRF sniffer output under QEMU.
v1: https://lore.kernel.org/netdev/[email protected]/Thanks. As discussed in v1, this sounds the better approach to me too. But it would be better to get the opinion of experts on VRF and SRv6.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In end_dt_vrf_rcv() (net/ipv6/seg6_local.c), the new code restores only skb->mac_header.
--
seg6: Fix unset mac header in SRv6 End.DT VRF decapsulation
After the VRF rx handler returns, this patch makes end_dt_vrf_rcv() restore a valid mac header that points at the network header. It only does this when the VRF has not rebuilt one for sniffers. This fixes an out of bounds read during UDP GSO re-segmentation: skb_mac_offset() on an unset mac header gave a huge __skb_push() length.
Quoted 5 lines
net/ipv6/seg6_local.c +0
-0
net/ipv6/seg6_local.c static struct sk_buff *end_dt_vrf_rcv(struct sk_buff *skb, u16 family, · line 1209
Quoted 10 lines
net/ipv6/seg6_local.c +7
-0@@ -1200,6 +1200,14 @@ static struct sk_buff *end_dt_vrf_rcv(struct sk_buff *skb, u16 family,/* the skb buffer was consumed by the handler */ return NULL ; +/* the VRF device had its chance to rebuild the mac header for +* sniffers; restore a valid one pointing at the network header, +* like any L3 device without an L2 header, before the packet +* continues up the stack. +*/ +if (!skb_mac_header_was_set (skb)) +skb_reset_mac_header (skb);
[Severity: Medium]
Should this also call skb_reset_mac_len()?
As far as I can tell, skb->mac_len still holds the outer frame's L2 length at this point. On Ethernet ingress, __netif_receive_skb_core() set it to ETH_HLEN for the outer SRv6 packet. decap_and_validate() only resets the network and transport headers:
skb_reset_network_header(skb);
skb_reset_transport_header(skb);On the VRF side, mac_len is only fixed in vrf_prepare_mac_header(), which always does both resets together:
drivers/net/vrf.c:vrf_prepare_mac_header() {
...
skb_reset_mac_header(skb);
skb_reset_mac_len(skb);
...
}That helper only runs when a sniffer is attached to the VRF (!list_empty(&vrf_dev->ptype_all)). It is also skipped on the IPv4 multicast, PACKET_LOOPBACK and IPv6 strict/link-local paths.
Without a sniffer, the packet leaves end_dt_vrf_rcv() with mac_header equal to network_header but mac_len still 14. It then goes through ip_route_input() / ip6_route_input() and dst_input(). It never passes through __netif_receive_skb_core() again, so mac_len is never recomputed.
skb_mac_header_was_set() now returns true, so helpers that rebuild an L2 header from mac_len use the stale value. For example, in xfrm4_remove_tunnel_encap() and xfrm6_remove_tunnel_encap():
skb_reset_network_header(skb); skb_mac_header_rebuild(skb); if (skb->mac_len) eth_hdr(skb)->h_proto = skb->protocol;
Would this copy 14 bytes of the ESP packet's outer IP header into a fake Ethernet header and then write h_proto into it? The skb is then re-injected via gro_cells/netif_rx, where GRO and taps can see that header. The BEET and iptfs rebuild paths look similar.
Also, seg6_do_srh() used to reject these skbs for L2ENCAP and L2ENCAP_RED:
case SEG6_IPTUN_MODE_L2ENCAP: case SEG6_IPTUN_MODE_L2ENCAP_RED: if (!skb_mac_header_was_set(skb)) return -EINVAL; if (pskb_expand_head(skb, skb->mac_len, 0, GFP_ATOMIC) < 0) return -ENOMEM; skb_mac_header_rebuild(skb); skb_push(skb, skb->mac_len);
That check now passes. Would 14 bytes of the inner IP header then be pushed as the destination MAC, source MAC and ethertype, and the result encapsulated and transmitted? The __seg6_do_srh_encap() and inline encap paths look like they build a fake L2 header in the headroom the same way.
I didn't find an out-of-bounds access from this, because the stripped outer headers leave enough headroom. Before this patch, the xfrm path wrote h_proto at head + 0xffff + 12, so the patch does remove that write.
The UDP GSO crash from the changelog is also fixed, because __skb_gso_segment() resets both mac_header and mac_len before calling skb_mac_gso_segment().
The new comment doesn't seem to hold, and neither does this part of the commit message:
when no rebuild happened, the packet now carries the same mac header state as any packet received on an L3 device.
A packet received on an L3 device has mac_len == 0. Would doing both resets, the way vrf_prepare_mac_header() does, make the code match the description?
if (!skb_mac_header_was_set(skb)) {
skb_reset_mac_header(skb);
skb_reset_mac_len(skb);
}Quoted 4 lines
net/ipv6/seg6_local.c +1
-0+/* when a packet is received by a VRF or by one of its slaves, the * master device reference is set into the skb. */
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017120144.3059-1-yymhvert%40gmail.com
Andrea Mayer
maintainerQuoted 34 lines · On Sat, 17 Oct 2026 20:01:44 +0800 Boyan Liu <[email protected]> wrote:
SRv6 End.DT4/End.DT6 VRF decapsulation unsets the mac header in
end_dt_vrf_rcv()so that the VRF device can rebuild it for packet sniffers. The VRF rx handler only performs the rebuild when a sniffer is actually attached to the VRF device (ptype_allnon-empty); otherwise the packet continues up the stack withmac_header==0xffff.Every other receive path delivers packets with a valid mac header:
NIC drivers set it ineth_type_trans(), and tunnels without an L2 header (ipip, sit, gre, tun) reset it to the network header after decapsulation.skb_mac_header()even warns on the unset state withDEBUG_NET_WARN_ON_ONCE().If the decapsulated packet is an unexpected UDP GSO packet,
udp_queue_rcv_skb()re-segments it after restoringskb->datato the mac header with__skb_push(skb, -skb_mac_offset(skb)). With the mac header unset,skb_mac_offset()returns a large positive value, which the unsigned__skb_push()argument turns into a huge length:skb->datamoves far outside the buffer andskb->lenis corrupted, so segmentation reads out of bounds:BUG: KASAN: slab-out-of-bounds in inet_gso_segment (net/ipv4/af_inet.c:1383) Read of size 1 at addr ffff88800da7ffff by task exploit/149 Call Trace: inet_gso_segment (net/ipv4/af_inet.c:1383) skb_mac_gso_segment (net/core/gso.c:53) __skb_gso_segment (net/core/gso.c:124) udp_queue_rcv_skb (net/ipv4/udp.c:2476 net/ipv4/udp.c:2466) udp_unicast_rcv_skb (net/ipv4/udp.c:2620) ip_local_deliver (net/ipv4/ip_input.c:262) seg6_local_input_core (net/ipv6/seg6_local.c:1640) lwtunnel_input (net/core/lwtunnel.c:465) ipv6_rcv (net/ipv6/ip6_input.c:351)
Quoted 5 lines
Restore a valid mac header, pointing at the network header, once the VRF rx handler returns. The sniffer rebuild happens inside the handler while the header is still unset, so tap behavior is unchanged; when no rebuild happened, the packet now carries the same mac header state as any packet received on an L3 device.
Thanks Boyan. On the SRv6 side the approach looks reasonable to me. With my own reproducer I see a KASAN slab-out-of-bounds in inet_gso_segment() without the fix. With the fix I could not reproduce it anymore, and the datagrams are delivered. A sniffer on the VRF sees the same L2 header with and without the fix.
Quoted 10 lines
[snip]
net/ipv6/seg6_local.c +1
-0@@ -1113,6 +1113,14 @@ static struct sk_buff *end_dt_vrf_rcv(struct sk_buff *skb, u16 family,/* the skb buffer was consumed by the handler */ return NULL ; +/* the VRF device had its chance to rebuild the mac header for
net/ipv6/seg6_local.c static struct sk_buff *end_dt_vrf_rcv(struct sk_buff *skb, u16 family, · line 1126
Quoted 10 lines
net/ipv6/seg6_local.c +7
-0+* sniffers; restore a valid one pointing at the network header, +* like any L3 device without an L2 header, before the packet +* continues up the stack. +*/ +if (!skb_mac_header_was_set (skb)) +skb_reset_mac_header (skb); +/* when a packet is received by a VRF or by one of its slaves, the * master device reference is set into the skb. */
The patch sets the mac header but not skb->mac_len, which stays at the value the ingress left (e.g. 14). IMO the patch should also reset skb->mac_len with skb_reset_mac_len(), which gives 0 with the mac header at the network header. Sashiko raised the same point.
Sashiko also asks about L2ENCAP. With the fix, the decapsulated packets now pass the skb_mac_header_was_set() check in seg6_do_srh() when the VRF has no sniffer. In my tests L2ENCAP then builds a malformed frame. skb_mac_header_was_set() only means the mac header is set, not that a real L2 header is present, and the L2 ends up rebuilt from the IP header bytes. Resetting mac_len does not make the frame valid either, since the IP header itself then sits where the L2 header should be. skb_mac_header_was_set() already lets End.DX4 packets into L2ENCAP without the fix, and the resulting frame is malformed as well. I will look at the L2ENCAP check separately.
Ciao,
Andrea