Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: julius@bairaktaris.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	dsahern@kernel.org, idosch@nvidia.com, willemb@google.com,
	ncardwell@google.com, kuniyu@google.com,
	steffen.klassert@secunet.com, nbd@nbd.name,
	jiayuan.chen@linux.dev, mfleming@cloudflare.com,
	almasrymina@google.com, bigeasy@linutronix.de,
	richardbgobert@gmail.com, ecree.xilinx@gmail.com,
	bsdhenrymartin@gmail.com
Subject: Re: [PATCH net v6 4/5] ipmr: set up GSO state for tunnel vifs
Date: Wed, 25 Nov 2026 15:15:15 +0000	[thread overview]
Message-ID: <179561971501.3135.8394313222349713065@kernel.org> (raw)
In-Reply-To: <ffd8ca7abd44882707fbca297889f6e43ced4a65.1795295554.git.julius@bairaktaris.de>

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

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

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).

- [High] The new filter in ipmr_prepare_xmit()
  (net/ipv4/ipmr.c:1964-1966) drops an encapsulated GSO packet only when…
- [Medium] ip_encap() (net/ipv4/ipmr.c:1873-1890) adds a new outermost
  IPv4 header with frag_off = 0 (DF clear) to a GSO skb, but leaves…
- [Medium] ipmr: skb_checksum_help() in ipmr_prepare_xmit() corrupts SCTP
  CRC32c
- [Low] The commit message says the encapsulated GRE and UDP-tunnel GSO
  packets the patch now drops were already lost before: 'without this…

--

ipmr: set up GSO state for tunnel vifs

This commit makes ip_encap() in net/ipv4/ipmr.c set up GSO state for
VIFF_TUNNEL vifs. It calls iptunnel_handle_offloads() and
skb_set_inner_ipproto(), reserves one outer IP ID per segment, and sets
the outer length with iph_set_totlen(). It also drops encapsulated GSO
packets without SKB_GSO_IPXIP4 in ipmr_prepare_xmit(), and completes the
pending checksum of encapsulated non-GSO packets before encapsulation.

> GRE
> and UDP tunnel aggregates do not: gre_gso_segment() and
> skb_udp_tunnel_segment() take the payload type from
> skb->inner_protocol. Drop those before the vif counts them; without
> this change ipip_gso_segment() dropped them, as they lacked
> SKB_GSO_IPXIP4.

[Severity: Low]
Is this accurate for devices that segment these packets in hardware?

It holds when the packet is segmented in software. Some NICs list
NETIF_F_GSO_GRE or NETIF_F_GSO_UDP_TUNNEL in hw_enc_features and accept
an outer IPPROTO_IPIP header in ndo_features_check. On those, the old
aggregate never reached ipip_gso_segment().

mlx5 is one example. Its hw_enc_features gets GSO_UDP_TUNNEL and
GSO_GRE, and only the _CSUM variants are in gso_partial_features.
mlx5e_tunnel_features_check() also keeps the features for an outer IPIP
header:

drivers/net/ethernet/mellanox/mlx5/core/en_main.c:mlx5e_tunnel_features_check() {
    ...
	case IPPROTO_IPIP:
	case IPPROTO_IPV6:
		if (mlx5e_tunnel_proto_supported_tx(priv->mdev, IPPROTO_IPIP))
			return features;
    ...
}

So netif_gso_ok() passed and the skb was handed to the hardware, which
most likely produced malformed segments.

On such hardware, the new early return in ipmr_prepare_xmit() changes
the result from transmitting to dropping. The drop also happens before
any vif, device or MIB counter is updated, so nothing records it.

Could the commit message describe this as a behaviour change on these
devices rather than a no-op for all of them?

> diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
> index 836f3f95b20c4..eae382a2fadb3 100644
> --- a/net/ipv4/ipmr.c
> +++ b/net/ipv4/ipmr.c
> @@ -1869,6 +1869,10 @@ static void ip_encap(struct net *net, struct sk_buff *skb,
>  	struct iphdr *iph;
>  	const struct iphdr *old_iph = ip_hdr(skb);
>  
> +	/* skb_cow() in ipmr_prepare_xmit() leaves no header to unclone */
> +	iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4);
> +	skb_set_inner_ipproto(skb, IPPROTO_IPIP);
> +
>  	skb_push(skb, sizeof(struct iphdr));
>  	skb->transport_header = skb->network_header;
>  	skb_reset_network_header(skb);
> @@ -1882,8 +1886,8 @@ static void ip_encap(struct net *net, struct sk_buff *skb,
>  	iph->saddr	=	saddr;
>  	iph->protocol	=	IPPROTO_IPIP;
>  	iph->ihl	=	5;
> -	iph->tot_len	=	htons(skb->len);
> -	ip_select_ident(net, skb, NULL);
> +	iph_set_totlen(iph, skb->len);
> +	ip_select_ident_segs(net, skb, NULL, skb_shinfo(skb)->gso_segs ?: 1);

[Severity: Medium]
What happens to SKB_GSO_TCP_FIXEDID and SKB_GSO_TCP_FIXEDID_INNER here?

These bits are positional. Documentation/networking/segmentation-offloads.rst
says "For encapsulated packets, SKB_GSO_TCP_FIXEDID refers only to the
outer header". tcp4_gro_complete() maps them as:

	BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID << 1 != SKB_GSO_TCP_FIXEDID_INNER);
	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4 |
			(NAPI_GRO_CB(skb)->ip_fixedid * SKB_GSO_TCP_FIXEDID);

inet_gso_segment() then computes:

	fixedid = !!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCP_FIXEDID << encap));

When fixedid is set, it does not increment the ID per segment.

ip_encap() adds a new outermost header with frag_off = 0, but it leaves
these bits as they are. Fixed IDs are common for TCP GRO aggregates:
DF packets get ID 0, and inet_gro_flush() sets ip_fixedid when the first
two IDs are equal.

For such an aggregate, doesn't the FIXEDID bit that described the
original header now apply to the new DF-clear ipmr header?

If so, every segment would carry the same outer IP ID with DF clear, and
the gso_segs IDs reserved by ip_select_ident_segs() would go unused. The
original header, now at encap level 1, would be segmented according to
FIXEDID_INNER, which described a different header. Nested IPXIP4
aggregates would shift the same way.

This seems to contradict "reserve one outer IP ID per segment as
iptunnel_xmit() does" in the commit message. Before this patch,
ipip_gso_segment() dropped these packets because they lacked
SKB_GSO_IPXIP4, so this is new behaviour.

>  	ip_send_check(iph);
>  
>  	memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
> @@ -1951,6 +1955,15 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
>  	}
>  
>  	if (vif->flags & VIFF_TUNNEL) {
> +		/* An encapsulated packet carries the inner headers of its
> +		 * own tunnel. Only IPXIP4 GSO packets nest: their IP headers
> +		 * are segmented by protocol field, while GRE and UDP tunnel
> +		 * segmentation read skb->inner_protocol, which ip_encap()
> +		 * sets for its own header.
> +		 */
> +		if (skb_is_gso(skb) && skb->encapsulation &&
> +		    !(skb_shinfo(skb)->gso_type & SKB_GSO_IPXIP4))
> +			return -1;

[Severity: High]
Can FOU and GUE aggregates get past this check and then be segmented
with the wrong inner protocol?

The check only rejects encapsulated GSO packets when SKB_GSO_IPXIP4 is
clear. fou_gro_receive() and gue_gro_receive() clear
NAPI_GRO_CB(skb)->encap_mark, so ipip or sit GRO can nest inside a UDP
tunnel aggregate:

  udp_gro_complete()
    gso_type |= SKB_GSO_UDP_TUNNEL(_CSUM), encapsulation = 1
  sit_gro_complete() / ipip_gro_complete()
    gso_type |= SKB_GSO_IPXIP4
  ipv6_gro_complete() / inet_gro_complete()
    skb_set_inner_protocol(skb, ETH_P_IPV6 or ETH_P_IP)

Such a packet has both UDP_TUNNEL and IPXIP4 set, so it passes this
check. ip_encap() then overwrites the recorded payload type:

	skb_set_inner_ipproto(skb, IPPROTO_IPIP);

skb_udp_tunnel_segment() in net/ipv4/udp_offload.c dispatches on that
field:

	case ENCAP_TYPE_IPPROTO:
		offloads = is_ipv6 ? inet6_offloads : inet_offloads;
		ops = rcu_dereference(offloads[skb->inner_ipproto]);

For FOU or GUE carrying 6in4 (ipproto 41), wouldn't this run
ipip_gso_segment() and inet_gso_segment() on the IPv6 header?

That would usually fail with -EINVAL and drop the packet after it has
been counted as sent. When the traffic class and source address bytes
happen to form a plausible ihl and protocol, malformed segments would be
built instead.

Before this patch, these aggregates segmented correctly in software. The
outer ipip_gso_segment() accepted them because sit had already set
IPXIP4, and skb_udp_tunnel_segment() dispatched on ETH_P_IPV6.

The comment above says UDP tunnel segmentation reads
skb->inner_protocol, which ip_encap() overwrites. Should the check reject
GSO packets that have any of SKB_GSO_GRE, SKB_GSO_GRE_CSUM,
SKB_GSO_UDP_TUNNEL or SKB_GSO_UDP_TUNNEL_CSUM set, instead of testing for
the absence of SKB_GSO_IPXIP4?

FOU carrying IPIP still works, but only because IPPROTO_IPIP happens to
be the right handler.

>  		rt = ip_route_output_ports(net, &fl4, NULL,
>  					   vif->remote, vif->local,
>  					   0, 0,

[ ... ]

> @@ -1985,6 +1998,17 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
>  		return -1;
>  	}
>  
> +	/* Complete the pending checksum of an encapsulated packet, as for
> +	 * a packet sent through an ipip device. This may reallocate the
> +	 * head: no pointer into it is used after this point.
> +	 */
> +	if ((vif->flags & VIFF_TUNNEL) && skb->encapsulation &&
> +	    !skb_is_gso(skb) && skb->ip_summed == CHECKSUM_PARTIAL &&
> +	    skb_checksum_help(skb)) {
> +		ip_rt_put(rt);
> +		return -1;
> +	}
> +
>  	WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1);
>  	WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len);
>  

[Severity: Medium]
Does this do the right thing for an encapsulated SCTP packet whose
CRC32c is still pending?

The comment and the commit message say this matches what happens to a
packet sent through an ipip device. validate_xmit_skb() does not call
skb_checksum_help() directly, though. It calls
skb_csum_hwoffload_help(), which checks for SCTP first:

	if (unlikely(skb_csum_is_sctp(skb)))
		return !!(features & NETIF_F_SCTP_CRC) ? 0 :
			skb_crc32c_csum_help(skb);

skb_checksum_help() has no such check. For a non-GSO skb with
encapsulation set, ip_summed == CHECKSUM_PARTIAL and csum_not_inet set,
it computes a 16-bit ones-complement sum and writes it at
csum_start + csum_offset. That overwrites half of the 32-bit SCTP
checksum field with the wrong algorithm. It sets ip_summed to
CHECKSUM_NONE but leaves csum_not_inet set. skb_crc32c_csum_help()
would have written the CRC32c and called skb_reset_csum_not_inet().

Such a packet can come from BPF encapsulation (bpf_skb_adjust_room(),
bpf_lwt_push_ip_encap()) or IPVS tunnel mode on a device that
advertises NETIF_F_SCTP_CRC. The receiver would then drop every one of
these packets on a bad CRC, after the vif and device counters have
recorded them as sent.

The trigger needs CAP_NET_ADMIN and an unusual setup, but this is new
behaviour added by the patch, and it does not match the parity the
comment claims.

Would calling skb_csum_hwoffload_help(skb, 0) here be the better fit?
That is what validate_xmit_skb() ends up doing for an encapsulated skb
on an ipip device. It falls through to skb_checksum_help() for the
non-SCTP case and dispatches SCTP to skb_crc32c_csum_help().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795295554.git.julius%40bairaktaris.de

  reply	other threads:[~2026-11-25 15:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 21:14 [PATCH net v6 0/5] ipmr: forward GSO multicast packets Julius Bairaktaris
2026-11-21 21:14 ` [PATCH net v6 1/5] net: gro: set the inner transport header of encapsulated fraglist packets Julius Bairaktaris
2026-11-21 21:14 ` [PATCH net v6 2/5] net: gso: segment fraglist packets with a software tunnel checksum Julius Bairaktaris
2026-11-25 15:15   ` netdev-bot+sashiko
2026-11-21 21:14 ` [PATCH net v6 3/5] net: gso: count the inner UDP header of encapsulated UDP GSO packets Julius Bairaktaris
2026-11-21 21:14 ` [PATCH net v6 4/5] ipmr: set up GSO state for tunnel vifs Julius Bairaktaris
2026-11-25 15:15   ` netdev-bot+sashiko [this message]
2026-11-21 21:14 ` [PATCH net v6 5/5] ipmr: do not drop GSO packets that fit the MTU after segmentation Julius Bairaktaris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179561971501.3135.8394313222349713065@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsdhenrymartin@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=julius@bairaktaris.de \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=mfleming@cloudflare.com \
    --cc=nbd@nbd.name \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardbgobert@gmail.com \
    --cc=steffen.klassert@secunet.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox