Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames
@ 2026-12-02 12:36 Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

ip6gre can check the length of one header and read another when
transmitting a VLAN-tagged frame. Parsing the frame again after pushing
GRE can also lose the inner protocol. This series extends Eric
Dumazet's original fix and targets net-next because it changes the
ip6_tnl_xmit() interface.

Patches 1 and 2 bound the ERSPAN VLAN and DS-field reads and derive COS
from the mirrored frame. For a VLAN protocol, the IP version nibble is
a heuristic: a non-IP payload such as MPLS can still give nonzero COS.
Patches 3 and 4 classify the payload once, before encapsulation, and
use that result for header inheritance, truncation and PMTU handling.
Patch 5 tests hop limit, traffic class and COS with and without VLAN.
The IPv4 GRE transmit path, tunnel receive paths, ip6gre header_ops
and VXLAN/Geneve remain follow-ups.

In KVM the new selftest passed 24/24 with the series (14/24 on the
base). On both kernels 16 existing selftests passed and the
264-case functional matrix matched the previous results. A separate
iperf3 check passed BIG TCP traffic over gre, gretap, ip6gre and
ip6gretap; the upstream BIG TCP selftest skipped for lack of netperf.
All five intermediate kernels and the final CONFIG_INET=n kernel built.
The earlier KMSAN results are from 5eb53a1fbf80.

I used Claude Code and Codex for development, testing and review and
take responsibility for the submission.

Changes since v7:
 - Rebase onto net-next 3a3cf3118f1f, which enables BIG TCP on GRE
   devices.
 - In patch 4, check for IPv6 before sending ICMPv6 Packet Too Big on
   -EMSGSIZE, as Sashiko suggested. In KVM, oversized ARP frames now
   drop without calling either ICMP handler. IPv4 and IPv6 senders
   still receive the expected MTU errors, with and without an 802.1Q
   tag. Patches 1-3 and 5 are unchanged.

Changes since v6 (introduced in v7):
 - Expand the single patch for net into a five-patch series for
   net-next following the scope discussion [1].
 - Replace skb_vlan_inet_prepare() in the IPv6 GRE transmit path.
   Preserve the network header when skb->protocol already identifies
   the payload, including on VLAN devices with reorder_hdr off.
 - When skb->protocol is a VLAN type on an Ethernet device, read the
   EtherType from the frame and walk the tags. Set the network header
   only if the tags lead to IPv4 or IPv6.
 - Pass the classified protocol to ip6_tnl_xmit() so it can use it
   after the GRE header has been pushed.
 - Put the two ERSPAN header fixes first (patches 1 and 2), use the
   classified protocol in ip6erspan (patch 4), and add a selftest
   for tagged and untagged traffic (patch 5).

[1] https://lore.kernel.org/netdev/20261014005308.1606362-1-littlesmilingcloud@gmail.com/

v7: https://lore.kernel.org/netdev/20261201005941.1536429-1-littlesmilingcloud@gmail.com/
v6: https://lore.kernel.org/netdev/20261008012554.202925-1-littlesmilingcloud@gmail.com/
v5: https://lore.kernel.org/netdev/20261005231414.932997-1-littlesmilingcloud@gmail.com/
v4: https://lore.kernel.org/netdev/20261004145205.226974-1-littlesmilingcloud@gmail.com/
v3: https://lore.kernel.org/netdev/20260119112512.28196-1-fw@strlen.de/
v2: https://lore.kernel.org/netdev/20260106144529.1424886-1-edumazet@google.com/
v1: https://lore.kernel.org/netdev/20260105100330.2258612-1-edumazet@google.com/

Anton Danilov (5):
  erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
  erspan: take the COS from the mirrored frame, not from the tunnel
    family
  ip6_gre: classify the inner packet once on transmit
  ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
  selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags

 include/net/erspan.h                          |  68 +++++--
 include/net/ip6_tunnel.h                      |   3 +-
 net/ipv4/ip_gre.c                             |  13 +-
 net/ipv6/ip6_gre.c                            |  97 +++++++---
 net/ipv6/ip6_tunnel.c                         |  11 +-
 tools/testing/selftests/net/Makefile          |   1 +
 .../selftests/net/ip6_gre_vlan_inherit.sh     | 172 ++++++++++++++++++
 7 files changed, 309 insertions(+), 56 deletions(-)
 create mode 100755 tools/testing/selftests/net/ip6_gre_vlan_inherit.sh


base-commit: 3a3cf3118f1f4fa3b5a51f5d88b27dd43737c380
-- 
2.47.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
  2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
