This is v7 of "ip6_gre: use skb_vlan_inet_prepare() instead of
pskb_inet_may_pull()", a single patch for net through v6. It is now a
series for net-next.
The reviews of v4 to v6 kept finding the same thing from different
sides: on transmit ip6_gre works out what the frame carries in three
places, each by its own rule, and making one of them right moved the
problem to another. I asked about the scope in the v6 thread [1]. This
is the wider version: the packet is classified once, on entry to
ndo_start_xmit, and the result is passed down, to ip6_tnl_xmit() as
well.
The whole series grew out of Eric's original patch (v1 to v3 below).
Patch 3 still fixes the mismatch that patch fixed, at the same two call
sites, and carries his Suggested-by; the other patches are what testing
it turned up along the way.
The series targets net-next because it reworks the transmit path and
changes the exported ip6_tnl_xmit() interface to fix these long-standing
bugs together.
Patches 1 and 2 are about erspan_build_header() and
erspan_build_header_v2(), shared by erspan and ip6erspan:
- patch 1 bounds the VLAN tag read, which does not check that the
frame is long enough (syzbot report);
- patch 2 takes the TOS for the COS field as IPv4 or IPv6 by the
frame's own protocol rather than by the tunnel family, with bounded
reads.
Patch 3 is the classification in ip6gre_tunnel_xmit() and
ip6erspan_tunnel_xmit(): one length check and one answer, read from the
frame itself when skb->protocol is a VLAN type, and no second parse in
ip6_tnl_xmit() after the GRE header has been pushed. It closes the
second syzbot report and makes the hop limit of a VLAN-tagged frame
inherited on all ip6gretap and ip6erspan devices.
Patch 4 makes ip6erspan use that answer where it went by skb->protocol,
so that a tagged frame gets its traffic class inherited as well.
Patch 5 adds a selftest for the inherited hop limit and traffic class
and for the ERSPAN COS, with and without a VLAN tag.
The erspan patches and the ip6_gre ones are in one series because they
are about the same frames on the same transmit path.
Not in this series, for follow-ups:
- the IPv4 side: gre_tap_xmit() and erspan_xmit() have the same
mismatch between the check and the parsing, and ip_tunnel_xmit() and
ip_md_tunnel_xmit() the same parse after the push;
- ip_tunnel_rcv(), which sets the network header of a tagged frame on
the tag;
- an ip6gre device with ip6gre_header_ops takes the outer destination
from the packet in __gre6_xmit() without a length check;
- vxlan and geneve call skb_vlan_inet_prepare() on transmit for every
skb, which sets the network header on the VLAN tag for a frame that
comes from a VLAN device with reorder_hdr off.
This series was developed with LLM-based coding assistants (Claude Code
and Codex). They were used to write and revise the code and the changelogs,
to build and test the series in virtme-ng, and to review it before posting
with a local run of the Sashiko review prompts. I have reviewed every
change and every text and take responsibility for them.
Testing on net-next 5eb53a1fbf80, which includes the tunnel drop-reason
series, was repeated for both the base and this series in virtme-ng:
- the new selftest passes all 24 checks with the series; 10 fail on
the base;
- 16 existing networking selftest scripts pass on both, including
all 72 l2_tos_ttl_inherit checks;
- 264 functional scenarios per kernel reproduce the earlier results,
covering frame layouts, COS, mac_len and reorder_hdr;
- KMSAN probes cover 61 scenarios per kernel. With the series, only
the known IPv4 gretap short-frame case outside its scope still
reports an error. Both KMSAN builds needed the same test-only
objtool workaround in mm/Makefile and emitted a return-thunk warning
at boot, before the networking tests;
- all five intermediate commits build, including W=1 checks of the
affected networking objects. With CONFIG_INET=n, cls_flower.o builds
at every step and the final kernel builds as well.
The series was then rebased onto net-next 16f67342f619. The normal-kernel
selftests, the 264-scenario functional matrix, the intermediate builds
and the CONFIG_INET=n checks were repeated there with the same results.
The KMSAN results above are from 5eb53a1fbf80; KMSAN was not rerun after
this rebase.
Patch 2 retains the existing DSCP-to-COS mapping. For a VLAN protocol,
it uses the version nibble at the network header as a heuristic for IP;
this can also match a non-IP payload such as an MPLS label. Its COS is
not guaranteed to be zero or unchanged from the old implementation.
General non-IP classification and a new COS policy based on VLAN PCP,
MPLS TC or skb->priority are outside this series.
After changing patch 2 to read named IP header fields, I rebuilt patch 2
and the full series, including CONFIG_INET=n, and reran the new selftest,
gre_gso and the 52-case COS matrix. The full regression and KMSAN runs
described above predate that cleanup.
Changes since v6:
- a series for net-next instead of one patch for net;
- skb_vlan_inet_prepare() is not used any more. The review of v6
pointed out that it also moves a network header that is correct: a
VLAN device with reorder_hdr off leaves the tag in the frame and
skb->protocol as the inner protocol, and for a frame mirrored from
it v6 took the hop limit and the traffic class from the tag. Now the
frame is only looked into when skb->protocol is a VLAN type, and the
network header is only set when the tags lead to IPv4 or IPv6;
- the payload type behind the tags is read from the frame, from the
EtherType at offset 12, not from a depth given by skb->mac_len;
- ip6_tnl_xmit() gets the payload protocol from its caller instead of
parsing the packet after the GRE header has been pushed. This was
listed as a follow-up in v6;
- the two erspan_build_header() fixes, listed as a follow-up in v6,
come first as patches 1 and 2;
- new: ip6erspan uses the classified protocol (patch 4) and a selftest
(patch 5);
- the subject of the main patch says what it does now.
[1] https://lore.kernel.org/netdev/2026…@gmail.com/
v6: https://lore.kernel.org/netdev/2026…@gmail.com/
v5: https://lore.kernel.org/netdev/2026…@gmail.com/
v4: https://lore.kernel.org/netdev/2026…@gmail.com/
v3: https://lore.kernel.org/netdev/2026…@strlen.de/
v2: https://lore.kernel.org/netdev/2026…@google.com/
v1: https://lore.kernel.org/netdev/2026…@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 | 95 +++++++---
net/ipv6/ip6_tunnel.c | 11 +-
tools/testing/selftests/net/Makefile | 1 +
.../selftests/net/ip6_gre_vlan_inherit.sh | 172 ++++++++++++++++++
7 files changed, 308 insertions(+), 55 deletions(-)
create mode 100755 tools/testing/selftests/net/ip6_gre_vlan_inherit.sh
base-commit: 16f67342f6192f04fec94fa0c7a3ba03e7a24578
--
2.47.3