🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #6

Re: [PATCH v3 net 0/3] net: always dissect GSO packets in __virtio_net_hdr_to_skb()

#6
From: Willem de Bruijn
Date: Wed, 07 Oct 2026 00:30
145 lines
15539 bytes
On Tue, Oct 6, 2026 at 8:18 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Oct 06, 2026 at 08:13:43PM -0400, Willem de Bruijn wrote:
> > On Tue, Oct 6, 2026 at 7:50 PM Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > On Tue, Oct 06, 2026 at 07:26:46PM -0400, Willem de Bruijn wrote:
> > > > On Tue, Oct 6, 2026 at 6:38 PM Michael S. Tsirkin <mst@redhat.com> wrote:
> > > > >
> > > > > On Thu, Oct 01, 2026 at 07:11:37PM +0000, Eric Dumazet wrote:
> > > > > > This series fixes a bypass of untrusted GSO flow dissection in
> > > > > > __virtio_net_hdr_to_skb() when VIRTIO_NET_HDR_F_NEEDS_CSUM is not set,
> > > > > > and adds a kselftest covering VLAN-tagged GSO packets without NEEDS_CSUM:
> > > > > >
> > > > > > - Patch 1 fixes __skb_flow_dissect(), which computes key_control->thoff
> > > > > >   with min_t(u16, ...). This truncates skb->len and returns a bogus small
> > > > > >   transport offset when skb->len modulo 65536 is smaller than the
> > > > > >   transport offset. Offsets that do not fit in the u16 thoff now fail the
> > > > > >   dissection instead of being silently truncated.
> > > > > >
> > > > > > - Patch 2 initializes skb->dev and skb->network_header before calling
> > > > > >   virtio_net_hdr_*_to_skb() in tun_get_user(), tun_xdp_one(),
> > > > > >   virtnet_receive_done(), and raw_verify_header(), removes the
> > > > > >   '&& skb->network_header' condition and the unvalidated
> > > > > >   'else if (gso_type)' fallback in __virtio_net_hdr_to_skb(), and moves
> > > > > >   virtio_net_hdr_match_proto() after skb_flow_dissect_flow_keys_basic()
> > > > > >   so it validates the dissected L3 protocol (keys.basic.n_proto) rather
> > > > > >   than the outer L2 protocol.
> > > > > >
> > > > > > - Patch 3 adds kselftests in tools/testing/selftests/net/tun.c verifying
> > > > > >   that VLAN-tagged (802.1Q) TCPv4 GSO packets without NEEDS_CSUM (both
> > > > > >   flags = 0 and flags = VIRTIO_NET_HDR_F_DATA_VALID) are accepted on a
> > > > > >   TAP device, that mismatched GSO types and truncated TCP headers without
> > > > > >   NEEDS_CSUM are rejected with -EINVAL, and that a 65540-byte frame is
> > > > > >   accepted.
> > > > > >
> > > > > > v3:
> > > > > >  - New patch 1: avoid u16 truncation of skb->len when computing thoff in
> > > > > >    __skb_flow_dissect(). Patch 2 makes tun_get_user() dissect IFF_TAP
> > > > > >    frames before eth_type_trans(), with skb->len up to 65549 for a GSO
> > > > > >    frame carrying a maximal IPv4 packet (Sashiko).
> > > > > >  - Patch 3: truncate the TCP header after 10 bytes so that the test
> > > > > >    requires the transport offset found by flow dissection, and add a
> > > > > >    65540-byte frame test (Sashiko).
> > > > > >  - Link to v2: https://lore.kernel.org/netdev/20260928144254.3361044-1-edumazet@kernel.org/
> > > > > >
> > > > > > v2:
> > > > > >  - Patch 2: drop the pre-dissection virtio_net_hdr_match_proto() check
> > > > > >    inside 'if (!skb->protocol)' so VLAN-tagged GSO frames without
> > > > > >    NEEDS_CSUM are not rejected before flow dissection (Michael S. Tsirkin).
> > > > > >  - Patch 2: clarify the changelog regarding why skb->network_header was 0
> > > > > >    in those callers and why skb_reset_mac_header() is dropped in
> > > > > >    tun_get_user() for IFF_TUN (Michael S. Tsirkin).
> > > > > >  - Patch 3: add selftest in tools/testing/selftests/net/tun.c based on
> > > > > >    Michael's reproducer.
> > > > > >  - Link to v1: https://lore.kernel.org/netdev/20260927195536.2489079-1-edumazet@google.com/
> > > > >
> > > > >
> > > > > Not without trepidation about the amount of stuff we are shoving
> > > > > into virtio_net_hdr_to_skb which, believe me or not, used to be 50 LOC
> > > > > of trivial code in 2019:
> > > >
> > > > Unfortunately that let through many bad packets and unintentional
> > > > (ab)uses of the API.
> > > >
> > > > The current state is the result of numerous fixes we had to apply
> > > > since then to protect the kernel. Generally there are two approaches:
> > > >
> > > > 1. make every reachable path in the kernel robust against unexpected
> > > > input. Frequently that means checks in the hot path that penalizes all
> > > > normal traffic, only to catch a bad actor or fuzzer. And it's not
> > > > straightforward to prove that all reachable paths are protected.
> > > > 2. strict input validation.
> > > >
> > > > With strict input validation from the start the checks could have been
> > > > simpler (hindsight is 20/20). Unfortunately, now we are stuck with
> > > > weird input (GSO without NEEDS_CSUM, skb protocol 0, encapsulation
> > > > headers, ..) that we now have to work around and try to not break,
> > > > that may or may not have real users.
> > > >
> > > > This patch actually makes the function simpler. By reducing the
> > > > differences between the various callers of the function. This is great.
> > > >
> > > > It sucks how complex this function has become, hopefully we can
> > > > find more such ways of making it simpler. The strict validation itself
> > > > is a good thing imho.
> > >
> > >
> > > Yes indeed. I have a vague idea how to do it: check some
> > > performance-critical types of packets and for the rest just calculate
> > > the checksum then and there.
> >
> > That sounds promising.
> >
> > Checksumming is only one of the risks. Segmentation is another.
>
> Same approach for segmentation would be great but how do we know how to
> segment at input?