@ 2026-12-02 12:36 ` Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

erspan_build_header() and erspan_build_header_v2() decide whether the
mirrored frame is VLAN tagged by reading the EtherType at offset 12
and, for ETH_P_8021Q, the TCI at offset 14, without checking that the
frame is that long. Shorter frames do reach them: the transmit paths
check the length with pskb_inet_may_pull_reason() on IPv4 and
pskb_inet_may_pull() on IPv6. These only make sure that the IPv4 or
IPv6 header announced by skb->protocol is there. A frame
that announces anything else gets through, whatever its length.

syzbot reported the EtherType read for a short frame redirected into
an erspan device by bpf. It does not take bpf: a 10 byte frame
redirected into erspan or ip6erspan by tc mirred from a tun device
gives "KMSAN: uninit-value in erspan_build_header".

The TCI read has the same problem two bytes further on. A 14 byte
frame that ends right after the 0x8100 EtherType gets two bytes from
past its end copied into the VLAN field of the ERSPAN header, and KMSAN
reports them when the packet is received on the other side.

Read both fields with skb_header_pointer(), so that a frame too short
to carry a tag is treated as untagged.

The TCI read was found by an AI code review agent, in a review of
another series that touches these functions. Both reads were confirmed
in a VM on an unmodified kernel built with KMSAN, with the two frames
above. With this patch and the next one, which bounds the remaining
read of this kind, the same frames give no report on erspan.

Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre")
Reported-by: syzbot+9e27778c0edc62cb97d8@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9e27778c0edc62cb97d8
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 include/net/erspan.h | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/include/net/erspan.h b/include/net/erspan.h
index c6209e7b6c96..6bda757b6da2 100644
--- a/include/net/erspan.h
+++ b/include/net/erspan.h
@@ -174,13 +174,12 @@ static inline void erspan_build_header(struct sk_buff *skb,
 				u32 id, u32 index,
 				bool truncate, bool is_ipv4)
 {
-	struct ethhdr *eth = (struct ethhdr *)skb->data;
 	enum erspan_encap_type enc_type;
 	struct erspan_base_hdr *ershdr;
 	struct qtag_prefix {
 		__be16 eth_type;
 		__be16 tci;
-	} *qp;
+	} *qp, _qp;
 	u16 vlan_tci = 0;
 	u8 tos;
 	__be32 *idx;
@@ -194,8 +193,8 @@ static inline void erspan_build_header(struct sk_buff *skb,
 	/* If mirrored packet has vlan tag, extract tci and
 	 * preserve vlan header in the mirrored frame.
 	 */
-	if (eth->h_proto == htons(ETH_P_8021Q)) {
-		qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
+	qp = skb_header_pointer(skb, 2 * ETH_ALEN, sizeof(_qp), &_qp);
+	if (qp && qp->eth_type == htons(ETH_P_8021Q)) {
 		vlan_tci = ntohs(qp->tci);
 		enc_type = ERSPAN_ENCAP_INFRAME;
 	}
@@ -268,13 +267,12 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
 					  u32 id, u8 direction, u16 hwid,
 					  bool truncate, bool is_ipv4)
 {
-	struct ethhdr *eth = (struct ethhdr *)skb->data;
 	struct erspan_base_hdr *ershdr;
 	struct erspan_md2 *md2;
 	struct qtag_prefix {
 		__be16 eth_type;
 		__be16 tci;
-	} *qp;
+	} *qp, _qp;
 	u16 vlan_tci = 0;
 	u8 gra = 0; /* 100 usec */
 	u8 bso = 0; /* Bad/Short/Oversized */
@@ -288,10 +286,9 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
 	/* Unlike v1, v2 does not have En field,
 	 * so only extract vlan tci field.
 	 */
-	if (eth->h_proto == htons(ETH_P_8021Q)) {
-		qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
+	qp = skb_header_pointer(skb, 2 * ETH_ALEN, sizeof(_qp), &_qp);
+	if (qp && qp->eth_type == htons(ETH_P_8021Q))
 		vlan_tci = ntohs(qp->tci);
-	}
 
 	bso = erspan_detect_bso(skb);
 	skb_push(skb, sizeof(*ershdr) + ERSPAN_V2_MDSIZE);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family
  2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
@ 2026-12-02 12:36 ` Anton Danilov
  2026-12-03 12:38   ` netdev-bot+sashiko
  2026-12-02 12:36 ` [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

erspan_build_header() and erspan_build_header_v2() take the TOS for
the COS field from ip_hdr(skb)->tos when the tunnel is IPv4 and from
the IPv6 traffic class when the tunnel is IPv6. But is_ipv4 describes
the tunnel, not the mirrored frame, so

 - an IPv4 frame mirrored to ip6erspan gets its COS from the IPv4
   version/IHL byte and the high TOS nibble: always 2, whatever the
   DSCP;
 - an IPv6 frame mirrored to erspan gets its COS from the low nibble
   of the traffic class: 4 instead of 5 for EF;
 - a frame that is neither gets its COS from whatever lies at the
   network header offset, which for a short frame is past its end.

Pick the IP version by the frame instead: by skb->protocol or, when
that is a VLAN type, by the version field at the network header. Read
the two bytes that hold the TOS or traffic class with
skb_header_pointer(). Return COS 0 if those bytes are unavailable or
the protocol is not recognized as IPv4 or IPv6 by this rule.

Keep the existing DSCP-to-COS mapping. This change bounds the reads
and removes the tunnel family from the interpretation of the inner
IP header; it does not introduce a new QoS policy based on VLAN PCP, MPLS
TC or skb->priority. The latter is a queueing priority, not necessarily
a three-bit class of service, and would need an explicit mapping.

For skb->protocol carrying a VLAN type, the version field is only a
heuristic, not validation of the encapsulated protocol. A non-IP
payload such as an MPLS label can begin with the same nibble as IPv4
or IPv6 and still produce a nonzero COS. Its COS can also differ from
the old tunnel-family-based result. Classifying arbitrary non-IP
VLAN payloads is outside this change; no COS 0 guarantee is made for
them. The two-byte read is bounded regardless of that classification.

The TOS is still read at the network header. That is where the stack,
tc mirred and packet sockets leave the IP header, also for frames that
do not start with an Ethernet header and its tags, such as a packet
mirrored from an L3 device or a frame behind a switch tag mirrored
from a DSA conduit. Where the network header is not on the IP header
the COS stays wrong, as do the other fields read there; one such case
is a tagged frame written by a packet socket under an IP sll_protocol,
whose network header is on the tag.

Drop the is_ipv4 argument, and with it the stale forward declaration
of erspan_build_header() in ip_gre.c, which would have had to follow.

The wrong COS and the read past the end were found by an AI code
review agent, in a review of another series that touches these
functions, and confirmed in a VM on an unmodified kernel:

 - EF (DSCP 46) frames mirrored with tc from a veth give COS 2 for
   IPv4 over ip6erspan v1 and v2, COS 4 for IPv6 over erspan v1 and
   v2, and COS 5 in the other four combinations. With the patch all
   eight give COS 5. So do the same frames with the EtherType at
   offset 12 overwritten by tc pedit as a switch tag would, sent
   through a VLAN device, and IP packets mirrored from a tun device:
   48 cases in all;
 - a 14 byte non-IP frame gives a KMSAN report when the packet is
   received on the other side; with the patch it does not.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 include/net/erspan.h | 53 ++++++++++++++++++++++++++++++++++++--------
 net/ipv4/ip_gre.c    | 13 ++++-------
 net/ipv6/ip6_gre.c   | 10 ++++-----
 3 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/include/net/erspan.h b/include/net/erspan.h
index 6bda757b6da2..c272b3fb9bfd 100644
--- a/include/net/erspan.h
+++ b/include/net/erspan.h
@@ -58,9 +58,11 @@
  * GRE proto ERSPAN type I/II = 0x88BE, type III = 0x22EB
  */
 
+#include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/skbuff.h>
+#include <net/dsfield.h>
 #include <uapi/linux/erspan.h>
 
 #define ERSPAN_VERSION	0x1	/* ERSPAN type II */
@@ -170,9 +172,46 @@ static inline u8 tos_to_cos(u8 tos)
 	return cos;
 }
 
