net: fix skb->protocol not updated after VLAN network header adjustment
Subsystems (6)
cover net: fix skb->protocol not updated after VLAN network header adjustment
From: Wei Fang <[email protected]>
After calling skb_set_network_header() to skip past the VLAN tag, skb->protocol still points to the outer VLAN EtherType. If skb_probe_transport_header() is then called without updating skb->protocol to the inner protocol, the flow dissector will misparse the inner header as a VLAN header and fail to set transport_header, leaving it at its uninitialized sentinel value (~0U).
This series fixes two instances of this bug in packet_parse_headers() and tap_get_user_xdp() by assigning the return value of vlan_get_protocol_and_depth() to skb->protocol after skb_set_network_header().
Wei Fang (2):
net: packet: fix skb->protocol not updated after VLAN network header
adjustment
net: tap: fix skb->protocol not updated after VLAN network header
adjustment
drivers/net/tap.c | 12 +++++++++--- net/packet/af_packet.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 net: packet: fix skb->protocol not updated after VLAN network header adjustment
From: Wei Fang <[email protected]>
In packet_parse_headers(), when processing a VLAN-tagged frame on a SOCK_RAW AF_PACKET socket, skb_set_network_header() is called with the depth returned by vlan_get_protocol_and_depth() to advance network_header past the VLAN tag to the inner protocol header. However, skb->protocol was not updated to reflect the inner EtherType resolved by vlan_get_protocol_and_depth(), leaving it pointing to the outer VLAN EtherType (e.g. ETH_P_8021Q).
This mismatch causes skb_probe_transport_header() to invoke the flow dissector with proto=ETH_P_8021Q but nhoff already pointing past the VLAN tag to the inner header. The dissector interprets the inner header bytes as a VLAN header, fails to find a recognizable encapsulated protocol, and returns false. Consequently, transport_header is never set and remains at its uninitialized sentinel value (~0U = 0xFFFF).
Any subsequent code that calls skb_transport_header() or udp_hdr() on such an skb will dereference a pointer 65535 bytes past skb->head, potentially corrupting arbitrary kernel memory.
Save the return value of vlan_get_protocol_and_depth(), which already resolves the inner EtherType, and assign it to skb->protocol after skb_set_network_header(). This keeps skb->protocol and network_header consistent when skb_probe_transport_header() is called, allowing the flow dissector to correctly identify the transport layer header.
--- net/packet/af_packet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/packet/af_packet.c +9 -3
@@ -1945,9 +1945,15 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)/* Move network header to the right position for VLAN tagged packets */ if (likely (skb->dev->type ==ARPHRD_ETHER ) && -eth_type_vlan (skb->protocol) && -vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +eth_type_vlan (skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }skb_probe_transport_header (skb); }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH net 1/2] net: packet: fix skb->protocol not updated after VLAN network header adjustment
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Overwriting `skb->protocol` with the inner protocol while leaving the VLAN tag inline in the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Overwriting skb->protocol with the inner protocol while leaving the VLAN tag inline in the payload hides the VLAN tag from the network stack and drivers. This breaks packet transmission for VLAN-tagged packets sent via AF_PACKET SOCK_RAW. --
--- Patch [1]: [PATCH net 1/2] net: packet: fix skb->protocol not updated after VLAN network header adjustment --- commit f62ea124b860e7404cd95296234dc5505cb676c4
Author: Wei Fang <[email protected]>
net: packet: fix skb->protocol not updated after VLAN network header adjustment
This commit updates skb->protocol with the inner protocol resolved by vlan_get_protocol_and_depth() for VLAN-tagged frames sent via AF_PACKET SOCK_RAW. This allows the flow dissector to correctly identify the inner transport header instead of failing and leaving the transport header unset.
Quoted 8 lines
net/packet/af_packet.c +0
-0@@ -1945,9 +1945,15 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)/* Move network header to the right position for VLAN tagged packets */ if (likely(skb->dev->type == ARPHRD_ETHER) &&
net/packet/af_packet.c static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) · line 1954
Quoted 10 lines
net/packet/af_packet.c +7
-3- eth_type_vlan(skb->protocol) && - vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 0) -skb_set_network_header (skb, depth); + eth_type_vlan(skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto;
[Severity: High]
Does overwriting skb->protocol here hide the inline VLAN tag from the network stack and drivers?
Since the VLAN tag is left inline in the MAC payload, updating skb->protocol to the inner protocol (e.g. ETH_P_IP) causes eth_type_vlan(skb->protocol) to become false.
This can lead to vlan_features_check() being bypassed, which might allow the stack to send VLAN packets to a driver with TSO enabled even if the hardware doesn't support it.
Additionally, drivers like ixgbe that check for ETH_P_8021Q might fail to recognize the inline software VLAN tag, potentially causing issues like inserting duplicate VLAN tags when DCB is enabled or breaking egress TC filters.
Quoted 5 lines
net/packet/af_packet.c +2
-0+ } + }skb_probe_transport_header (skb); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 net: tap: fix skb->protocol not updated after VLAN network header adjustment
In reply to [email protected]From: Wei Fang <[email protected]>
In tap_get_user_xdp(), when processing a VLAN-tagged frame, skb_set_network_header() is called with the depth returned by vlan_get_protocol_and_depth() to advance network_header past the VLAN tag to the inner protocol header. However, skb->protocol was not updated to reflect the inner EtherType, leaving it pointing to the outer VLAN EtherType (e.g. ETH_P_8021Q).
This mismatch has two consequences. First, skb_probe_transport_header() is called after the VLAN adjustment with proto=ETH_P_8021Q but nhoff already pointing past the VLAN tag to the inner header. The flow dissector interprets the inner header bytes as a VLAN header, fails to find a recognizable encapsulated protocol, and returns false. Consequently, transport_header is never set and remains at its uninitialized sentinel value (~0U), causing any subsequent skb_transport_header() or udp_hdr() call to dereference a pointer 65535 bytes past skb->head, potentially corrupting arbitrary kernel memory. Second, TC egress and eBPF programs that inspect skb->protocol directly (e.g. bpf_skb_net_base_len(), bpf_skb_net_grow(), __bpf_redirect_neigh()) will see ETH_P_8021Q instead of the inner protocol and behave incorrectly.
Save the return value of vlan_get_protocol_and_depth(), which already resolves the inner EtherType, and assign it to skb->protocol after skb_set_network_header(). This keeps skb->protocol and network_header consistent for all subsequent processing.
--- drivers/net/tap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/tap.c +9 -3
@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) }/* 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); +if (eth_type_vlan (skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }rcu_read_lock (); tap =rcu_dereference (q->tap);
Signature · 1 line
2.34.1
Willem de Bruijn
maintainerRe: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
Quoted 45 lines · wei.fang@ wrote:
From: Wei Fang <[email protected]>
In
tap_get_user_xdp(), when processing a VLAN-tagged frame,skb_set_network_header()is called with the depth returned byvlan_get_protocol_and_depth()to advancenetwork_headerpast the VLAN tag to the inner protocol header. However,skb->protocolwas not updated to reflect the inner EtherType, leaving it pointing to the outer VLAN EtherType (e.g.ETH_P_8021Q).This mismatch has two consequences. First,
skb_probe_transport_header()is called after the VLAN adjustment with proto=ETH_P_8021Q but nhoff already pointing past the VLAN tag to the inner header. The flow dissector interprets the inner header bytes as a VLAN header, fails to find a recognizable encapsulated protocol, and returns false. Consequently,transport_headeris never set and remains at its uninitialized sentinel value (~0U), causing any subsequentskb_transport_header()orudp_hdr()call to dereference a pointer 65535 bytes pastskb->head, potentially corrupting arbitrary kernel memory. Second, TC egress and eBPF programs that inspectskb->protocoldirectly (e.g.bpf_skb_net_base_len(),bpf_skb_net_grow(),__bpf_redirect_neigh()) will seeETH_P_8021Qinstead of the inner protocol and behave incorrectly.Save the return value of
vlan_get_protocol_and_depth(), which already resolves the inner EtherType, and assign it toskb->protocolafterskb_set_network_header(). This keepsskb->protocolandnetwork_headerconsistent for all subsequent processing.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]>--- drivers/net/tap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/net/tap.c +0
-2@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) }/* 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 )
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 10 lines
drivers/net/tap.c +9
-1-skb_set_network_header (skb, depth); +if (eth_type_vlan (skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }
Does the same apply to the same call in tap_get_user?
And in general to other callers of vlan_get_protocol_and_depth, including through wrapper skb_network_protocol?
Quoted 6 lines
drivers/net/tap.c +0
-0rcu_read_lock (); tap =rcu_dereference (q->tap);Signature · 1 line
2.34.1
RE: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
Quoted 42 lines
Quoted 21 lines
In
tap_get_user_xdp(), when processing a VLAN-tagged frame,skb_set_network_header()is called with the depth returned byvlan_get_protocol_and_depth()to advancenetwork_headerpast the VLAN tag to the inner protocol header. However,skb->protocolwas not updated to reflect the inner EtherType, leaving it pointing to the outer VLAN EtherType (e.g.ETH_P_8021Q).This mismatch has two consequences. First,
skb_probe_transport_header()is called after the VLAN adjustment with proto=ETH_P_8021Q but nhoff already pointing past the VLAN tag to the inner header. The flow dissector interprets the inner header bytes as a VLAN header, fails to find a recognizable encapsulated protocol, and returns false. Consequently,transport_headeris never set and remains at its uninitialized sentinel value (~0U), causing any subsequentskb_transport_header()orudp_hdr()call to dereference a pointer 65535 bytes pastskb->head, potentially corrupting arbitrary kernel memory. Second, TC egress and eBPF programs that inspectskb->protocoldirectly (e.g.bpf_skb_net_base_len(),bpf_skb_net_grow(),__bpf_redirect_neigh()) will seeETH_P_8021Qinstead of the inner protocol and behave incorrectly.Quoted 6 lines
Save the return value of
vlan_get_protocol_and_depth(), which already resolves the inner EtherType, and assign it toskb->protocolafterskb_set_network_header(). This keepsskb->protocolandnetwork_headerconsistent for all subsequent processing.Fixes 8c76e77f9069 ("tap: call skb_probe_transport_header after setting
skb->dev")drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q,
Quoted 11 lines
Assisted-by WChat:claude-opus-4-8Signed-off-by Wei Fang <[email protected]>--- drivers/net/tap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/net/tap.c +0
-0@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue *q,struct
xdp_buff*xdp)Quoted 2 lines
drivers/net/tap.c +0
-0}
Quoted 15 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 13 lines
drivers/net/tap.c +9
-3/* 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); +if (eth_type_vlan (skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }Does the same apply to the same call in
tap_get_user?
The situation of tap_get_user() is different, skb_probe_transport_header() is called before the VLAN adjustment block. So I think transport_header should be correct. The only concern is whether skb->protocol needs to be updated after calling skb_set_network_header().
I'm not sure as I am not fairly familiar with the tap driver. I added this patch because Sashiko reported that the tap driver has the same issue as af_packet.
Quoted 3 lines
And in general to other callers of
vlan_get_protocol_and_depth, including through wrapperskb_network_protocol?
I don't think this issue exists elsewhere. The issue arises because skb_probe_transport_header() is called after skb_set_network_header(), and at this point, skb->protocol and network_header are not synchronized ( In __skb_flow_dissect(), nhoff = skb_network_offset(skb) but proto is ETH_P_8021Q or ETH_P_8021AD)), causing skb_probe_transport_header() to fail to set transport_header correctly.
Perhaps the correct approach would be to restore the original skb->protocol value after skb_probe_transport_header(), maintaining consistency with the previous behavior; otherwise, it might introduce new issues.
RE: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
Quoted 44 lines
Quoted 3 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue
Quoted 3 lines
drivers/net/tap.c +0
-0@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue*q,
Quoted 4 lines
struct
xdp_buff*xdp)Quoted 3 lines
drivers/net/tap.c +0
-0}/* Move network header to the right position for VLAN tagged packets */
Quoted 5 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
Quoted 5 lines
drivers/net/tap.c +2
-3-if (eth_type_vlan (skb->protocol) && -vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +if (eth_type_vlan (skb->protocol)) { + __be16 proto = vlan_get_protocol_and_depth(skb,
skb->protocol,Quoted 9 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 7 lines
drivers/net/tap.c +7
-0+ &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }Does the same apply to the same call in
tap_get_user?The situation of
tap_get_user()is different,skb_probe_transport_header()is called before the VLAN adjustment block. So I thinktransport_headershould be correct. The only concern is whetherskb->protocolneeds to be updated after callingskb_set_network_header().I'm not sure as I am not fairly familiar with the tap driver. I added this patch because Sashiko reported that the tap driver has the same issue as
af_packet.Quoted 3 lines
And in general to other callers of
vlan_get_protocol_and_depth, including through wrapperskb_network_protocol?I don't think this issue exists elsewhere. The issue arises because
skb_probe_transport_header()is called afterskb_set_network_header(), and at this point,skb->protocolandnetwork_headerare not synchronized ( In__skb_flow_dissect(), nhoff =skb_network_offset(skb)but proto isETH_P_8021QorETH_P_8021AD)), causingskb_probe_transport_header()to fail to settransport_headercorrectly.
Quoted 3 lines
Perhaps the correct approach would be to restore the original
skb->protocolvalue afterskb_probe_transport_header(), maintaining consistency with the previous behavior; otherwise, it might introduce new issues.
For AF_PACKET, it has been confirmed that skb->protocol does not need to be restored to its initial value; otherwise, the egress tc flower for protocol ip will not match the packet. A known issue is that the packets cannot match the egress TC flower rules for protocol 802.1Q, but this issue exists before this series. This is likely a limitation of using AF_PACKET to send packets.
Willem de Bruijn
maintainerRE: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
Quoted 48 lines · Wei Fang
Quoted 44 lines
Quoted 3 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue
Quoted 3 lines
drivers/net/tap.c +0
-0@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue*q,
Quoted 4 lines
struct
xdp_buff*xdp)Quoted 3 lines
drivers/net/tap.c +0
-0}/* Move network header to the right position for VLAN tagged packets */
Quoted 5 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
Quoted 5 lines
drivers/net/tap.c +2
-3-if (eth_type_vlan (skb->protocol) && -vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +if (eth_type_vlan (skb->protocol)) { + __be16 proto = vlan_get_protocol_and_depth(skb,
skb->protocol,Quoted 9 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 7 lines
drivers/net/tap.c +7
-0+ &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }Does the same apply to the same call in
tap_get_user?The situation of
tap_get_user()is different,skb_probe_transport_header()is called before the VLAN adjustment block. So I thinktransport_headershould be correct. The only concern is whetherskb->protocolneeds to be updated after callingskb_set_network_header().I'm not sure as I am not fairly familiar with the tap driver. I added this patch because Sashiko reported that the tap driver has the same issue as
af_packet.Quoted 3 lines
And in general to other callers of
vlan_get_protocol_and_depth, including through wrapperskb_network_protocol?I don't think this issue exists elsewhere. The issue arises because
skb_probe_transport_header()is called afterskb_set_network_header(), and at this point,skb->protocolandnetwork_headerare not synchronized ( In__skb_flow_dissect(), nhoff =skb_network_offset(skb)but proto isETH_P_8021QorETH_P_8021AD)), causingskb_probe_transport_header()to fail to settransport_headercorrectly.Quoted 3 lines
Perhaps the correct approach would be to restore the original
skb->protocolvalue afterskb_probe_transport_header(), maintaining consistency with the previous behavior; otherwise, it might introduce new issues.
Quoted 5 lines
For
AF_PACKET, it has been confirmed thatskb->protocoldoes not need to be restored to its initial value; otherwise, the egress tc flower for protocol ip will not match the packet. A known issue is that the packets cannot match the egress TC flower rules for protocol 802.1Q, but this issue exists before this series. This is likely a limitation of usingAF_PACKETto send packets.
Actually this update of network header to start of the IP header may have been a mistake. If userspace inserts a VLAN packet, that is what should enter the stack.
But for this specific issue: would it make sense to just move skb_probe_transport_header before that adjustment?
RE: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
Quoted 61 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/tap.c static int tap_get_user_xdp(struct
Quoted 3 lines
drivers/net/tap.c +0
-0@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct
tap_queueQuoted 22 lines
Quoted 22 lines
*q,
Quoted 4 lines
struct
xdp_buff*xdp)Quoted 3 lines
drivers/net/tap.c +0
-0}/* Move network header to the right position for VLAN tagged packets */
Quoted 5 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
Quoted 5 lines
drivers/net/tap.c +2
-3-if (eth_type_vlan (skb->protocol) && -vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +if (eth_type_vlan (skb->protocol)) { + __be16 proto = vlan_get_protocol_and_depth(skb,
skb->protocol,Quoted 9 lines
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 7 lines
drivers/net/tap.c +7
-0+ &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }Does the same apply to the same call in
tap_get_user?Quoted 7 lines
Quoted 7 lines
The situation of
tap_get_user()is different,skb_probe_transport_header()is called before the VLAN adjustment block. So I thinktransport_headershould be correct. The only concern is whetherskb->protocolneeds to be updated after callingskb_set_network_header().I'm not sure as I am not fairly familiar with the tap driver. I added this patch because Sashiko reported that the tap driver has the same issue as
af_packet.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
And in general to other callers of
vlan_get_protocol_and_depth, including through wrapperskb_network_protocol?I don't think this issue exists elsewhere. The issue arises because
skb_probe_transport_header()is called afterskb_set_network_header(),and
Quoted 3 lines
Quoted 3 lines
at this point,
skb->protocolandnetwork_headerare not synchronized ( In__skb_flow_dissect(), nhoff =skb_network_offset(skb)but proto isETH_P_8021QorETH_P_8021AD)), causingskb_probe_transport_header()to
Quoted 3 lines
Quoted 3 lines
fail to set
transport_headercorrectly.Perhaps the correct approach would be to restore the original
skb->protocolQuoted 1 line
Quoted 1 line
value after
skb_probe_transport_header(), maintaining consistency withthe
Quoted 5 lines
Quoted 1 line
previous behavior; otherwise, it might introduce new issues.
For
AF_PACKET, it has been confirmed thatskb->protocoldoes not need to be restored to its initial value; otherwise, the egress tc flower for protocol ip will not match the packet. A known issue is that the packets cannot match theegress
Quoted 2 lines
TC flower rules for protocol 802.1Q, but this issue exists before this series. This is likely a limitation of using
AF_PACKETto send packets.
Quoted 6 lines
Actually this update of network header to start of the IP header may have been a mistake. If userspace inserts a VLAN packet, that is what should enter the stack.
But for this specific issue: would it make sense to just move
skb_probe_transport_headerbefore that adjustment?
I think it is feasible. The transport_header will be set correctly, and other behaviors will remain consistent with before, without introducing an new issues.
[email protected]
AI reviewRe: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment
In reply to [email protected]Thank 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:
Pre-existing issues:
- [High] Incomplete fix: skb->protocol is not updated after network_header adjustment in tap_get_user(). --
--- Patch [2]: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment --- commit 6866d2a8bbb104d45013a4b8fcd7c1800086ae28
Author: Wei Fang <[email protected]>
net: tap: fix skb->protocol not updated after VLAN network header adjustment
This commit fixes an issue in tap_get_user_xdp() where skb->protocol was not updated after advancing the network header past the VLAN tag. It sets the protocol to the inner EtherType to keep skb->protocol and network_header consistent for subsequent processing.
Quoted 10 lines
drivers/net/tap.c +0
-2@@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) }/* 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 )
drivers/net/tap.c static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) · line 1092
Quoted 10 lines
drivers/net/tap.c +9
-1-skb_set_network_header (skb, depth); +if (eth_type_vlan (skb->protocol)) { +__be16 proto =vlan_get_protocol_and_depth (skb, skb->protocol, + &depth); + +if (proto !=0 ) { +skb_set_network_header (skb, depth); + skb->protocol = proto; + } + }
[Severity: High]
This isn't a bug introduced by this patch, but does tap_get_user() also need this same fix for non-XDP transmission paths?
Looking at tap_get_user() in drivers/net/tap.c, it contains the identical logic that was patched here:
drivers/net/tap.c:tap_get_user() {
...
/* 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);
...
}Without updating skb->protocol here as well, will TC egress and eBPF programs still read skb->protocol as ETH_P_8021Q while network_header points to the inner IP header?
If a user or guest VM writes a VLAN-tagged packet to a TAP file descriptor using standard (non-XDP) I/O, could this allow them to craft an IP header that causes traffic classification and security policies to misinterpret the packet?
Quoted 3 lines
drivers/net/tap.c +0
-0rcu_read_lock (); tap =rcu_dereference (q->tap);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2