gso_type?

The main issue I see is that we do not have a way to then process the
chain of segs. So maybe we cannot realistically do it at this stage.

Come to think of it, I previously considered this and ended up with
commit 121d57af308d ("gso: validate gso_type in GSO handlers")
instead.
Technical Details
Message-ID: <CAF=yD-Lz9KSJ8Z8Fz8EF_+nmN5ea9k00sweQvvR74HpGCGwVSA@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342125-linux-kernel-netdev=dewy.ru
References: <20261001191140.2818991-1-edumazet@kernel.org> <20261006183410-mutt-send-email-mst@kernel.org> <CAF=yD-K2Lq_TAbN0=vpRZQrcp_R9Vu4E7frixWeBO2ehBQHdiw@mail.gmail.com> <20261006194851-mutt-send-email-mst@kernel.org> <CAF=yD-KeGZFmcb4v1PMjhTZghTQgtCwSQqejne8qad0W5KaJBQ@mail.gmail.com> <20261006201729-mutt-send-email-mst@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342125-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v3 net 0/3] net: always dissect GSO packets in __virtio_net_hdr_to_skb()
Date: Tue, 6 Oct 2026 20:30:50 -0400
Organization: Usenet Network
Message-ID: <CAF=yD-Lz9KSJ8Z8Fz8EF_+nmN5ea9k00sweQvvR74HpGCGwVSA@mail.gmail.com>
References: <20261001191140.2818991-1-edumazet@kernel.org> <20261006183410-mutt-send-email-mst@kernel.org>
 <CAF=yD-K2Lq_TAbN0=vpRZQrcp_R9Vu4E7frixWeBO2ehBQHdiw@mail.gmail.com>
 <20261006194851-mutt-send-email-mst@kernel.org> <CAF=yD-KeGZFmcb4v1PMjhTZghTQgtCwSQqejne8qad0W5KaJBQ@mail.gmail.com>
 <20261006201729-mutt-send-email-mst@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="543228"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:squ6uYuXgmmrsMijlcx34uNjOt4= sha256:ZUdgtqUm4V1GKs1qaUApTK6MnlqD2TaVzlj/zKbldko=
	sha1:rH9+YfOM8F7Z4CA0rMKXZtyVpAw= sha256:xRsMLc2E0xOa998wVvDKZFWNvsI3GmfbMmYrgTzzeQk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id B309D10F093; Wed,  7 Oct 2026 03:31:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id l1VPmrhF1o3p;
	Wed,  7 Oct 2026 03:31:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-342125-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 6A9CB10F067; Wed,  7 Oct 2026 03:31:36 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id 2FB37606CDF; Wed,  7 Oct 2026 00:31:35 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A896277C88;
	Wed,  7 Oct 2026 00:31:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fTrGIDcP"
