From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792799169; b=KnMmmdiwvWDsT9NUDFm+hVas8CccJBo7ejQv9zdCxCatjF2pwTBDXbkcEhsReH3+ZKq+ wX0W7X9kPP5CD4qRwrhevPzSPV509DstZboxa+5AUhWCqGaHzHb5o70E8JbvOadiyAdme AlAeaOBMP6RbMaApbXC+CIuvTj3JVRADJGHjvpSzmhJagha+wfzxqN2cnjKoYGtnTi8Cv 8eQ6lr/rW+cseWOFrjcvH6l8E7NwlS/XKDcNt6dzgSZik4IvxB0mb6lv28xHp2Fw0yjKK dx7IA2wxg/nDCUoIsgJqVOchm9k0PoyuzoTmi/br5lmhITGYSLAvr6ExUg9Cxh50reQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792799169; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Date:From: To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=O5btSrqleegX0p5ha9cygCby9IqJb3FwGDRdWPZ2zaI=; b=0TchOuELSP0UNZ/IPOuQcH6ZWDkgMqgg6v1Edvsy06BSBiv4/ZbAEOK152k7Txaic0G3 Rzc43JjZ05vTE2uHLNF+7v7nStpXQ/4b9QfkIYUuYrAzNKQBpj6+RNcSt55+HB95HEBVv Os9pbnBbsPnTkuKeCdqAPf1OkpIHrC8pnALmTly9Omp72vged1bW7advxV/Bs9oA2TNZU rU376sA1TlpjTYEN7mFbgL8m4XbHjALwKT+Ek3w6zVUpT8cs7Tmxu5RzB7I96CXF6aALY AxNW/KMpjnSMc+9Mg6p629Uv3HVMWbocsIC3lwAKrVPDD8e9gKdhJ6iKUalMtizMuJQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VHlN++zG; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=sIa10mhW; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4279D606A31B for ; Fri, 23 Oct 2026 23:46:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4279D606A31B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VHlN++zG; dkim=pass (2048-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=sIa10mhW DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792799167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O5btSrqleegX0p5ha9cygCby9IqJb3FwGDRdWPZ2zaI=; b=VHlN++zGfy1mwsOiBdYnmBLsB4sojylTejSLE/kuc5Akk33ecfs1En1h5WXbi8nCY4d38n TogfJ3YbeOxEO5AJnfub0jpplafpDzYvl4M5wPGfeLt169bPG6xhrAf8sZxB2DTW93Uxai J9J8F/eiSRkwLSXOEMsaisAI9ERO6xY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-B1a7HxxiOoSYzv4kSS91TQ-1; Fri, 23 Oct 2026 19:46:06 -0400 X-MC-Unique: B1a7HxxiOoSYzv4kSS91TQ-1 X-Mimecast-MFC-AGG-ID: B1a7HxxiOoSYzv4kSS91TQ_1792799165 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48dfdc0f491so731266f8f.1 for ; Fri, 23 Oct 2026 16:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1792799165; x=1793403965; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=O5btSrqleegX0p5ha9cygCby9IqJb3FwGDRdWPZ2zaI=; b=sIa10mhWJb9jedb2ALgc++Xo0G/4eTSlD+KEJM2CUAtP3c5YkVLdyK3yGIzz8yVj+/ J6yv7jktbVRzlvQI4+4eo0YrTnx0/nmEIM1EQwaDBQHWg+r9J2qDgsR7uEadZaOGfiMB uiSRkc2bM4YOGluGQunjWBrN4h98IkSR5Dct1b6EFrSKlmQLToaUDRCelXQchtcLpwV8 rvBnS4evi/VqrT3AG8+qORSkq0xL55ZEwcHbSO97IMch2hBmiH3zCqJHPTS7uKg/vUg9 rJgGgSyZVoVo2bhHwq9bsknmDB91ZreqC6pue9eQPL6UU80VdFsARrvHlWGCwyTtSHPx MzqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792799165; x=1793403965; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=O5btSrqleegX0p5ha9cygCby9IqJb3FwGDRdWPZ2zaI=; b=B5UXMNrI8Zof5h9EBoPBc6OgQ3GnQhOljPWghT3T9g/eaUjnXcw7odzOGO7Z88Hjjx eIk6qbeUa6QN73gmms+y0bXN/dJPtszMN1TL0DS4sTsswOe0x4lq5woxPmE+/R505cz3 6oH2jfUcJVeejZ7bRQPB/UVFBF99cqb4XB0D68haXuN3t/CUFhKJ+BRJttWeStvjPjnM NPE2ZZ+zTz00rSdqPjztOhiN6G93716zGW6pEmN85diJFct6LA0a5K5v/Hlw65gB8zYW g/3r3WJquGPsVpeJOdggqXhZB31+oTc66zz0Aa2/ynG0GJ2HhZr/xdvFIWGPUVi8QCRO RIJg== X-Gm-Message-State: AFq9FYJ5lYXIphocYewVwijUCXxuMmM8ywIf/AsnVcSBZyuXlPGBzDj9 mzE26RUI6BwxJ/kLZ8FVCsVrLzFR4tlbcr6zLxZsBesflRlhypjbEXr0Gqr7Lt2nuKSljHEdYEK q8Jgu8SG3c7GAXuaxYckI1ExDlwvTFWp+GyKfz4D9f7ZtD2snoT6mRyILVQNzmdNPlg== X-Gm-Gg: AYBFou15BPNKaVZUmR/7EL9DHz1VLIHqGvOCevbohSZOJpPah9/e+/QBHAQdzcMtGVP m9+7RgqmnfobLHrKNobqOEY5UO35c1RWJfvJzkDahlzi8pHb5QwSpKETpoMDenxERk2UcldrKfZ R/4VdGqnhHeqahcKcwJP3RDHyUpMfRnA+cGQcrCtJVyBnPHeW2SINT0xD2hSrCHkRt4kmOYA9rT RwhZiD8/I1TedqTUNkyRodj//NERcYCaZ1WqhEoqloP/jFMZuJKD2akKbO3L4XbGM7ZFW9RqSNF VFvzBOdcIBOiod0B+/U4sz9JqSJ6wcOR9xL/4aRFK3+RitTg4anrtXfaxOUafi245x4MN5Q= X-Received: by 2002:a05:600c:4f4f:b0:4a3:5a42:b29c with SMTP id 5b1f17b1804b1-4a35acbc00bmr6034905e9.26.1792799164678; Fri, 23 Oct 2026 16:46:04 -0700 (PDT) X-Received: by 2002:a05:600c:4f4f:b0:4a3:5a42:b29c with SMTP id 5b1f17b1804b1-4a35acbc00bmr6034755e9.26.1792799164158; Fri, 23 Oct 2026 16:46:04 -0700 (PDT) Received: from redhat.com ([2a06:c701:73f6:2400:30a8:9e33:7d82:c035]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a359fc1207sm12576005e9.1.2026.10.23.16.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2026 16:46:03 -0700 (PDT) Date: Fri, 23 Oct 2026 19:46:00 -0400 From: "Michael S. Tsirkin" To: Willem de Bruijn Cc: linux-kernel@vger.kernel.org, Chris Arges , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Phil Sutter , Jason Wang , Eugenio =?iso-8859-1?Q?P=E9rez?= , Xuan Zhuo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, virtualization@lists.linux.dev, Max Krasnyansky , Rusty Russell , Paulos Yibelo Subject: Re: [PATCH net v6 4/5] net: resolve uncommon partial checksums at ingress Message-ID: <20261023192005-mutt-send-email-mst@kernel.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Oct 23, 2026 at 03:37:48PM -0400, Willem de Bruijn wrote: > Michael S. Tsirkin wrote: > > As reported first by Paulos Yibelo (after which > > others, credited below, found more ways the bug can affect users) a > > virtio net header can place CHECKSUM_PARTIAL at any in-packet offset. > > If that state is retained, later checksum completion can modify the > > packet after protocol processing has made decisions from it. > > > > Let's fix that: let's validate csum_start and csum_offset and only keep > > CHECKSUM_PARTIAL when csum_start and csum_offset match a parsed TCP or > > UDP header, while handling VLAN headers, IPv4 options and IPv6 extension > > headers. Complete other non-GSO checksums immediately, before any > > protocol processing runs. > > > > We can't easily "complete the checksum" for GSO we don't recognize - GSO > > assumes knowledge of the protocol. We could segment ignoring the > > checksum then do whatever csum_start and csum_offset say, but that > > seems like an overkill for something that shouldn't happen. > > > > There's some risk here: > > - non-gso packets which can't be parsed get checksum calculated in > > software, adding performance overhead > > - gso packets which can't be parsed get dropped > > > > Note that for zero copy, userspace can change the data after the > > checksum has been calculated. This is fundamental to zero copy by > > design, and the only outcome is a bad checksum and a packet drop. > > > > To mitigate the risks, the following patch will add a sysctl knob to > > bypass the resolution. This is reasonable if the setup is such that > > there is no protocol processing at all. > > > > UDP tunnel headers get the same handling on the inner header. > > > > Packets without VIRTIO_NET_HDR_F_NEEDS_CSUM are unaffected. > > > > Reported-by: Paulos Yibelo > > Reported-by: Chris Arges > > Tested-by: Chris Arges > > Fixes: f43798c27684 ("tun: Allow GSO using virtio_net_hdr") > > Suggested-by: Willem de Bruijn > > Signed-off-by: Michael S. Tsirkin > > A few comments inline. All but one cosmetic. Feel free to ignore > those. Please do review the comment from an LLM about the tunnel. > Aside from that LGTM. > ... > > @@ -368,7 +637,20 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, > > skb->inner_mac_header = inner_nh + skb_headroom(skb); > > skb->transport_header = outer_th + skb_headroom(skb); > > skb->encapsulation = 1; > > - return 0; > > + > > + if (!skb_is_gso(skb)) > > + skb_shinfo(skb)->gso_type &= ~(SKB_GSO_UDP_TUNNEL_CSUM | > > + SKB_GSO_UDP_TUNNEL); > > + > > + /* > > + * We know VIRTIO_NET_HDR_F_NEEDS_CSUM was set so __virtio_net_hdr_to_skb > > + * set CHECKSUM_PARTIAL. > > + */ > > + if (virtio_net_csum_partial_ok_at_offset(skb, gso_inner_type, inner_nh, > > + inner_proto)) > > + return 0; > > + > > + return __virtio_net_resolve_csum_partial_mismatch(skb); > > Allowing `!skb_is_gso(skb)` packets through `virtio_net_hdr_tnl_to_skb()` > has a few issues: > > 1. When `!skb_is_gso(skb)` and `virtio_net_csum_partial_ok_at_offset()` > returns false, `__virtio_net_resolve_csum_partial_mismatch()` completes > the checksum in software and lets the packet pass, but `skb->encapsulation`, > `skb->inner_protocol`, `skb->inner_transport_header`, > `skb->inner_network_header`, and `skb->inner_mac_header` have already > been populated with the unvalidated `inner_th` (`csum_start`) and > `inner_nh` offsets (unlike `virtio_net_hdr_to_skb()`, which restores > `skb->transport_header`). Oh right. Hmm. I can just run the check first. > 2. If `!skb_is_gso(skb)` and `VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM` is set, > clearing `SKB_GSO_UDP_TUNNEL_CSUM` drops the outer UDP checksum request, > since a non-GSO skb can only carry a single `CHECKSUM_PARTIAL` offset > (at `inner_th`). Right. But it works! Because the checksum is 0 then. I'll ponder what is best. > 3. On RX, a non-GSO UDP packet with `CHECKSUM_PARTIAL` at `inner_th` causes > `skb_csum_unnecessary()` (`skb_checksum_start_offset(skb) >= 0`) to treat > the outer UDP checksum as already validated. > > Unlike plain GSO (commit 7c6d2ecbda83), UDP tunnel offload is modern-only and > explicitly requires GSO (`/* The UDP tunnel must carry a GSO packet, but no UFO. */`). > Why not reject `!skb_is_gso(skb)` right after `__virtio_net_hdr_to_skb()`, and > return `-EINVAL` directly if `!virtio_net_csum_partial_ok_at_offset()`? This will break apps, I think. See 7c6d2ecbda83 -- MST