Re: [PATCH net-next v8 2/5] erspan: take the COS from the mirrored frame, not from the tunnel family
From: netdev-bot+sashiko
Date: Thu Dec 03 2026 - 07:39:12 EST
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@xxxxxxxxx>
[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