X-Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1DA5263F44
	for <netdev@vger.kernel.org>; Wed,  7 Oct 2026 00:31:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.128.173
X-ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791333092; cv=pass; b=Oze6SskLnhvy3bO/gBaBUjLoS7TKA/+6GsFOtFoUzWdpKv/wWEaVoPPJJVqW12HWLJYNyPSKqB50QWO+lcJl2mBN+TGx1mussety3twXFt5Ng5OBX+PKvaFQuTrs46jOa3NHkRd53ONM5PbdY2Lydyu5lgZjG1ldQ6t4Ih47Iew=
X-ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791333092; c=relaxed/simple;
	bh=niOAy71+vwLxeNDu7irEi8aD74bqAPYxK3A5TWs5LFs=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=P4ZpDp4HeJS3g5nOHoWqdlDMW+DPN/llkaLBhlKLOuMDWXbnw6eyZKjyXcd516anS4ruQ4h+uxwEb7XczpjBpcWovvlNYICam3qxUkxOKpBbyjposqvkDdFfZo9zDMjMFZ511YAzM6xIoJqjmbQVxp6uBwLjig9gw/oi5pNiNdQ=
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fTrGIDcP; arc=pass smtp.client-ip=209.85.128.173
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-8acda240937so12900107b3.3
        for <netdev@vger.kernel.org>; Tue, 06 Oct 2026 17:31:30 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1791333090; cv=none;
        d=google.com; s=arc-20260327;
        b=ha3J/1PyAEMcG7hiA18epMkCfEcYyUft+vE7RiNUxUrTFhytchfXHzMYXmis4bMyXj
         803HJK4lyDX0QsQb6apafQLjpDhixKeRcQ19cjsU1xJrQ7MfMBFqHLYLk6iLrmE8s362
         ldCW6QNv6TXLkq2jTpMNy2VN/10ggQqIVST4Jji22j9jq2z2W0N+hLfrm2xr9bGTUYWz
         dTu4p+34krfOczOnQ4NVcp3yJa2oT8ft7RFW9Pb4QI5um6wbsWuI6tJRkE8TcFjOWAlH
         14QNQ+pf7oEttJXZvcvrw9GttQ2PcKNsxUTohlamLjg0D0y5RNc9+5zZR6SUp+6QTHvH
         MpqQ==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:dkim-signature;
        bh=AXsj4IEY3ClB/Ign26yPSnLd9Ut+UmSEbaB0ddJSUPI=;
        fh=8zRtZHbmPfKVnzV1VCa8UNwoNCjx0yOj4TQZSYuRRsw=;
        b=rcp82pnA4rJhEwQoAAiVf3wSUZEhRo/8Ny+PAB49YKKpZ20AGffdwR7sQJSX0kFaVd
         xaJuiVbC+c1v7uz9ToZK5rj4fu6ttA905hOKppUpItmTKtDgjLfKEtlOMZFisnchn1D6
         Hw4dHIc6Paqyups46N99V4ydVmWcFkc3rfDXjran/wWZH5mTiRtnDV6+Sob+pyPQLPyI
         +bbOZqkGBixl6RL2OozsXqEKw/p9RVEIVky9ljIOIoz7GXr8fFnVfDq1zGKmEE8X37L4
         1j4QyM2qyt71q2cR/z1r6tqIABKEu535sraUhrdI3mzW5aGOk/OfBZBIx2f6cKmwoD6S
         rYIg==;
        darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1791333090; x=1791937890; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:cc:to:subject:message-id
         :date:from:in-reply-to:references:mime-version:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=AXsj4IEY3ClB/Ign26yPSnLd9Ut+UmSEbaB0ddJSUPI=;
        b=fTrGIDcPqmdTkWtbbOIfKzpS9/6BtWwMlN8HoZRnzcR14sFTRJt245r8BidGvh1bTj
         DuVVB9XaTGTuWgzJpP3DI/6AUUPOqc8B0T7t2ajg0lyIBhyYmhpeiozDdJ60L+3nh/7W
         T5Im8QWVXP7BnOamNgli/qEg2HIB7WwI5cxdvWVQ18Ox9MrZ+bg0Ykf2RC6R3prDY1Ze
         476yuhiAE/87NsCDcdzDzs0xpr04Svlh8jTDj80KGisifO9MvX6YAC5ARQE+SuAHIyyP
         CDb8IM8f1OJ7eIB5jLKL7nsq2yaFr4xJ0R3LFxX7sg47Tuu795biye7S3pwYkpKEnmWA
         Kdzg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1791333090; x=1791937890;
        h=content-transfer-encoding:content-type:cc:to:subject:message-id
         :date:from:in-reply-to:references:mime-version:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=AXsj4IEY3ClB/Ign26yPSnLd9Ut+UmSEbaB0ddJSUPI=;
        b=b+D/xJs0bweqvgL173wODxI4uWQFWF7NdKCKBV16MEJR+v2JHe6XLEIZ5YzLBRkxsl
         ssDqt+uVMC1rkGpSmXpgfACdnH/k3FLFiR1V6zHzr4eT1RLLFz+i2+21hBZqqPDLRiEc
         4jn2HIP8W/gydIFGe+XNPUoQllxzLtUDoZFF7chgny273JNKDQp+ywIeGjn/UR0mw/3h
         Y+eEikLO85gmRAx5js4iptGENoVgYk4+rR34qAPJO7891qVrBCcKS6vchacD/oOfjSOk
         aEObOLmVGGUAy619QXEMqn+X7817EVd/R9gG+6Cn2a3d4T1LHr0qcjzBLmQpCpYY8c70
         rNZw==
X-Forwarded-Encrypted: i=1; AKwUvByH5CImr2LbE0Lg6zOtD6u11wIJ6zt2Or2/ZhcnMBacEAUhge6YGY5/xl62hksn19YwR0qpRQA=@vger.kernel.org
X-Gm-Message-State: AFq9FYJOPOFTKRPNP557lDhwBk6ooauAAKrcyk6caDo9NTD3tuc3vGNq
	tTUzMaSkqSBf0OMB6bKgmdXGfV27gdHx2aWXpxqQmgeF+a5AaSNRt07y4Bnu3iwAZ6aOpXvY8NV
	EADzb5orr+mTZyMA4iRCv21hrs+Mrofg=
X-Gm-Gg: AYBFou3FQEi3FfOUu4UjbuhaLybUkbdxu9COTKGjiMujs4nq5bXl6M8FfBZ059kZRRC
	SBSgHHOv11EUbKYoYfSFGHkooxxiqM8hxCyIWuF+32/GLTROIhSVe+azX6fGThKsGs4dGb+adTk
	7fnwH0H3HwSA73O6mFIdFWYtaWP7UlMVJ9l2GPv9XnGWdvatKN377NbGOhVOZbKGbboxgsEyjgp
	/z2/ARMhKUVAymB0bhvZljcVVlPIwYI1JPewx3eUCaURajZNSQwYzXSuxWrbpU2LLsZvedMbwiO
	KyzsfwZ5ca0SPfkljbw0RKc5Dls8yVVObf3q31lUW3ZJG6txweYNbQj3AdzgwU4sgh/IbFiyfWF
	tOPUgeO8LRIKJ
X-Received: by 2002:a05:690e:1248:b0:675:34b8:78a2 with SMTP id
 956f58d0204a3-6790a3cf36bmr459923d50.92.1791333089372; Tue, 06 Oct 2026
 17:31:29 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <20261006201729-mutt-send-email-mst@kernel.org>
X-Gm-Features: AclHuK809EveqtCiNaq5e--JTY7ihVSrHlLis1D0XWamTBEJhvTEDYYOvl1CucQ
X-Cc: Eric Dumazet <edumazet@kernel.org>, "David S . Miller" <davem@davemloft.net>, 
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, 
	Willem de Bruijn <willemb@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, 
	edumazet@google.com