+/* TOS of the mirrored frame, for the COS field, read at the network
+ * header.  The IP version comes from skb->protocol or, for a VLAN type,
+ * from the version field there, and not from the tunnel family.  The
+ * bytes are read with skb_header_pointer(), so a frame that does not
+ * have them gets 0.
+ */
+static inline u8 erspan_frame_tos(const struct sk_buff *skb)
+{
+	/* Align the two-byte buffer as struct iphdr, since
+	 * skb_header_pointer() may return its address as iph.
+	 */
+	__be16 _prefix __aligned(__alignof__(struct iphdr));
+	int offset = skb_network_offset(skb);
+	__be16 type = skb->protocol;
+	const struct iphdr *iph;
+
+	if (offset < 0)
+		return 0;
+
+	/* Version and DS field fit in the first 16 bits of either IP header. */
+	iph = skb_header_pointer(skb, offset, sizeof(_prefix), &_prefix);
+	if (!iph)
+		return 0;
+
+	if (eth_type_vlan(type)) {
+		if (iph->version == 4)
+			type = htons(ETH_P_IP);
+		else if (iph->version == 6)
+			type = htons(ETH_P_IPV6);
+	}
+
+	if (type == htons(ETH_P_IP))
+		return iph->tos;
+	if (type == htons(ETH_P_IPV6))
+		return ipv6_get_dsfield((const struct ipv6hdr *)iph);
+	return 0;
+}
+
 static inline void erspan_build_header(struct sk_buff *skb,
-				u32 id, u32 index,
-				bool truncate, bool is_ipv4)
+				u32 id, u32 index, bool truncate)
 {
 	enum erspan_encap_type enc_type;
 	struct erspan_base_hdr *ershdr;
@@ -184,9 +223,7 @@ static inline void erspan_build_header(struct sk_buff *skb,
 	u8 tos;
 	__be32 *idx;
 
-	tos = is_ipv4 ? ip_hdr(skb)->tos :
-			(ipv6_hdr(skb)->priority << 4) +
-			(ipv6_hdr(skb)->flow_lbl[0] >> 4);
+	tos = erspan_frame_tos(skb);
 
 	enc_type = ERSPAN_ENCAP_NOVLAN;
 
@@ -265,7 +302,7 @@ static inline u8 erspan_detect_bso(struct sk_buff *skb)
 
 static inline void erspan_build_header_v2(struct sk_buff *skb,
 					  u32 id, u8 direction, u16 hwid,
-					  bool truncate, bool is_ipv4)
+					  bool truncate)
 {
 	struct erspan_base_hdr *ershdr;
 	struct erspan_md2 *md2;
@@ -279,9 +316,7 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
 	u8 sgt = 0;
 	u8 tos;
 
-	tos = is_ipv4 ? ip_hdr(skb)->tos :
-			(ipv6_hdr(skb)->priority << 4) +
-			(ipv6_hdr(skb)->flow_lbl[0] >> 4);
+	tos = erspan_frame_tos(skb);
 
 	/* Unlike v1, v2 does not have En field,
 	 * so only extract vlan tci field.
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 745bd12dcd68..7e8606074979 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -111,9 +111,6 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly;
 static const struct header_ops ipgre_header_ops;
 
 static int ipgre_tunnel_init(struct net_device *dev);
-static void erspan_build_header(struct sk_buff *skb,
-				u32 id, u32 index,
-				bool truncate, bool is_ipv4);
 
 static unsigned int ipgre_net_id __read_mostly;
 static unsigned int gre_tap_net_id __read_mostly;
@@ -630,14 +627,14 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	if (version == 1) {
 		erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
-				    ntohl(md->u.index), truncate, true);
+				    ntohl(md->u.index), truncate);
 		proto = htons(ETH_P_ERSPAN);
 	} else if (version == 2) {
 		erspan_build_header_v2(skb,
 				       ntohl(tunnel_id_to_key32(key->tun_id)),
 				       md->u.md2.dir,
 				       get_hwid(&md->u.md2),
-				       truncate, true);
+				       truncate);
 		proto = htons(ETH_P_ERSPAN2);
 	} else {
 		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
@@ -790,13 +787,11 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 		__clear_bit(IP_TUNNEL_SEQ_BIT, flags);
 	} else if (tunnel->erspan_ver == 1) {
 		erspan_build_header(skb, ntohl(tunnel->parms.o_key),
-				    tunnel->index,
-				    truncate, true);
+				    tunnel->index, truncate);
 		proto = htons(ETH_P_ERSPAN);
 	} else if (tunnel->erspan_ver == 2) {
 		erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key),
-				       tunnel->dir, tunnel->hwid,
-				       truncate, true);
+				       tunnel->dir, tunnel->hwid, truncate);
 		proto = htons(ETH_P_ERSPAN2);
 	} else {
 		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 38c5c519986d..51f4311bebfa 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1019,15 +1019,14 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 		if (md->version == 1) {
 			erspan_build_header(skb,
 					    ntohl(tun_id),
-					    ntohl(md->u.index), truncate,
-					    false);
+					    ntohl(md->u.index), truncate);
 			proto = htons(ETH_P_ERSPAN);
 		} else if (md->version == 2) {
 			erspan_build_header_v2(skb,
 					       ntohl(tun_id),
 					       md->u.md2.dir,
 					       get_hwid(&md->u.md2),
-					       truncate, false);
+					       truncate);
 			proto = htons(ETH_P_ERSPAN2);
 		} else {
 			goto tx_err;
@@ -1053,14 +1052,13 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 
 		if (t->parms.erspan_ver == 1) {
 			erspan_build_header(skb, ntohl(t->parms.o_key),
-					    t->parms.index,
-					    truncate, false);
+					    t->parms.index, truncate);
 			proto = htons(ETH_P_ERSPAN);
 		} else if (t->parms.erspan_ver == 2) {
 			erspan_build_header_v2(skb, ntohl(t->parms.o_key),
 					       t->parms.dir,
 					       t->parms.hwid,
-					       truncate, false);
+					       truncate);
 			proto = htons(ETH_P_ERSPAN2);
 		} else {
 			goto tx_err;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit
  2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
@ 2026-12-02 12:36 ` Anton Danilov
  2026-12-03 12:39   ` netdev-bot+sashiko
  2026-12-02 12:36 ` [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
  2026-12-02 12:36 ` [PATCH net-next v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Anton Danilov
  4 siblings, 1 reply; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

ip6gre_tunnel_xmit() and ip6erspan_tunnel_xmit() work out what the
encapsulated packet carries in three places, each by its own rule:

 - the length check, pskb_inet_may_pull(), goes by skb->protocol and
   makes sure of an IPv4 or IPv6 header at the network header;
 - the dispatch in ip6gre_tunnel_xmit() uses skb_protocol(skb, true),
   which looks through VLAN tags from skb->data, at a depth taken from
   skb->mac_len;
 - ip6_tnl_xmit() calls skb_protocol(skb, true) again for the hop limit
   to inherit, after the GRE and ERSPAN headers have been pushed, so
   this walk starts inside those headers.

For a VLAN-tagged frame the three disagree:

 - the check sees a VLAN type and pulls nothing, while the dispatch
   finds IPv4 or IPv6 behind the tag and reads the inner header anyway.
   A tagged frame too short for that header has it read from past its
   end and is sent, while an untagged one is dropped (the syzbot report
   below);
 - the walk in ip6_tnl_xmit() lines up with the inner EtherType only on
   ip6gretap with a 4 byte GRE header and skb->mac_len 0 or 18. With a
   key, a checksum, a sequence number, another mac_len, or on
   ip6erspan, it reads MAC address or ERSPAN bytes instead: the hop
   limit is then not inherited, or, when those bytes read as ETH_P_IP
   or ETH_P_IPV6, taken from wherever the network header points,
   whatever the frame carries;
 - skb->mac_len is no guide here: on transmit it is whatever the device
   the skb was received on left, 14 forwarded, 18 from a VLAN device
   with reorder_hdr off, 24 from an NBMA gre device, 0 for a local one.

Classify the packet once, on entry, and pass the result down:

 - a non-VLAN skb->protocol is taken as it is, with the network header
   where the sender left it and the same length check as before;
 - a VLAN skb->protocol on ip6gretap and ip6erspan is resolved from the
   frame, starting with the EtherType at offset 12 from skb->data,
   where __vlan_get_protocol() starts once skb->mac_len is ETH_HLEN.
   When the tags lead to IPv4 or IPv6, that header is pulled and the
   network header is set on it, and a frame too short for it is dropped
   as an untagged one is. Any other frame gets the same check as before
   and is sent untouched, with no field taken from it;
 - ip6gre has no Ethernet header at skb->data, so no tags are looked
   for there and a VLAN skb->protocol is a protocol like any other.

ip6_tnl_xmit() takes the result as a new argument and no longer parses
the packet. ip6_tunnel's own devices pass skb->protocol: they send only
IPv4, IPv6 and MPLS, for which skb_protocol() returned just that.

What changes for traffic that was not broken before:

 - the hop limit of a tagged frame is inherited on every ip6gretap and
   ip6erspan device, not only on ip6gretap with a 4 byte GRE header and
   mac_len 0 or 18;
 - a frame that arrives with its network header on a VLAN tag (after tc
   act_ife decode, a generic XDP redirect, or tc act_vlan push on an
   already tagged frame) gets its traffic class from the IP header, not
   from the TCI;
 - a VLAN-typed skb on ip6gre, such as an Ethernet frame forwarded to
   it by nft fwd, no longer has its traffic class taken through the tag;
   its GRE protocol stays the VLAN type, with an Ethernet or mangled IP
   header behind it, before and after.

The length check mismatch was reported by syzbot, the walk after the
push by the Sashiko review of v5, and the role of skb->mac_len by an AI
code review agent on an earlier version. All were confirmed in a VM on
an unmodified kernel:

 - with KMSAN, an 18 byte tagged ARP frame written by a packet socket
   to a keyed ip6gretap or an ip6erspan device, with bytes that read as
   ETH_P_IP where the second walk lands, goes out with a hop limit from
   past its end; with the patch it goes out with the route's hop limit
   and the reports are gone;
 - a 20 byte tagged IPv4 frame on a keyed ip6gretap is sent before the
   patch and dropped with it;
 - IPv4 packets with TTL 33 and hoplimit inherit were sent to ip6gretap
   with and without a key and to ip6erspan v1 and v2, in 35 ways: local
   stack, VLAN devices with reorder_hdr on and off, a bridge, tc mirred
   from ingress and egress, bpf and generic XDP redirect, nft fwd,
   packet sockets, act_vlan, act_pedit, act_ife, and a tun device.
   Before the patch the tagged frames that reach the device with a VLAN
   skb->protocol go out with hop limit 33 only on ip6gretap without a
   key and only with skb->mac_len 0, 64 otherwise; with the patch all
   go out with 33 on all four devices. Frames that reach with an IP
   skb->protocol are unchanged.

gre_gso.sh, l2_tos_ttl_inherit.sh, ip6_gre_headroom.sh, ip6_tunnel.sh
and the mirror_gre and ip6gre forwarding selftests give the same
results before and after.

Fixes: 3f8a8447fd0b ("ip6_gre: use actual protocol to select xmit")
Fixes: b09ab9c92e50 ("ip6_tunnel: allow to inherit from VLAN encapsulated IP")
Reported-by: syzbot+6023ea32e206eef7920a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6023ea32e206eef7920a
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 include/net/ip6_tunnel.h |  3 +-
 net/ipv6/ip6_gre.c       | 77 ++++++++++++++++++++++++++++++++++------
 net/ipv6/ip6_tunnel.c    |  9 +++--
 3 files changed, 72 insertions(+), 17 deletions(-)

diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h
index d1f0a427e9c8..50caf745a61b 100644
--- a/include/net/ip6_tunnel.h
+++ b/include/net/ip6_tunnel.h
@@ -144,7 +144,8 @@ int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
 		     const struct in6_addr *raddr);
 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
-		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);
+		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto,
+		 __be16 payload_protocol);
 __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
 __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
 			     const struct in6_addr *raddr);
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 51f4311bebfa..c413e47c6ceb 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -730,7 +730,8 @@ static struct ip_tunnel_info *skb_tunnel_info_txcheck(struct sk_buff *skb)
 static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 			       struct net_device *dev, __u8 dsfield,
 			       struct flowi6 *fl6, int encap_limit,
-			       __u32 *pmtu, __be16 proto)
+			       __u32 *pmtu, __be16 proto,
+			       __be16 payload_protocol)
 {
 	struct ip6_tnl *tunnel = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags);
@@ -797,7 +798,7 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 	}
 
 	return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
-			    NEXTHDR_GRE);
+			    NEXTHDR_GRE, payload_protocol);
 }
 
 static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
@@ -821,7 +822,7 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
 		return -1;
 
 	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			  skb->protocol);
+			  skb->protocol, htons(ETH_P_IP));
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE)
@@ -860,7 +861,7 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
 		return -1;
 
 	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
-			  &mtu, skb->protocol);
+			  &mtu, skb->protocol, htons(ETH_P_IPV6));
 	if (err != 0) {
 		if (err == -EMSGSIZE)
 			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
@@ -870,7 +871,8 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
-static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
+static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev,
+			     __be16 payload_protocol)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	int encap_limit = -1;
@@ -887,11 +889,64 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
 						t->parms.o_flags));
 	if (err)
 		return err;
-	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, skb->protocol);
+	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
+			  skb->protocol, payload_protocol);
 
 	return err;
 }
 
+/* Classify the payload once, on entry to ndo_start_xmit, and make sure
+ * that the header the answer stands for is in the linear area.  Nothing
+ * below parses the frame again: the answer is passed down, also to
+ * ip6_tnl_xmit().  It is ETH_P_IP or ETH_P_IPV6 only when that header is
+ * at the network header.
+ *
+ * If skb->protocol is not a VLAN type, it and the network header are
+ * taken as the sender left them.
+ *
+ * If it is a VLAN type on an Ethernet device, the payload type is in the
+ * frame, behind the tags, and is read from there, starting with the
+ * EtherType at offset 12 from skb->data: that is where
+ * __vlan_get_protocol() starts when skb->mac_len is ETH_HLEN.  The
+ * skb->mac_len the skb comes with is no guide, it is what the device it
+ * was received on left there, or 0.  When the tags lead to IPv4 or IPv6,
+ * that header is pulled and the network header is set on it.  Any other
+ * frame gets the same check as before and is sent as it is, with the
+ * network header left alone, and no field is taken from it.
+ *
+ * ip6gre has no Ethernet header at skb->data to find tags in, so a VLAN
+ * skb->protocol there is a protocol like any other.
+ */
+static enum skb_drop_reason
+ip6gre_xmit_classify(struct sk_buff *skb, const struct net_device *dev,
+		     __be16 *payload_protocol)
+{
+	enum skb_drop_reason reason;
+	int depth, nhlen;
+	__be16 type;
+
+	*payload_protocol = skb->protocol;
+	if (dev->type != ARPHRD_ETHER || !eth_type_vlan(skb->protocol))
+		return pskb_inet_may_pull_reason(skb);
+
+	skb->mac_len = ETH_HLEN;
+	type = __vlan_get_protocol(skb, skb->protocol, &depth);
+	if (type == htons(ETH_P_IP))
+		nhlen = sizeof(struct iphdr);
+	else if (type == htons(ETH_P_IPV6))
+		nhlen = sizeof(struct ipv6hdr);
+	else
+		return pskb_inet_may_pull_reason(skb);
+
+	reason = pskb_may_pull_reason(skb, depth + nhlen);
+	if (reason)
+		return reason;
+
+	skb_set_network_header(skb, depth);
+	*payload_protocol = type;
+	return SKB_NOT_DROPPED_YET;
+}
+
 static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 	struct net_device *dev)
 {
@@ -900,7 +955,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 	__be16 payload_protocol;
 	int ret;
 
-	if (!pskb_inet_may_pull(skb))
+	if (ip6gre_xmit_classify(skb, dev, &payload_protocol))
 		goto tx_err;
 
 	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
@@ -909,7 +964,6 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 	if (t->parms.collect_md)
 		tun_info = skb_tunnel_info_txcheck(skb);
 
-	payload_protocol = skb_protocol(skb, true);
 	switch (payload_protocol) {
 	case htons(ETH_P_IP):
 		ret = ip6gre_xmit_ipv4(skb, dev);
@@ -918,7 +972,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 		ret = ip6gre_xmit_ipv6(skb, dev);
 		break;
 	default:
-		ret = ip6gre_xmit_other(skb, dev);
+		ret = ip6gre_xmit_other(skb, dev, payload_protocol);
 		break;
 	}
 
@@ -941,6 +995,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	struct ip_tunnel_info *tun_info = NULL;
 	struct ip6_tnl *t = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags) = { };
+	__be16 payload_protocol;
 	bool truncate = false;
 	int encap_limit = -1;
 	__u8 dsfield = false;
@@ -950,7 +1005,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	__u32 mtu;
 	int nhoff;
 
-	if (!pskb_inet_may_pull(skb))
+	if (ip6gre_xmit_classify(skb, dev, &payload_protocol))
 		goto tx_err;
 
 	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
@@ -1073,7 +1128,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			 htonl(atomic_fetch_inc(&t->o_seqno)));
 
 	err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			   NEXTHDR_GRE);
