* [PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
2026-12-01 0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
@ 2026-12-01 0:59 ` Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 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-01 0:59 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 v7 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family
2026-12-01 0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
@ 2026-12-01 0:59 ` Anton Danilov
2026-12-03 3:59 ` netdev-bot+sashiko
2026-12-01 0:59 ` [PATCH net-next v7 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-01 0:59 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 b9754272b1c9..d31252090d87 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 726636d7815b..d8e239a96841 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* Re: [PATCH net-next v7 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family
2026-12-01 0:59 ` [PATCH net-next v7 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
@ 2026-12-03 3:59 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 3:59 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 "erspan: take the COS from the mirrored frame, not
from the tunnel family" fixes two old bugs in erspan_build_header()…
--
erspan: take the COS from the mirrored frame, not from the tunnel family
The patch adds a helper, erspan_frame_tos(). erspan_build_header() and
erspan_build_header_v2() now use it to read the TOS for the ERSPAN COS
field from the mirrored frame, not from the tunnel family. The helper
reads the two bytes with skb_header_pointer(), and the patch drops the
is_ipv4 argument and the stale forward declaration in ip_gre.c.
> erspan: take the COS from the mirrored frame, not from the tunnel family
>
> 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
[ ... ]
> - 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.
[ ... ]
> - 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 patch have Fixes: tags?
It fixes two old problems in erspan_build_header() and
erspan_build_header_v2() in include/net/erspan.h:
- For short non-IP frames, the ip_hdr(skb)->tos / ipv6_hdr(skb) read at
the network header is unbounded, and KMSAN reports it.
- The COS is wrong when the mirrored frame's family differs from the
tunnel's.
The previous patch in the series, "erspan: bound the VLAN tag read in
erspan_build_header{,_v2}()", has these tags:
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
Its message also says it depends on this patch:
With this patch and the next one, which bounds the remaining
read of this kind, the same frames give no report on erspan.
Without Fixes: tags here, stable selection could take only the first
patch. Stable kernels would then keep the uninitialized TOS read and the
wrong COS.
The old read can be reached on existing kernels. erspan_xmit() checks the
length only through pskb_inet_may_pull_reason(), and that pulls nothing
for a non-IP skb->protocol:
include/net/ip_tunnels.h:pskb_inet_may_pull_reason() {
...
default:
nhlen = 0;
}
return pskb_network_may_pull_reason(skb, nhlen);
}
Blame on the baseline shows where the two reads came from:
- the one in erspan_build_header() with a3222dc95ca7
- the one in erspan_build_header_v2() with f551c91de262
Would it work to use the same two Fixes: tags as the previous patch,
plus the commit that added the ip6erspan callers that pass is_ipv4 as
false? A note saying that this patch completes the syzbot fix could
also help.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201005941.1536429-1-littlesmilingcloud%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v7 3/5] ip6_gre: classify the inner packet once on transmit
2026-12-01 0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family Anton Danilov
@ 2026-12-01 0:59 ` Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
2026-12-01 0:59 ` [PATCH net-next v7 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Anton Danilov
4 siblings, 0 replies; 9+ messages in thread
From: Anton Danilov @ 2026-12-01 0:59 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 d8e239a96841..d7d7fd478200 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 4912b08228a1..868c49b97a8f 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 v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
2026-12-01 0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
` (2 preceding siblings ...)
2026-12-01 0:59 ` [PATCH net-next v7 3/5] ip6_gre: classify the inner packet once on transmit Anton Danilov
@ 2026-12-01 0:59 ` Anton Danilov
2026-12-03 3:59 ` netdev-bot+sashiko
2026-12-01 0:59 ` [PATCH net-next v7 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-01 0:59 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() picks the traffic class and the flow label to
inherit, the ERSPAN truncation bit and the ICMP error to send for a
packet that is too big by skb->protocol, and ip6_tnl_xmit() picks its
minimum MTU the same way. A VLAN-tagged frame therefore gets none of
that: its outer traffic class is 0 where ip6gretap inherits it, the
truncation bit is not set from its IP length, and an IPv4 packet behind
a tag gets an ICMPv6 Packet Too Big built from its IPv4 header.
Use the protocol that the previous patch works out on entry, behind the
tags. The header it stands for has been pulled and the network header
is on it.
Found by an AI code review agent on an earlier version of the previous
patch and confirmed in a VM on an unmodified kernel: an IPv4 packet
with TOS 0xb8 behind a VLAN tag, sent to ip6erspan v1 and v2 with
tclass inherit in each of the ways listed in the previous patch, goes
out with traffic class 0 before this patch and with 0xb8 after it;
untagged packets go out with 0xb8 before and after. The truncation
bit, the ICMP error and the minimum MTU were not measured.
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
net/ipv6/ip6_gre.c | 8 ++++----
net/ipv6/ip6_tunnel.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index d7d7fd478200..698cf1cdd4ab 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,7 +1132,7 @@ 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
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 868c49b97a8f..8ccc90333c99 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* Re: [PATCH net-next v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
2026-12-01 0:59 ` [PATCH net-next v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
@ 2026-12-03 3:59 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 3:59 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 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
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] ip6erspan_tunnel_xmit() (net/ipv6/ip6_gre.c:1135-1139) now
picks the Packet Too Big type with `if (payload_protocol ==…
- [Low] Switching the native-mode dispatch in ip6erspan_tunnel_xmit()
(net/ipv6/ip6_gre.c:1090) from skb->protocol to payload_protocol sends…
- [Low] The subject says the change is 'in ip6erspan', but the
ip6_tunnel.c hunk changes the shared ip6_tnl_xmit() MTU floor…
- [Low] The patch fixes misbehaviour that users can see in
ip6erspan_tunnel_xmit(), and the commit message says it was confirmed…
--
ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan
With this patch, ip6erspan_tunnel_xmit() uses the payload_protocol from
ip6gre_xmit_classify() instead of skb->protocol for VLAN-tagged frames.
That value now picks the traffic class, flow label, ERSPAN truncation bit
and ICMP error type. The patch makes the same change to the minimum MTU
floor in ip6_tnl_xmit().
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index d7d7fd4782001..698cf1cdd4ab6 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;
[Severity: Low]
Should this patch carry a Fixes: tag?
The commit message says the behaviour was confirmed in a VM. Tagged
frames went out with outer traffic class 0. The ERSPAN T bit was not set
from the inner IP length. An oversized IPv4 packet behind a tag got an
ICMPv6 Packet Too Big built from its IPv4 header.
The first and previous patches in this series each have two Fixes: tags,
but this one has none. Without a tag, stable selection has nothing that
links this change to the classify patch it depends on.
>
> - if (skb->protocol == htons(ETH_P_IPV6)) {
> + if (payload_protocol == htons(ETH_P_IPV6)) {
> int thoff;
>
[ ... ]
> @@ -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,
[Severity: Low]
This switch now sends tagged IPv4/IPv6 frames through
prepare_ip6gre_xmit_ipv4() and prepare_ip6gre_xmit_ipv6(). Before, they
went to the default arm, which only copied t->fl.u.ip6. The commit
message lists the traffic class, flow label, T bit and ICMP type. Doesn't
this also change a few other things for tagged frames?
The encap limit is now applied unless IP6_TNL_F_IGN_ENCAP_LIMIT is set:
prepare_ip6gre_xmit_ipv4() {
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
*encap_limit = t->parms.encap_limit;
...
}
As a result, ip6_tnl_xmit() pushes the 8-byte tunnel encapsulation limit
destination option and lowers its mtu by 8. With the iproute2 default
encap limit of 4, tagged frames now carry an extra destination options
header on the wire.
fl6.flowi6_mark now becomes t->parms.fwmark or skb->mark. It used to
be 0.
A statically configured tclass, ip6_tclass(t->parms.flowinfo), now
reaches the outer header. Before, dsfield was 0.
Tagged IPv6 frames also get two new drop paths:
- the inner saddr equals t->parms.raddr
- the inner TEL option has encap_limit 0, in which case
prepare_ip6gre_xmit_ipv6() also sends ICMPV6_PARAMPROB
Untagged ip6erspan traffic and tagged ip6gretap traffic already get all
of this, so the code itself looks fine. The previous patch listed its
side effects under "What changes for traffic that was not broken before".
Could this commit message mention these changes in the same way?
[ ... ]
> @@ -1132,7 +1132,7 @@ 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
[Severity: Medium]
Because of the catch-all else, every payload that is not IPv4 still gets
icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu). Is that intended?
Take a VLAN-tagged frame whose inner type is neither IPv4 nor IPv6, such
as MPLS, ARP or PPPoE behind a tag. ip6gre_xmit_classify() leaves
payload_protocol at the VLAN type and does not move the network header.
The comment on ip6gre_xmit_classify() says such frames are sent:
* as it is, with the
* network header left alone, and no field is taken from it.
icmp6_send() does not check the protocol. It reads the bytes at the
network header as an ipv6hdr, within the linear area, and sends the
Packet Too Big to hdr->saddr. Here hdr->saddr is just payload bytes. For
ICMPV6_PKT_TOOBIG, icmp6_send() also skips the multicast and
non-PACKET_HOST filter.
The mtu passed here can also be below IPV6_MIN_MTU. ip6_tnl_xmit()
clamps to IPV4_MIN_MTU when payload_protocol is not ETH_P_IPV6. For
example, the mtu can be around 1210-1218 when the outer path MTU is 1280.
The -EMSGSIZE check in ip6_tnl_xmit() does not depend on the protocol.
A large non-GSO tagged frame can therefore reach this path when the outer
path MTU is below the device MTU plus overhead.
For comparison, ip6gre_xmit_other() sends no ICMP for the same result,
and ipxip6_tnl_xmit() does nothing in its default case:
case IPPROTO_IPV6:
icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
break;
default:
break;
Untagged non-IP payloads already behaved this way before the series.
Since this hunk makes the ICMP family follow the real payload, should the
else become else if (payload_protocol == htons(ETH_P_IPV6))?
> diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
> index 868c49b97a8f9..8ccc90333c99e 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);
[Severity: Low]
The subject says "in ip6erspan", but every caller shares ip6_tnl_xmit().
Doesn't this hunk also change ip6gretap?
ip6gre_xmit_ipv6() already passes htons(ETH_P_IPV6) as payload_protocol
for VLAN-tagged IPv6 frames:
err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
&mtu, skb->protocol, htons(ETH_P_IPV6));
Before this patch, the floor for those frames came from the VLAN
skb->protocol, so it was IPV4_MIN_MTU. After it, the floor is
IPV6_MIN_MTU.
On ip6gretap, that changes when -EMSGSIZE and the ICMPv6 Packet Too Big
fire. It also changes the value passed to
skb_dst_update_pmtu_no_confirm().
For example, with an outer path MTU of 1280, a tagged IPv6 frame used to
get -EMSGSIZE at around 1218 bytes. Now it passes the check and the outer
IPv6 layer fragments it.
The new floor looks correct and matches untagged IPv6 on ip6gretap. Could
the commit message say that ip6gretap is affected too, given that it also
says the minimum MTU was not measured?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201005941.1536429-1-littlesmilingcloud%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v7 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags
2026-12-01 0:59 [PATCH net-next v7 0/5] ip6_gre, erspan: fix inner header handling for VLAN-tagged and short frames Anton Danilov
` (3 preceding siblings ...)
2026-12-01 0:59 ` [PATCH net-next v7 4/5] ip6_gre: go by the inner protocol behind VLAN tags in ip6erspan Anton Danilov
@ 2026-12-01 0:59 ` Anton Danilov
2026-12-03 3:59 ` netdev-bot+sashiko
4 siblings, 1 reply; 9+ messages in thread
From: Anton Danilov @ 2026-12-01 0:59 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 v7 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags
2026-12-01 0:59 ` [PATCH net-next v7 5/5] selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags Anton Danilov
@ 2026-12-03 3:59 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 3:59 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 tools/testing/selftests/net/ip6_gre_vlan_inherit.sh,
setup() and tunnel_create() ignore the exit status of every command…
--
selftests: net: add a test for ip6gretap and ip6erspan with VLAN tags
This adds ip6_gre_vlan_inherit.sh. It sends IPv4 and IPv6 packets with a
given TTL and TOS through ip6gretap and ip6erspan, with and without a VLAN
device on top of the tunnel. On the receiving side, tc flower and u32
check the inherited outer hop limit, traffic class and ERSPAN COS.
> 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 0000000000000..94aed82e9441c
> --- /dev/null
> +++ b/tools/testing/selftests/net/ip6_gre_vlan_inherit.sh
[ ... ]
> +setup()
> +{
> + setup_ns ns1 ns2 || exit "$ksft_skip"
> +
> + ip -n "$ns1" link add veth1 type veth peer name veth2 netns "$ns2"
[ ... ]
> + 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
[Severity: Medium]
What happens here if the tunnel cannot be created? The exit status of
this ip link add is not checked. The same is true of the clsact qdisc and
the flower and u32 filters in setup(), and of the VLAN, address and
neighbour commands below. The case statement above also has no default
branch. setup_ns is the only step whose failure is handled.
These steps can fail when CONFIG_IPV6_GRE is not built, when iproute2
does not know erspan_dir, erspan_hwid or encaplimit none, or when
cls_flower, cls_u32, act_gact or sch_ingress is missing.
In those cases test_kind() still goes on into send_and_check(). The
counters never increase, so each busywait in send_and_check() runs for the
full BUSYWAIT_TIMEOUT of 20 s. It does not sleep between polls, so it keeps
forking tc and jq the whole time:
tools/testing/selftests/net/lib.sh:busywait() {
local timeout_ms=$1; shift
loopy_wait : "$timeout_ms" "$@"
}
Would this give up to 24 FAIL lines saying "outer hop limit and traffic
class not inherited" or "COS not taken from the inner header"? That would
be about 8 minutes of busy-spinning and a non-zero exit, where a skip is
expected.
Could these setup steps be checked so that the test exits with $ksft_skip,
as it already does when setup_ns fails?
> + 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
[ ... ]
> + 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"
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201005941.1536429-1-littlesmilingcloud%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread