linux-um archives
 help / color / mirror / Atom feed
From: Chris Arges <carges@cloudflare.com>
To: Showta Ishizaki <zakinko@snowrabbit.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	netdev@vger.kernel.org, "Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"Simon Horman" <horms@kernel.org>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Paulos Yibelo" <habte.yibelo@gmail.com>,
	"Björn Töpel" <bjorn@kernel.org>,
	virtualization@lists.linux.dev, linux-um@lists.infradead.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH RFC net v9 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets
Date: Wed, 2 Dec 2026 15:06:38 -0600	[thread overview]
Message-ID: <axB_NPcujvScN_OI@20HS2G4> (raw)
In-Reply-To: <20261202.rfcv9.41657.5.zakinko@snowrabbit.org>

On 2026-12-02 13:00:00, Showta Ishizaki wrote:
> A packet may be tagged as UDP tunnel GSO and still be too small to
> segment. Then nothing consumes the pseudo-header seed the sender left in
> the outer UDP checksum. The GSO layer is not run, and transmit checksum
> offload completes only the inner checksum, so the seed goes out as the
> outer checksum.
> 
> Zeroing it is not an option either: IPv6 receivers drop a zero UDP
> checksum unless the tunnel opted in (RFC 6935, RFC 6936).
> 
> Compute the outer checksum when VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM asks
> for one: with local checksum offload while the inner checksum is still
> partial, or by a full sum once the inner one was completed in software
> because its metadata did not match the packet. Such packets no longer
> need to be dropped.
> 
> The addresses come from the outer header in the frame and the length
> from the UDP header. udp_set_csum() is not used: it is built with
> CONFIG_INET, which virtio_net does not depend on.
> 
> Fixes: a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
> Suggested-by: Willem de Bruijn <willemb@google.com>
> Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
> ---
>  include/linux/virtio_net.h | 105 ++++++++++++++++++++++++++++++++++---
>  1 file changed, 98 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index 714b20acd38f..9fb71a5ee991 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -8,8 +8,10 @@
>  #include <linux/netdevice.h>
>  #include <linux/udp.h>
>  #include <net/ip.h>
> +#include <net/ip6_checksum.h>
>  #include <net/ipv6.h>
>  #include <net/tcp.h>
> +#include <net/udp.h>
>  #include <uapi/linux/tcp.h>
>  #include <uapi/linux/virtio_net.h>
>  
> @@ -553,6 +555,64 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
>  	return ip_proto == IPPROTO_UDP && outer_th == thoff;
>  }
>  
> +/* Fill in the outer UDP checksum of a tunnel packet that is not GSO.
> + * While the inner checksum is still CHECKSUM_PARTIAL this is local
> + * checksum offload, as udp_set_csum() does for udp_tunnel_xmit_skb(),
> + * and needs the transport header at @outer_th.  Once the inner
> + * checksum has been completed the datagram is summed in full.
> + *
> + * The pseudo-header comes from the frame, not from the seed the sender
> + * put in uh->check: the addresses of the outer IP header and the
> + * length of the UDP header, which skb->len exceeds when the frame is
> + * padded.
> + *
> + * udp_set_csum() itself is not used: it is built with CONFIG_INET,
> + * which virtio_net does not depend on.
> + */
> +static inline int
> +virtio_net_tnl_set_outer_csum(struct sk_buff *skb, bool has_eth,
> +			      bool outer_isv6, unsigned int outer_th)
> +{
> +	unsigned int thoff;
> +	struct udphdr *uh;
> +	int ip_proto, nhoff;
> +	__be16 proto;
> +	__wsum csum;
> +	int len, err;
> +
> +	/* virtio_net_tnl_offsets_ok() has passed; this finds nhoff. */
> +	if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto) ||
> +	    !virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
> +		return -EINVAL;
> +
> +	err = skb_ensure_writable(skb, outer_th + sizeof(*uh));
> +	if (err)
> +		return err;
> +
> +	uh = (struct udphdr *)(skb->data + outer_th);
> +	len = ntohs(uh->len);
> +	uh->check = 0;
> +	if (skb->ip_summed == CHECKSUM_PARTIAL)
> +		csum = lco_csum(skb);
> +	else
> +		csum = skb_checksum(skb, outer_th, skb->len - outer_th, 0);

After doing some testing, I found that non-zero Ethernet padding causes
full-checksum fallback to product incorrect outer UDP checksums. I was able
to fix my tests with this change:
```
	if (skb->ip_summed == CHECKSUM_PARTIAL) {
 		csum = lco_csum(skb);
	} else {
		if (len < sizeof(*uh) || len > skb->len - outer_th)
			return -EINVAL;
		csum = skb_checksum(skb, outer_th, len, 0);
	}
```


  reply	other threads:[~2026-12-02 21:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  4:00 [PATCH RFC net v9 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-02  4:00 ` [PATCH RFC net v9 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-12-02  4:00 ` [PATCH RFC net v9 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-12-02  4:00 ` [PATCH RFC net v9 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-12-02 21:06   ` Chris Arges [this message]
2026-12-02  4:00 ` [PATCH RFC net v9 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-12-02  4:00 ` [PATCH RFC net v9 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-02  4:00 ` [PATCH RFC net v9 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki

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=axB_NPcujvScN_OI@20HS2G4 \
    --to=carges@cloudflare.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=bjorn@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=habte.yibelo@gmail.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richard@nod.at \
    --cc=skhan@linuxfoundation.org \
    --cc=virtualization@lists.linux.dev \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=zakinko@snowrabbit.org \
    /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