+			   NEXTHDR_GRE, payload_protocol);
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE) {
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index d743904425f8..931911b5e8a8 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1107,6 +1107,8 @@ EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);
  *   @encap_limit: encapsulation limit
  *   @pmtu: Path MTU is stored if packet is too big
  *   @proto: next header value
+ *   @payload_protocol: protocol of the inner packet; ETH_P_IP or ETH_P_IPV6
+ *	only if that header is at the network header, in the linear area
  *
  * Description:
  *   Build new header and do some sanity checks on the packet before sending
@@ -1120,7 +1122,7 @@ EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);
 
 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu,
-		 __u8 proto)
+		 __u8 proto, __be16 payload_protocol)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct net *net = t->net;
@@ -1132,13 +1134,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	unsigned int eth_hlen = t->dev->type == ARPHRD_ETHER ? ETH_HLEN : 0;
 	unsigned int psh_hlen = sizeof(struct ipv6hdr) + t->encap_hlen;
 	unsigned int max_headroom = psh_hlen;
-	__be16 payload_protocol;
 	bool use_cache = false;
 	u8 hop_limit;
 	int err = -1;
 
-	payload_protocol = skb_protocol(skb, true);
-
 	if (t->parms.collect_md) {
 		hop_limit = skb_tunnel_info(skb)->key.ttl;
 		goto route_lookup;
@@ -1424,7 +1423,7 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 	skb_set_inner_ipproto(skb, protocol);
 
 	err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			   protocol);
+			   protocol, skb->protocol);
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
  2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
                   ` (2 preceding siblings ...)
  2026-12-02 12:36 ` [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
@ 2026-12-02 12:36 ` Anton Danilov
  2026-12-03 12:39   ` netdev-bot+sashiko
  2026-12-02 12:36 ` [PATCH net-next v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Anton Danilov
  4 siblings, 1 reply; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

ip6erspan_tunnel_xmit() uses skb->protocol to select the inner header
for traffic class and flow label inheritance, length checks and ICMP
errors. ip6_tnl_xmit() uses it to select the minimum MTU. When the
protocol is a VLAN EtherType, a tagged IPv4 packet can lose its traffic
class and take the ICMPv6 error path on -EMSGSIZE.

Use the payload protocol classified on entry to the tunnel. For IPv4
and IPv6 the classifier has pulled the header and set or preserved the
network header offset. On -EMSGSIZE, send Fragmentation Needed for
IPv4 and Packet Too Big for IPv6. Other payloads have no inner IP
source to notify, so let them take the usual transmit error path.

An AI review of an earlier version identified the traffic class issue.
In VM tests with tclass inherit, a tagged IPv4 packet with TOS 0xb8
had outer traffic class 0 on ip6erspan v1 and v2. With this change it
has traffic class 0xb8, as it does without a tag.

On native ip6erspan v1, an oversized ARP frame took the ICMPv6 error
path with the old unconditional else, both with and without an 802.1Q
tag. With the IPv6 check both frames were dropped without calling
either ICMP handler. For both tag layouts the IPv4 sender received
Fragmentation Needed and the IPv6 sender received Packet Too Big.
Each error quoted the original Echo Request and advertised MTU 1338.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 net/ipv6/ip6_gre.c    | 10 +++++-----
 net/ipv6/ip6_tunnel.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index c413e47c6ceb..0ecee2271bbd 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1021,11 +1021,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	}
 
 	nhoff = skb_network_offset(skb);
-	if (skb->protocol == htons(ETH_P_IP) &&
+	if (payload_protocol == htons(ETH_P_IP) &&
 	    (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
 		truncate = true;
 
-	if (skb->protocol == htons(ETH_P_IPV6)) {
+	if (payload_protocol == htons(ETH_P_IPV6)) {
 		int thoff;
 
 		if (skb_transport_header_was_set(skb))
@@ -1087,7 +1087,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			goto tx_err;
 		}
 	} else {
-		switch (skb->protocol) {
+		switch (payload_protocol) {
 		case htons(ETH_P_IP):
 			memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
 			prepare_ip6gre_xmit_ipv4(skb, dev, &fl6,
@@ -1132,10 +1132,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE) {
-			if (skb->protocol == htons(ETH_P_IP))
+			if (payload_protocol == htons(ETH_P_IP))
 				icmp_ndo_send(skb, ICMP_DEST_UNREACH,
 					      ICMP_FRAG_NEEDED, htonl(mtu));
-			else
+			else if (payload_protocol == htons(ETH_P_IPV6))
 				icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
 		}
 
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 931911b5e8a8..3d8b2d5851ef 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1227,7 +1227,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		max_headroom += 8;
 		mtu -= 8;
 	}
-	mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ?
+	mtu = max(mtu, payload_protocol == htons(ETH_P_IPV6) ?
 		       IPV6_MIN_MTU : IPV4_MIN_MTU);
 
 	skb_dst_update_pmtu_no_confirm(skb, mtu);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags
  2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
                   ` (3 preceding siblings ...)
  2026-12-02 12:36 ` [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
@ 2026-12-02 12:36 ` Anton Danilov
  4 siblings, 0 replies; 9+ messages in thread
From: Anton Danilov @ 2026-12-02 12:36 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Simon Horman, David Ahern, Willem de Bruijn, Ido Schimmel,
	Florian Westphal, William Tu, Meenakshi Vohra, Matthias May,
	Mazin Al Haddad, Shuah Khan, linux-kselftest, linux-kernel

Add ip6_gre_vlan_inherit.sh. It sends IPv4 and IPv6 packets with a
given TTL and TOS through ip6gretap, with and without a key, and
through ip6erspan v1 and v2, directly and through a VLAN device on top
of the tunnel, and checks on the receiving side that

 - the outer hop limit and traffic class are those of the inner
   packet, with a VLAN tag in front of it or without;
 - on ip6erspan, the COS field of the ERSPAN header is the one that the
   inner TOS asks for, for IPv4 and for IPv6.

The outer header is matched with tc flower and the COS field with tc
u32, and the packets are counted.

Without the previous patches of this series 10 of the 24 checks fail:
the hop limit behind a tag on ip6gretap with a key, the hop limit and
traffic class behind a tag on ip6erspan, and the COS of IPv4 packets on
ip6erspan.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 tools/testing/selftests/net/Makefile          |   1 +
 .../selftests/net/ip6_gre_vlan_inherit.sh     | 172 ++++++++++++++++++
 2 files changed, 173 insertions(+)
 create mode 100755 tools/testing/selftests/net/ip6_gre_vlan_inherit.sh

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index fb0a64662053..0d8a5ff31b17 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -53,6 +53,7 @@ TEST_PROGS := \
 	io_uring_zerocopy_tx.sh \
 	ioam6.sh \
 	ip6_gre_headroom.sh \
+	ip6_gre_vlan_inherit.sh \
 	ip6_tunnel.sh \
 	ip_defrag.sh \
 	ip_local_port_range.sh \
diff --git a/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh b/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh
new file mode 100755
index 000000000000..94aed82e9441
--- /dev/null
+++ b/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh
@@ -0,0 +1,172 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# ip6gretap and ip6erspan can take the outer hop limit and traffic class from
+# the packet they carry. Check that they do so for a packet behind a VLAN tag
+# as they do for one without a tag, and that ip6erspan derives the COS field
+# of the ERSPAN header from the carried packet, whether it is IPv4 or IPv6.
+#
+# +-------------------------------+          +---------------------------+
+# | ns1                           |          | ns2                       |
+# |                               |          |                           |
+# |  tun.10 (VLAN 10)             |          |                           |
+# |     |                         |          |                           |
+# |    tun (ip6gretap/ip6erspan)  |          |                           |
+# |     :                         |          |                           |
+# |   veth1 ------------------------------------ veth2                   |
+# |   2001:db8:1::1/64            |          |   2001:db8:1::2/64        |
+# |                               |          |   ingress: tc counters    |
+# +-------------------------------+          +---------------------------+
+#
+# The packets are sent to neighbours that only exist as static neighbour
+# entries, and are counted in ns2 as they arrive, by their outer header.
+
+# shellcheck disable=SC2154 # ns1 and ns2 are set by setup_ns
+source lib.sh
+
+readonly TTL=33
+readonly TOS=0xb8		# DSCP EF, which makes COS 5
+readonly COS_MATCH="0xa0 0xe0"	# COS 5 in the top bits of its byte
+readonly COUNT=5
+readonly LLADDR=00:00:5e:00:53:01
+
+# Offset of the COS byte from the outer IPv6 header: IPv6 (40), GRE with a
+# sequence number (8), then the third byte of the ERSPAN header. The tunnels
+# are created with "encaplimit none", so that no extension header moves it.
+readonly COS_OFF=50
+
+setup()
+{
+	setup_ns ns1 ns2 || exit "$ksft_skip"
+
+	ip -n "$ns1" link add veth1 type veth peer name veth2 netns "$ns2"
+	ip -n "$ns1" address add 2001:db8:1::1/64 dev veth1 nodad
+	ip -n "$ns2" address add 2001:db8:1::2/64 dev veth2 nodad
+	ip -n "$ns1" link set dev veth1 up
+	ip -n "$ns2" link set dev veth2 up
+
+	tc -n "$ns2" qdisc add dev veth2 clsact
+	# Encapsulated packets with the inherited hop limit and traffic class.
+	# flower reads a numeric ip_proto as hexadecimal: 0x2f is GRE.
+	tc -n "$ns2" filter add dev veth2 ingress pref 1 handle 101 \
+		protocol ipv6 flower ip_proto 0x2f \
+		ip_ttl "$TTL" ip_tos "$TOS" \
+		action continue
+	# ERSPAN packets with the expected COS.
+	# shellcheck disable=SC2086 # COS_MATCH is a value and a mask
+	tc -n "$ns2" filter add dev veth2 ingress pref 2 \
+		protocol ipv6 u32 \
+		match u8 47 0xff at 6 \
+		match u8 $COS_MATCH at "$COS_OFF" \
+		action pass
+}
+
+tunnel_create()
+{
+	local kind=$1; shift
+	local -a args
+
+	case "$kind" in
+	ip6gretap)
+		args=(type ip6gretap);;
+	ip6gretap_key)
+		args=(type ip6gretap key 1);;
+	ip6erspan_v1)
+		args=(type ip6erspan seq key 1 erspan_ver 1 erspan 1);;
+	ip6erspan_v2)
+		args=(type ip6erspan seq key 1 erspan_ver 2
+		      erspan_dir ingress erspan_hwid 1);;
+	esac
+
+	ip -n "$ns1" link add tun "${args[@]}" \
+		local 2001:db8:1::1 remote 2001:db8:1::2 \
+		tclass inherit hoplimit inherit encaplimit none
+	ip -n "$ns1" link add link tun name tun.10 type vlan id 10
+	ip -n "$ns1" link set dev tun up
+	ip -n "$ns1" link set dev tun.10 up
+
+	ip -n "$ns1" address add 192.0.2.1/28 dev tun
+	ip -n "$ns1" address add 2001:db8:2::1/64 dev tun nodad
+	ip -n "$ns1" address add 192.0.2.17/28 dev tun.10
+	ip -n "$ns1" address add 2001:db8:3::1/64 dev tun.10 nodad
+
+	ip -n "$ns1" neigh add 192.0.2.2 lladdr "$LLADDR" dev tun
+	ip -n "$ns1" neigh add 2001:db8:2::2 lladdr "$LLADDR" dev tun
+	ip -n "$ns1" neigh add 192.0.2.18 lladdr "$LLADDR" dev tun.10
+	ip -n "$ns1" neigh add 2001:db8:3::2 lladdr "$LLADDR" dev tun.10
+}
+
+tunnel_destroy()
+{
+	ip -n "$ns1" link del dev tun
+}
+
+inherit_count()
+{
+	tc_rule_handle_stats_get "dev veth2 ingress" 101 ".packets" "-n $ns2"
+}
+
+cos_count()
+{
+	tc -n "$ns2" -j -s filter show dev veth2 ingress pref 2 |
+		jq '[.[] | select(.options.actions) |
+		     .options.actions[0].stats.packets] | add'
+}
+
+# Send COUNT packets and check that as many arrive with the outer header
+# fields that the inner header asks for.
+send_and_check()
+{
+	local kind=$1; shift
+	local what=$1; shift
+	local dst=$1; shift
+	local inherit cos
+
+	inherit=$(inherit_count)
+	cos=$(cos_count)
+
+	# Nobody answers: ping sends COUNT packets and gives up.
+	ip netns exec "$ns1" ping -q -c "$COUNT" -i 0.01 -W 1 \
+		-t "$TTL" -Q "$TOS" "$dst" &> /dev/null
+
+	RET=0
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is \
+		">= $((inherit + COUNT))" inherit_count > /dev/null
+	check_err $? "outer hop limit and traffic class not inherited"
+	log_test "$kind: $what, hop limit and traffic class"
+
+	[[ "$kind" == ip6erspan* ]] || return 0
+
+	RET=0
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is \
+		">= $((cos + COUNT))" cos_count > /dev/null
+	check_err $? "COS not taken from the inner header"
+	log_test "$kind: $what, ERSPAN COS"
+}
+
+test_kind()
+{
+	local kind=$1; shift
+
+	tunnel_create "$kind"
+
+	send_and_check "$kind" "IPv4" 192.0.2.2
+	send_and_check "$kind" "IPv6" 2001:db8:2::2
+	send_and_check "$kind" "IPv4 in VLAN" 192.0.2.18
+	send_and_check "$kind" "IPv6 in VLAN" 2001:db8:3::2
+
+	tunnel_destroy
+}
+
+require_command jq
+
+trap cleanup_all_ns EXIT
+
+setup
+
+test_kind ip6gretap
+test_kind ip6gretap_key
+test_kind ip6erspan_v1
+test_kind ip6erspan_v2
+
+exit "$EXIT_STATUS"
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family
  2026-12-02 12:36 ` [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
@ 2026-12-03 12:38   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 12:38 UTC (permalink / raw)
  To: littlesmilingcloud
  Cc: netdev, edumazet, kuba, pabeni, davem, horms, dsahern, willemb,
	idosch, fw, u9012063, mvohra, matthias.may, mazin, shuah,
	linux-kselftest, linux-kernel

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit fixes two bugs that are visible on the wire, but it
  has no Fixes: tag.

Pre-existing issues:
- [Medium] erspan_frame_tos() (include/net/erspan.h) still gets the COS
  wrong for double-tagged (QinQ) frames mirrored from tc ingress.

--

erspan: take the COS from the mirrored frame, not from the tunnel family

This patch changes how erspan_build_header() and erspan_build_header_v2()
get the COS. They used to pick IPv4 or IPv6 from the tunnel family; now
they pick it from the mirrored frame, using skb->protocol and, for VLAN
types, the version nibble at the network header. The read uses
skb_header_pointer() and gives 0 if the bytes are not there, and the
is_ipv4 argument is dropped from both builders.

>      - a 14 byte non-IP frame gives a KMSAN report when the packet is
>        received on the other side; with the patch it does not.
>
>     Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>

[Severity: Low]
Should this commit carry Fixes: tags?

It fixes two bugs that show up on the wire. One is the COS taken from the
tunnel family. The other is the read past the end of a short non-IP frame,
which puts uninitialized bits into the transmitted COS field.

The previous patch in the series, "erspan: bound the VLAN tag read in
erspan_build_header{,_v2}()", has Fixes: tags and a syzbot Closes:. Its
message says the KMSAN reports only go away "with this patch and the next
one, which bounds the remaining read of this kind".

Without tags here, stable tooling could take the previous patch alone and
leave the uninitialized COS read in stable kernels.

Based on blame of the removed reads, the candidates look like:

  Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
  Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre")
  Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")

a3222dc95ca7 only moved this code into erspan.h, so it does not look like
the origin.

> diff --git a/include/net/erspan.h b/include/net/erspan.h
> index 6bda757b6da21..c272b3fb9bfd6 100644
> --- a/include/net/erspan.h
> +++ b/include/net/erspan.h

[ ... ]

> @@ -170,9 +172,46 @@ static inline u8 tos_to_cos(u8 tos)
>  	return cos;
>  }
>  
> +/* TOS of the mirrored frame, for the COS field, read at the network
> + * header.  The IP version comes from skb->protocol or, for a VLAN type,
> + * from the version field there, and not from the tunnel family.  The
> + * bytes are read with skb_header_pointer(), so a frame that does not
> + * have them gets 0.
> + */
> +static inline u8 erspan_frame_tos(const struct sk_buff *skb)
> +{

[ ... ]

> +	/* Version and DS field fit in the first 16 bits of either IP header. */
> +	iph = skb_header_pointer(skb, offset, sizeof(_prefix), &_prefix);
> +	if (!iph)
> +		return 0;
> +
> +	if (eth_type_vlan(type)) {
> +		if (iph->version == 4)
> +			type = htons(ETH_P_IP);
> +		else if (iph->version == 6)
> +			type = htons(ETH_P_IPV6);
> +	}
> +
> +	if (type == htons(ETH_P_IP))
> +		return iph->tos;
> +	if (type == htons(ETH_P_IPV6))
> +		return ipv6_get_dsfield((const struct ipv6hdr *)iph);
> +	return 0;
> +}

[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. For
double-tagged (QinQ) frames mirrored from tc ingress, does this heuristic
still take the COS from VLAN ID bits?

On receive, __netif_receive_skb_core() untags only once before
sch_handle_ingress():

    if (eth_type_vlan(skb->protocol)) {
        skb = skb_vlan_untag(skb);

skb_vlan_untag() moves the outer tag into hwaccel and sets skb->protocol
to the inner 0x8100. It then calls skb_reset_network_header(), which
leaves the network header on the inner TCI. If the NIC already stripped
the outer tag, the network header ends up there as well.

The path then continues:

  tcf_mirred_to_dev() -> validate_xmit_vlan() -> erspan_xmit()
    -> erspan_build_header() -> erspan_frame_tos()

erspan has no NETIF_F_HW_VLAN_*_TX, so validate_xmit_vlan() pushes the
tag back inline with __vlan_insert_inner_tag(). That moves only
mac_header and sets skb->protocol to the outer vlan_proto.

In erspan_frame_tos(), eth_type_vlan(type) is then true, and iph->version
is the top nibble of the inner TCI (PCP << 1 | DEI):

  - inner PCP 2 with DEI 0 is taken as IPv4, and iph->tos returns VID
    bits 0-7
  - inner PCP 3 with DEI 0 is taken as IPv6, and ipv6_get_dsfield()
    returns TCI bits 4-11
  - any other PCP gives COS 0, even when the payload is IP

The commit message says:

    The TOS is still read at the network header. That is where the stack,
    tc mirred and packet sockets leave the IP header, ...

Is that accurate for this ingress QinQ path? Could it be added to the
list of cases where the COS stays wrong?

Also, the later patch "ip6_gre: classify the inner packet once on
transmit" adds ip6gre_xmit_classify(). It walks the tags with
__vlan_get_protocol() and calls skb_set_network_header() on the inner IP
header.

No later patch in the series seems to change erspan_xmit() or
erspan_fb_xmit() in net/ipv4/ip_gre.c. At the end of the series, would
the same QinQ frame get a different COS over erspan than over ip6erspan?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202123613.1708463-1-littlesmilingcloud%40gmail.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit
  2026-12-02 12:36 ` [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
@ 2026-12-03 12:39   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 12:39 UTC (permalink / raw)
  To: littlesmilingcloud
  Cc: netdev, edumazet, kuba, pabeni, davem, horms, dsahern, willemb,
	idosch, fw, u9012063, mvohra, matthias.may, mazin, shuah,
	linux-kselftest, linux-kernel

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 this commit, ip6erspan_tunnel_xmit() (net/ipv6/ip6_gre.c)
  passes the classified payload_protocol only to ip6_tnl_xmit() (line…

--

ip6_gre: classify the inner packet once on transmit

This commit adds ip6gre_xmit_classify(). It works out the inner protocol
once, on entry to ip6gre_tunnel_xmit() and ip6erspan_tunnel_xmit(). On
Ethernet devices it looks through VLAN tags and pulls the inner IP header.
The result is passed down to ip6_tnl_xmit() as a new payload_protocol
argument. That replaces the skb_protocol(skb, true) calls, which parsed the
frame again after the GRE and ERSPAN headers were pushed.

Closes: https://syzkaller.appspot.com/bug?extid=6023ea32e206eef7920a

> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 51f4311bebfa4..c413e47c6ceb0 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c

[ ... ]

> @@ -950,7 +1005,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
>  	__u32 mtu;
>  	int nhoff;
>  
> -	if (!pskb_inet_may_pull(skb))
> +	if (ip6gre_xmit_classify(skb, dev, &payload_protocol))
>  		goto tx_err;
>  
>  	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))

[ ... ]

> @@ -1073,7 +1128,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
>  			 htonl(atomic_fetch_inc(&t->o_seqno)));
>  
>  	err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
> -			   NEXTHDR_GRE);
> +			   NEXTHDR_GRE, payload_protocol);
>  	if (err != 0) {
>  		/* XXX: send ICMP error even if DF is not set. */
>  		if (err == -EMSGSIZE) {

[Severity: Medium]
payload_protocol is passed to ip6_tnl_xmit() here. Does the rest of
ip6erspan_tunnel_xmit() still go by skb->protocol? In this commit the
truncate checks, the native mode dispatch and the choice of ICMP family
are unchanged:

net/ipv6/ip6_gre.c:ip6erspan_tunnel_xmit() {
    ...
	nhoff = skb_network_offset(skb);
	if (skb->protocol == htons(ETH_P_IP) &&
	    (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
		truncate = true;

	if (skb->protocol == htons(ETH_P_IPV6)) {
    ...
	} else {
		switch (skb->protocol) {
		case htons(ETH_P_IP):
    ...
		if (err == -EMSGSIZE) {
			if (skb->protocol == htons(ETH_P_IP))
				icmp_ndo_send(skb, ICMP_DEST_UNREACH,
					      ICMP_FRAG_NEEDED, htonl(mtu));
			else
				icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
    ...
}

ip6_tnl_xmit() now takes payload_protocol as an argument, but its MTU
floor still checks skb->protocol:

net/ipv6/ip6_tunnel.c:ip6_tnl_xmit() {
    ...
	mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ?
		       IPV6_MIN_MTU : IPV4_MIN_MTU);
    ...
}

Take a VLAN-tagged IPv4 or IPv6 frame on a native ip6erspan device.
ip6gre_xmit_classify() sets payload_protocol to ETH_P_IP or ETH_P_IPV6, so
the hop limit is inherited from the inner header.

The switch on skb->protocol still takes the default branch, though. That
skips prepare_ip6gre_xmit_ipv4() and prepare_ip6gre_xmit_ipv6(), so the
traffic class, flow label and encap_limit do not come from the inner
header. The truncate bit is not set from the inner length either.

On -EMSGSIZE, a tagged IPv4 frame would be passed to icmpv6_ndo_send()
with an IPv4 header at the network header. icmp6_send() bounds-checks that
read, so the result is a bogus PKT_TOOBIG, not memory corruption.

These sites behaved the same way before this patch. Even so, the
behaviour doesn't seem to match the new comment above
ip6gre_xmit_classify():

  Nothing below parses the frame again: the answer is passed down, also to
  ip6_tnl_xmit().

The next patch in the series, "ip6_gre: go by the inner protocol behind
VLAN tags in ip6erspan", appears to switch all four sites to
payload_protocol and to send icmpv6_ndo_send() only for ETH_P_IPV6. Could
that change be folded into this one? If not, could the comment and the
commit message be adjusted so this commit is accurate on its own?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202123613.1708463-1-littlesmilingcloud%40gmail.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
  2026-12-02 12:36 ` [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
@ 2026-12-03 12:39   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 12:39 UTC (permalink / raw)
  To: littlesmilingcloud
  Cc: netdev, edumazet, kuba, pabeni, davem, horms, dsahern, willemb,
	idosch, fw, u9012063, mvohra, matthias.may, mazin, shuah,
	linux-kselftest, linux-kernel

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

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] The advertised MTU on the -EMSGSIZE path is too large for
  ip6erspan, and this patch now sends it to VLAN-tagged IPv4 senders as…
- [Low] The commit message does not mention several behaviour changes the
  patch makes.
- [Low] The patch fixes user-visible bugs in ip6erspan_tunnel_xmit() but
  has no Fixes: tag.

--

ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan

This patch makes ip6erspan_tunnel_xmit() and ip6_tnl_xmit() use the
payload protocol classified on tunnel entry instead of skb->protocol. With
this, VLAN-tagged IPv4/IPv6 frames get traffic class inheritance, length
checks and the matching ICMP error. On -EMSGSIZE, non-IP payloads no
longer go down the ICMPv6 error path.

> ip6erspan_tunnel_xmit() uses skb->protocol to select the inner header
> for traffic class and flow label inheritance, length checks and ICMP
> errors. ip6_tnl_xmit() uses it to select the minimum MTU. When the
> protocol is a VLAN EtherType, a tagged IPv4 packet can lose its traffic
> class and take the ICMPv6 error path on -EMSGSIZE.

[ ... ]

> Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>

[Severity: Low]
Should this patch have a Fixes: tag?

Users can see both behaviours fixed here:

- On native ip6erspan, tagged IPv4/IPv6 lost traffic class and flow
  label inheritance because the switch fell into the default branch.
- On -EMSGSIZE, every non-IPv4 payload (ARP, or IPv4 behind a tag) went
  to icmpv6_ndo_send() through the unconditional else.

Both go back to the original ip6erspan native and collect_md support.

This patch also depends on payload_protocol, which comes from the
previous patch in the series, "ip6_gre: classify the inner packet once
on transmit". That patch does carry Fixes: tags.

Without a tag here, could stable tooling pick up the prerequisite but
miss this follow-up? That would leave ip6erspan only partly fixed in
stable trees.

> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index c413e47c6ceb0..0ecee2271bbd1 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c

[ ... ]

> @@ -1087,7 +1087,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
>  			goto tx_err;
>  		}
>  	} else {
> -		switch (skb->protocol) {
> +		switch (payload_protocol) {

[Severity: Low]
This isn't a bug, but should the commit message describe the other
behaviour changes for tagged frames on native ip6erspan?

With switch (payload_protocol), VLAN-tagged IPv4/IPv6 frames now go
through prepare_ip6gre_xmit_ipv4() and prepare_ip6gre_xmit_ipv6(). They
used to take the default branch, which left encap_limit at -1:

		default:
			memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
			break;

For tagged traffic this means:

- encap_limit now comes from t->parms.encap_limit unless
  IP6_TNL_F_IGN_ENCAP_LIMIT is set. Unset is the default, because
  ip6gre_netlink_parms() zeroes the flags. ip6_tnl_xmit() then lowers
  mtu by 8 and pushes an 8-byte Tunnel Encapsulation Limit destination
  option, so the packets on the wire change.
- With IP6_TNL_F_USE_ORIG_FWMARK, the outer route lookup now uses
  skb->mark.
- Tagged IPv6 frames whose source equals t->parms.raddr are now dropped.
- Tagged IPv6 frames that carry an encap limit option of 0 are now
  dropped, and an ICMPv6 Parameter Problem is sent.

The subject mentions only ip6erspan, but the floor change in
ip6_tnl_xmit() also affects ip6gretap. ip6gre_xmit_ipv6() passes
ETH_P_IPV6 as payload_protocol for tagged IPv6:

	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
			  &mtu, skb->protocol, htons(ETH_P_IPV6));

So tagged IPv6 on ip6gretap now gets the IPV6_MIN_MTU floor instead of
IPV4_MIN_MTU.

Untagged traffic already behaves this way, so these changes are probably
intended. The previous patch in the series, "ip6_gre: classify the inner
packet once on transmit", has a "What changes for traffic that was not
broken before" section. Could this patch have a similar one?

>  		case htons(ETH_P_IP):
>  			memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
>  			prepare_ip6gre_xmit_ipv4(skb, dev, &fl6,
> @@ -1132,10 +1132,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
>  	if (err != 0) {
>  		/* XXX: send ICMP error even if DF is not set. */
>  		if (err == -EMSGSIZE) {
> -			if (skb->protocol == htons(ETH_P_IP))
> +			if (payload_protocol == htons(ETH_P_IP))
>  				icmp_ndo_send(skb, ICMP_DEST_UNREACH,
>  					      ICMP_FRAG_NEEDED, htonl(mtu));
> -			else
> +			else if (payload_protocol == htons(ETH_P_IPV6))
>  				icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);

[Severity: Medium]
Is the mtu reported here small enough for ip6erspan? VLAN-tagged IPv4
senders now receive it too.

In ip6_tnl_xmit(), the only tunnel header subtracted from the advertised
value is the GRE header, via t->tun_hlen:

	mtu = dst6_mtu(dst) - eth_hlen - psh_hlen - t->tun_hlen;
	...
	if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
		*pmtu = mtu;
		err = -EMSGSIZE;

ip6erspan_calc_hlen() sets tun_hlen to 8 and counts the ERSPAN header
only in t->hlen:

	tunnel->tun_hlen = 8;
	tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
		       erspan_hdr_len(tunnel->parms.erspan_ver);

By the time ip6_tnl_xmit() runs, ip6erspan_tunnel_xmit() has already
pushed the ERSPAN and GRE headers. ip6gre_xmit_classify() has also put
the network header behind the tags, at depth = ETH_HLEN + 4 * n_tags.

So the length check passes only when the inner IP length is at most
mtu - erspan_hdr_len - 4 * n_tags. Yet icmp_ndo_send() and
icmpv6_ndo_send() advertise mtu itself, and
skb_dst_update_pmtu_no_confirm() caches that same value on the inner
route.

A sender that honours this Frag Needed or Packet Too Big would shrink
its packets to mtu, get rejected again with the same mtu, and never
converge. Wouldn't packets in the window
(mtu - erspan_hdr_len - 4 * n_tags, mtu] be black-holed?

The test result in the commit message looks like an example of this:

  "Each error quoted the original Echo Request and advertised MTU 1338."

With that path MTU, the largest inner packet that passes the check seems
to be 1330 bytes for v1 without a tag, and 1326 bytes for v1 with one
802.1Q tag.

The ERSPAN header part already affected untagged traffic before this
patch. The tag bytes part is new exposure for tagged IPv4 on ip6erspan.

>  		}
>  

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202123613.1708463-1-littlesmilingcloud%40gmail.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-03 12:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:36 [PATCH net-next v8 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
2026-12-02 12:36 ` [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
2026-12-02 12:36 ` [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
2026-12-03 12:38   ` netdev-bot+sashiko
2026-12-02 12:36 ` [PATCH net-next v8 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
2026-12-03 12:39   ` netdev-bot+sashiko
2026-12-02 12:36 ` [PATCH net-next v8 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
2026-12-03 12:39   ` netdev-bot+sashiko
2026-12-02 12:36 ` [PATCH net-next v8 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Anton Danilov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox