Fix wrong transport_header when sending VLAN-tagged frames
Subsystems (6)
v2 cover Fix wrong transport_header when sending VLAN-tagged frames
From: Wei Fang <[email protected]>
When sending a VLAN-tagged frame via AF_PACKET or tap, calling skb_set_network_header() before skb_probe_transport_header() causes the flow dissector to misinterpret the inner protocol header as a VLAN header. As a result, transport_header is never set and remains at its uninitialized sentinel value (~0U).
Move skb_probe_transport_header() to before skb_set_network_header() so the flow dissector sees network_header still pointing to the VLAN header and can correctly identify the transport layer.
---
v2 changes:
1. Move skb_probe_transport_header() to before skb_set_network_header()
2. Change the commit messages and titles
v1 link: https://lore.kernel.org/imx/[email protected]/
---
Wei Fang (2):
net: packet: fix wrong transport_header when sending VLAN-tagged frame
net: tap: fix wrong transport_header when sending VLAN-tagged frame
drivers/net/tap.c | 3 ++- net/packet/af_packet.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 net: packet: fix wrong transport_header when sending VLAN-tagged frame
From: Wei Fang <[email protected]>
In packet_parse_headers(), when processing a VLAN-tagged frame, skb_set_network_header() is called to advance network_header past the VLAN tag to the inner protocol header. skb_probe_transport_header() is then called with skb->protocol still set to the outer VLAN EtherType (e.g. ETH_P_8021Q), while nhoff (derived from skb_network_offset()) already points past the VLAN tag to the inner protocol header.
In __skb_flow_dissect(), proto is initialized to ETH_P_8021Q and nhoff points past the VLAN tag. When the dissector hits case ETH_P_8021Q, it reads a struct vlan_hdr at nhoff via __skb_header_pointer(), but that offset contains the inner protocol header (e.g. an IP header). The bytes are misinterpreted as a VLAN header, yielding a garbage encapsulated EtherType that matches no known protocol. The dissector returns false, so skb_probe_transport_header() never calls skb_set_transport_header(), leaving transport_header at its uninitialized sentinel value (~0U).
Move skb_probe_transport_header() to before skb_set_network_header(). At the time skb_probe_transport_header() is called, network_header still points to the VLAN header, so nhoff correctly points to the VLAN header. The flow dissector can then parse the VLAN header, extract the inner EtherType, and advance nhoff to the inner protocol header, allowing transport_header to be set correctly.
--- net/packet/af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/packet/af_packet.c +2 -2
@@ -1943,13 +1943,13 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) sock->type == SOCK_RAW) skb->protocol =dev_parse_header_protocol (skb); +skb_probe_transport_header (skb); +/* Move network header to the right position for VLAN tagged packets */ if (likely (skb->dev->type ==ARPHRD_ETHER ) &ð_type_vlan (skb->protocol) &&vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 )skb_set_network_header (skb, depth); - -skb_probe_transport_header (skb); }/*
Signature · 1 line
2.34.1
Re: [PATCH v2 net 1/2] net: packet: fix wrong transport_header when sending VLAN-tagged frame
Quoted 9 lines · wei.fang@ wrote:
From: Wei Fang <[email protected]>
In
packet_parse_headers(), when processing a VLAN-tagged frame,skb_set_network_header()is called to advancenetwork_headerpast the VLAN tag to the inner protocol header.skb_probe_transport_header()is then called withskb->protocolstill set to the outer VLAN EtherType (e.g.ETH_P_8021Q), while nhoff (derived fromskb_network_offset()) already points past the VLAN tag to the inner protocol header.
Quoted 8 lines
In
__skb_flow_dissect(), proto is initialized toETH_P_8021Qand nhoff points past the VLAN tag. When the dissector hits caseETH_P_8021Q, it reads a structvlan_hdrat nhoff via__skb_header_pointer(), but that offset contains the inner protocol header (e.g. an IP header). The bytes are misinterpreted as a VLAN header, yielding a garbage encapsulated EtherType that matches no known protocol. The dissector returns false, soskb_probe_transport_header()never callsskb_set_transport_header(), leavingtransport_headerat its uninitialized sentinel value (~0U).
Not for this patch, but: having a mismatched skb->protocol and network header offset is asking for trouble anyway.
The blamed commit states that this block is here for GSO packets, and the mismatch will by fixed up when skb->protocol is updated in virtio_net_hdr_set_proto. But that only updates GSO packets, while this block affects all VLAN tagged packets. Both GSO and non-GSO should be treated similarly throughout the stack. One approach is setting skb->protocol here. But that does mess with anything matching VLAN packets. There does not seem to be a perfect solution..
Quoted 10 lines
Move
skb_probe_transport_header()to beforeskb_set_network_header(). At the timeskb_probe_transport_header()is called,network_headerstill points to the VLAN header, so nhoff correctly points to the VLAN header. The flow dissector can then parse the VLAN header, extract the inner EtherType, and advance nhoff to the inner protocol header, allowingtransport_headerto be set correctly.Fixes dfed913e8b55 ("net/af_packet: add VLAN support for AF_PACKET SOCK_RAW GSO")Assisted-by WChat:claude-opus-4-8Signed-off-by Wei Fang <[email protected]>
PATCH v2 2/2 net: tap: fix wrong transport_header when sending VLAN-tagged frame
In reply to [email protected]From: Wei Fang <[email protected]>
In tap_get_user_xdp(), when processing a VLAN-tagged frame (e.g. ETH_P_8021Q), skb_set_network_header() is called first to advance network_header past the VLAN tag to the inner protocol header. skb_probe_transport_header() is then called with skb->protocol still set to ETH_P_8021Q, while nhoff (derived from skb_network_offset()) already points past the VLAN tag to the inner protocol header.
In __skb_flow_dissect(), proto is initialized to ETH_P_8021Q and nhoff points past the VLAN tag. When the dissector hits case ETH_P_8021Q, it reads a struct vlan_hdr at the current nhoff via __skb_header_pointer(), but that offset contains the inner protocol header (e.g. an IP header). The bytes are misinterpreted as a VLAN header, yielding a garbage encapsulated EtherType that matches no known protocol. The dissector returns false, so skb_probe_transport_header() never calls skb_set_transport_header(), leaving transport_header at its uninitialized sentinel value (~0U).
Move skb_set_network_header() to after skb_probe_transport_header(). At the time skb_probe_transport_header() is called, network_header still points to the VLAN header (offset ETH_HLEN), so nhoff is correct and the flow dissector can parse the VLAN header, extract the inner EtherType, and advance nhoff to the inner protocol header, allowing transport_header to be set correctly.
--- drivers/net/tap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap.c +2 -1
@@ -1091,12 +1091,13 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) } } +skb_probe_transport_header (skb); +/* Move network header to the right position for VLAN tagged packets */ if (eth_type_vlan (skb->protocol) &&vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 )skb_set_network_header (skb, depth); -skb_probe_transport_header (skb);dev_queue_xmit (skb);rcu_read_unlock ();
Signature · 1 line
2.34.1
Re: [PATCH v2 net 2/2] net: tap: fix wrong transport_header when sending VLAN-tagged frame
Quoted 26 lines · wei.fang@ wrote:
From: Wei Fang <[email protected]>
In
tap_get_user_xdp(), when processing a VLAN-tagged frame (e.g.ETH_P_8021Q),skb_set_network_header()is called first to advancenetwork_headerpast the VLAN tag to the inner protocol header.skb_probe_transport_header()is then called withskb->protocolstill set toETH_P_8021Q, while nhoff (derived fromskb_network_offset()) already points past the VLAN tag to the inner protocol header.In
__skb_flow_dissect(), proto is initialized toETH_P_8021Qand nhoff points past the VLAN tag. When the dissector hits caseETH_P_8021Q, it reads a structvlan_hdrat the current nhoff via__skb_header_pointer(), but that offset contains the inner protocol header (e.g. an IP header). The bytes are misinterpreted as a VLAN header, yielding a garbage encapsulated EtherType that matches no known protocol. The dissector returns false, soskb_probe_transport_header()never callsskb_set_transport_header(), leavingtransport_headerat its uninitialized sentinel value (~0U).Move
skb_set_network_header()to afterskb_probe_transport_header(). At the timeskb_probe_transport_header()is called,network_headerstill points to the VLAN header (offsetETH_HLEN), so nhoff is correct and the flow dissector can parse the VLAN header, extract the inner EtherType, and advance nhoff to the inner protocol header, allowingtransport_headerto be set correctly.
Quoted 3 lines
Fixes 8c76e77f9069 ("tap: call skb_probe_transport_header after setting skb->dev")Assisted-by WChat:claude-opus-4-8Signed-off-by Wei Fang <[email protected]>
Only if respinning: include the explanation why tap_get_user does not need this, only tap_get_user_xdp.
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Fri, 7 Aug 2026 14:34:03 +0800 you wrote:
From: Wei Fang <[email protected]>
When sending a VLAN-tagged frame via
AF_PACKETor tap, callingskb_set_network_header()beforeskb_probe_transport_header()causes the flow dissector to misinterpret the inner protocol header as a VLAN header. As a result,transport_headeris never set and remains at its uninitialized sentinel value (~0U).[...]
Here is the summary with links:
- [v2,net,1/2] net: packet: fix wrong transport_header when sending VLAN-tagged frame
https://git.kernel.org/netdev/net/c/01fdecc0480d - [v2,net,2/2] net: tap: fix wrong transport_header when sending VLAN-tagged frame https://git.kernel.org/netdev/net/c/cbb35cbe8db2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html