Re: [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets

From
sashiko-bot@kernel.org
Date
2026-12-05 04:01:53
Reply to
Showta Ishizaki, 2026-12-04
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] net: virtio: unchecked uh->len and LCO padding mismatch in
  outer csum
- [Low] net: virtio: IPv6 outer UDP csum ignores active Routing Header
  daddr
- [Low] net: virtio: lco_csum() miscomputes outer csum on odd inner_th -
  outer_th
- [Low] net: virtio: redundant outer header parsing in
  virtio_net_tnl_set_outer_csum()
--

commit 3a617a73c8dde395774db7194e8a070983df80c7
Author: Showta Ishizaki [off-list ref]

net: virtio: compute the outer checksum of non-GSO tunnel packets

This commit adds virtio_net_tnl_set_outer_csum() to compute the outer
UDP checksum for non-GSO tunnel packets with
VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM, either via local checksum offload
while CHECKSUM_PARTIAL or by summing the datagram in full after software
inner checksum completion.
quoted hunk ↗ jump to hunk
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 714b20acd38f0..6fe0c59217175 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
[ ... ]
quoted hunk ↗ jump to hunk
@@ -553,6 +555,72 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
 	return ip_proto == IPPROTO_UDP && outer_th == thoff;
 }
[ ... ]
quoted hunk ↗ jump to hunk
+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;
[Severity: Low]
This isn't a bug, but virtio_net_tnl_offsets_ok() has already run both
virtio_net_l3_start() and virtio_net_l4_start() for this packet, and
thoff and ip_proto are unused here.  Returning nhoff from
virtio_net_tnl_offsets_ok() and passing it in would avoid repeating the
outer header walk.

Similarly, virtio_net_hdr_tnl_to_skb() sets SKB_GSO_UDP_TUNNEL_CSUM or
SKB_GSO_UDP_TUNNEL in gso_type unconditionally and then immediately
clears them when !skb_is_gso(skb).
quoted hunk ↗ jump to hunk
+
+	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);
[Severity: Low]
Can lco_csum() miscompute the outer checksum when inner_th - outer_th is
odd?

virtio_net_hdr_tnl_to_skb() allows an odd inner_nh_offset, which makes
skb_checksum_start(skb) - skb_transport_header(skb) odd.  lco_csum()
passes that length to csum_partial(), which requires even lengths for
non-final chunks and otherwise folds the inner checksum complement at
the wrong byte parity.
quoted hunk ↗ jump to hunk
+	} else {
+		/* Sum the datagram alone: uh->len, not skb->len - outer_th,
+		 * which also counts non-zero Ethernet padding and so
+		 * miscomputes the outer checksum.  len is from the frame,
+		 * so bound it before reading that many bytes.
+		 */
+		if (len < sizeof(*uh) || len > skb->len - outer_th)
+			return -EINVAL;
+		csum = skb_checksum(skb, outer_th, len, 0);
+	}
[Severity: Medium]
Should the uh->len bounds check also run on the CHECKSUM_PARTIAL path,
before uh->check is cleared?  An untrusted frame with an invalid uh->len
currently bypasses the check and gets a bogus outer UDP checksum instead
of -EINVAL.

Also, when a small tunnel packet has non-zero Ethernet padding
(skb->len > outer_th + len), does lco_csum() produce the wrong outer
checksum?  skb_checksum_help() and TX offload sum through skb->len, so
the padding breaks LCO cancellation and causes receiver drops.

Validating uh->len before mutating uh->check and either requiring
outer_th + len == skb->len for LCO or falling back to completing the
inner checksum and summing [outer_th, outer_th + len) would handle both
cases.
quoted hunk ↗ jump to hunk
+
+	if (outer_isv6) {
+		const struct ipv6hdr *ip6h = (void *)(skb->data + nhoff);
+
+		uh->check = udp_v6_check(len, &ip6h->saddr, &ip6h->daddr,
+					 csum);
+	} else {
[Severity: Low]
Does udp_v6_check() use the wrong destination address when the outer
IPv6 packet carries an active Routing Header (segments_left > 0)?

virtio_net_l4_start() calls ipv6_find_hdr() with target -1, which walks
past NEXTHDR_ROUTING regardless of segments_left.  Using ip6h->daddr
instead of the final destination address from the Routing Header
violates RFC 8200 Section 8.1 and causes drops at the final destination.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=5
Thread (14 messages) 14 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help