Article View: linux.kernel.netdev
Article #15029Re: [PATCH net v6 3/3] net: virtio: validate outer protocol of UDP tunnel GSO packets
From: Eric Dumazet
Date: Thu, 12 Nov 2026 09:46
Date: Thu, 12 Nov 2026 09:46
186 lines
16190 bytes
16190 bytes
Le mer. 11 nov. 2026 à 23:41, <netdev-bot+sashiko@kernel.org> a écrit :
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0
>
> 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).
>
> - [Medium] The new has_eth=false path in virtio_net_hdr_tnl_to_skb()
> (include/linux/virtio_net.h) rejects almost every valid frame, so it…
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but it is a
> sibling of the injection the patch closes.
>
> --
>
> net: virtio: validate outer protocol of UDP tunnel GSO packets
>
> This patch makes virtio_net_hdr_tnl_to_skb() check that a UDP tunnel GSO
> frame really carries the outer IPv4 or IPv6 header it claims, with UDP at
> outer_th_offset. Callers now pass a has_eth argument that says whether the
> frame starts with an Ethernet header. tun_get_user() passes false for
> IFF_TUN devices.
>
> Link: https://lore.kernel.org/netdev/93d0e37c99711bebdf60c120af03010455c2f2e2.1793276116.git.mst@redhat.com/
>
> > diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> > index d1fcb25ab026b..ced5a1596e609 100644
> > --- a/drivers/net/tun.c
> > +++ b/drivers/net/tun.c
> > @@ -1950,7 +1950,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
> > break;
> > }
> >
> > - if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) {
> > + if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr,
> > + (tun->flags & TUN_TYPE_MASK) == IFF_TAP)) {
> > atomic_long_inc(&tun->rx_frame_errors);
> > err = -EINVAL;
> > goto free_skb;
>
> [ ... ]
>
> > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > index 83f801ff57006..fc9667176f23c 100644
> > --- a/include/linux/virtio_net.h
> > +++ b/include/linux/virtio_net.h
>
> [ ... ]
>
> > @@ -338,6 +504,9 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
> > if (ret)
> > return ret;
> >
> > + if (!virtio_net_tnl_offsets_ok(skb, has_eth, outer_isv6, outer_th))
> > + return -EINVAL;
> > +
>
> [Severity: Medium]
> Can the has_eth == false path be reached by ordinary IFF_TUN frames?
>
> On IFF_TUN, tun_get_user() resets the network header to offset 0 and now
> passes has_eth == false. virtio_net_l3_start() then takes the L3 header
> from skb_network_offset(), so virtio_net_tnl_offsets_ok() needs outer_th
> to be 20 for a plain IPv4 outer header, or 40 for plain IPv6.
>
> Earlier in virtio_net_hdr_tnl_to_skb(), the offset floor still assumes a
> 14-byte Ethernet header, whatever has_eth says:
>
> outer_l3min = ETH_HLEN + virtio_l3min(outer_isv6);
> ...
> if (outer_th < outer_l3min ||
> inner_nh < outer_th + sizeof(struct udphdr) ||
> inner_th < inner_nh + inner_l3min)
> return -EINVAL;
>
> So an outer_th of 20 or 40 fails against 34 or 54 before the new check
> runs. The only IFF_TUN frames that can pass both checks have IPv4 options
> (ihl >= 9) or at least 14 bytes of IPv6 extension headers.
>
> On the TX side, virtio_net_hdr_tnl_from_skb() computes outer_th relative
> to skb->data:
>
> outer_th = skb->transport_header - skb_headroom(skb) + vlan_hlen;
>
> On IFF_TUN, skb->data points at the IP header, so this emits 20 or 40.
> set_offload() also enables NETIF_F_GSO_UDP_TUNNEL without checking the
> device type. As a result, IFF_TUN devices advertise tunnel GSO, but their
> ordinary tunnel GSO frames get -EINVAL and increment rx_frame_errors.
>
> The ETH_HLEN floor predates this patch and comes from a2fb4bc4e2a6.
> However, the commit message relies on the has_eth == false path:
>
> "tun_get_user() passes whether the device is IFF_TAP."
>
> Should outer_l3min follow has_eth, for example:
>
> outer_l3min = (has_eth ? ETH_HLEN : 0) + virtio_l3min(outer_isv6);
Same answer as for v4 and v5: UDP tunnel GSO over IFF_TUN has never
worked since a2fb4bc4e2a6, and this series does not change that.
has_eth only makes sure IFF_TUN frames are not parsed as Ethernet.
Relaxing the floor enables a path that has never run. I prefer to do
that in a separate patch, with selftests covering IFF_TUN in both
directions, and not in this painful series.
>
> [Severity: High]
> This is a pre-existing issue, not one introduced by this patch, but it is
> closely related to the injection fixed here. Plain (non-tunnel) GSO
> frames return early and never reach the new check:
>
> gso_tunnel_type = hdr->gso_type & VIRTIO_NET_HDR_GSO_UDP_TUNNEL;
> if (!gso_tunnel_type)
> return virtio_net_hdr_to_skb(skb, hdr, little_endian);
>
> In __virtio_net_hdr_to_skb(), the VIRTIO_NET_HDR_F_NEEDS_CSUM branch only
> checks pskb_may_pull(), skb_partial_csum_set() and the transport offset
> against nh_min_len. virtio_net_hdr_match_proto() and the flow dissector
> run only in the branch without NEEDS_CSUM.
>
> So can a tap writer, or a guest via vhost-net, still send an Ethernet
> frame with ethertype ETH_P_NSH, gso_type TCPV4, TCPV6 or UDP_L4, and
> NEEDS_CSUM set? eth_type_trans() would then set skb->protocol to
> ETH_P_NSH.
>
> Suppose such a frame is forwarded, by a bridge or tc mirred, to a device
> that segments in software. Could the segmentation then recurse without
> limit?
>
> skb_mac_gso_segment()
> nsh_gso_segment()
> proto = tun_p_to_eth_p(nsh_hdr(skb)->np); /* TUN_P_NSH -> ETH_P_NSH */
> __skb_pull(skb, nsh_len);
> skb->mac_len = proto == htons(ETH_P_TEB) ? ETH_HLEN : 0;
> skb_mac_gso_segment()
> nsh_gso_segment()
> ...
>
> Neither nsh_gso_segment() nor skb_mac_gso_segment() limits the depth.
> Commit 006c8b834aed ("net: gso: limit recursive IP-in-IP segmentation")
> added the SKB_GSO_CB(skb)->recursion_counter check in
> gso_recursion_inc_test(). It is called only from inet_gso_segment() and
> ipv6_gso_segment().
>
> A frame of about 64KB made of stacked 8-byte NSH headers could recurse
> thousands of levels deep and overflow the kernel stack.
> TUN_P_ETHERNET -> ETH_P_TEB -> NSH appears to be a second route into the
> same recursion.
>
> Should nsh_gso_segment() use gso_recursion_inc_test()? Or should the
> plain NEEDS_CSUM path also validate the outer protocol?
This one looks real, and is independent of this series:
nsh_gso_segment() can call itself through skb_mac_gso_segment() with
no depth limit, whatever the way the packet entered the stack.
I will send a separate fix for nsh_gso_segment(), with a selftest.
The remark on the changelog of patch 2 is noted, I do not plan to
respin for it.
Let's merge this series and move on.
Technical Details
Message-ID:
<CAL4WiipcxHnbZye9P8_NySU=pLfQoSrMWF3PahgSQvfeuOgmsA@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361670-linux-kernel-netdev=dewy.ruReferences:
<20261110213628.3476051-4-edumazet@kernel.org> <179443691180.2199510.148246238688217560@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361670-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6 3/3] net: virtio: validate outer protocol of UDP
tunnel GSO packets
Date: Thu, 12 Nov 2026 10:46:19 +0100
Organization: Usenet Network
Message-ID: <CAL4WiipcxHnbZye9P8_NySU=pLfQoSrMWF3PahgSQvfeuOgmsA@mail.gmail.com>
References: <20261110213628.3476051-4-edumazet@kernel.org> <179443691180.2199510.148246238688217560@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1057811"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:S59q60Igk/xjtR3d9M0vu29uss8= sha256:6JazmjnqYudhhiDMtqUnVzclKXTPCkL29GMhJnxPiVg=
sha1:DdDOBQY+2V2ZX7Ne0vK79nZb2Iw= sha256:rl3bwk3wBW/vnXmXWSMQhyWJYX0uTbi9j3f46zJ1u6A=
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 DD62C1141AA; Thu, 12 Nov 2026 13:14:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
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=kernel.org
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 GUb9ZhhlrBvc;
Thu, 12 Nov 2026 13:14:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361670-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id E7AE911418E; Thu, 12 Nov 2026 13:14:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 1EA4E147049; Thu, 12 Nov 2026 09:46:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794476792;
b=IMxwjHxtZM9YDkBzcBg2yv68VwGZBayrg3E77ULgKucDHJYnmyaektj/rEuwlLshcTK7
5gmAWf36ksG+ODNDX0bohEcW0U6jenGBM6Dkb16fTmUGeGtPO3jsltTgRj7gl/VuX3kIT
jy2J2PZE5z9wp5WvO35ct9f3IRPOtkXrr2/FHOIvM5OuO6+diiuTogEWFNhjlrFChhnrl
fpNf18Z5NnfxWpUigziv7PzMOPPHzkpXv1bbYj8Dvvc29yMf8vEzT1rwOfcY/IJI8xWZ0
7t66iidE4BJUtfNgzKEZGR8QE9J6vuCfW6MHXLLdcM2kA/VHUv+vaWxgfjWDaaMCBQQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794476792;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=j6eZ4aCZFTS/utwlBgKhOAgoPY6BL5WxRnVfSRhjSzs=;
b=Gp7vaA5stnT04aMhHgUU/dnSzVpneqMxoKjyP4hCgN7gLdBHnUv7JGPRhwVfP7+T2qOE
pepH0O1xzGXyCUlNg+JVmS/lgLmAk94+413I6WOH9jAlmMcox9sQT6ZH/ZFhhSvo2GcDS
A1x4JQZANE8jrjyniEtXmsCc6PI2ILzP/4jXV+ZOwg48Nj1lzt6b/xzmtbECi+to+0hZz
H5GdD52l7YcYc3tubS48t1iq0P2Ub4k7WMshwxiz3EmC1NGwXu5YQTlAJ8+kpFfdoeFwY
XsDB1o6sDs8jz/HUXEjyFupNPPHb3NulzWiqbUqbVV3Gs3v6F+XxEG868TohOLGjk3Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LzBOJKST;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id CBC13606A336;
Thu, 12 Nov 2026 09:46:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LzBOJKST
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794476792;
b=GZfFLoEz17EmxHJ0PEVxJ+qS6oI72NWOmxTBLNO6ZC9Wj5lCR8sXVpXuHucBI9Vy5vYp
D/Dal4Siz9qSbjVV6cTVmlUuTGcnfJCnbdzHH/y1abEgKJUMTkgI6QqYbZ6MSjzQKj4Ea
ySskDxqMwZajsb3r+cWwu8PUEztZr7NKPI8vs/psYsqcEL+kYDYWHczsUMahg5g9C7LO0
caEKMn2fUqOYa9XWsRRZEyG74+UABPGsq7wvXQM9R3OkFcIWCzqbNOAej4wrkL/5BBq0c
Cpp4XGVh8r2aJ0vnmD5kCgr5lq2HAhGv5y6sv58JkpDOcLax06BDznPLh1ZqnJbAs3Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794476792;
h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=j6eZ4aCZFTS/utwlBgKhOAgoPY6BL5WxRnVfSRhjSzs=;
b=MzlMWyMtFQciihDVCqfICMEDsmIfCvZQfR8A5HQZDCDOl51y2F3VRg92cnh0mwOVgScc
YokBtjyRh2uRWEEzxzVGqsQwzlmpO6/upXwmFPt04NcyNl473k2OGA53tX1YU2FPQ9j4+
g0g1lkCfPyNCiP0x1EERJU2esREn/Pmtmp/uY2t0K1qSjTqoN+qz2glY+52HGxBHGC3x+
nzrQZqNR+vKKLt58yKbxWZvGzYghopfwMUg//5lQ5xqpUeFk4tKKG288U5JWNTb2DzbPG
Zwke1sgKNiopRtb9LA5pKX8Q4aPMwvQg9Mn5pV8AM1IN1Q6Mfz3GJyJIx3QYwPwhn8Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LzBOJKST;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80E8606A323
for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 09:46:31 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 746701F00A0D
for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 09:46:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1794476791;
bh=j6eZ4aCZFTS/utwlBgKhOAgoPY6BL5WxRnVfSRhjSzs=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=LzBOJKST07DI6OhKR9d/bV/f+EcOgB7DduaD1YvU39zKFCS/rJIAybY5s0taxn405
uR/pdQZZhAznLyB7nOQ+cufnEQqKOpnC5K0IJVR8Oq4IxawDfO2+KxuFEU6KobDRy6
EOZWHtZNf+OLv0tNVW6jMaW/GWbjjOuzvORsPft5nBryny0+60SKlJ07TJjbTwzLEh
pjJBoCVwl/3jcz1gV6z+XyIygjzLHbRCaM5QXVTAEZLwQrWwdNKlLILuk1WzQEkX1d
ehaHHedwd+Iu1lXkg6DteBdRHuHqE488DOHu9T2Z0S4T/EYfciiaMdmLUIH0JkfTHM
TPz9SulQgW1vg==
X-Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-6df0b02fe91so512637eaf.0
for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 01:46:31 -0800 (PST)
X-Forwarded-Encrypted: i=1; AL+hErEZnWlwkBo3VIgYy10qlvQGlKeqVoeyoHsZBMoO+8OQ4Td3tE6iJmd9buUHM9pPFTGERcAyv0s=@vger.kernel.org
X-Gm-Message-State: APuU4Z8h/xf0wxoRfVXqpmNSf4404uSIwib5ZVm7CigMKtzr7Or5qdhU
NNRaU9KYV66qX9PaOhIVUS+xtvpbgcKXLmt2vX+zkbWFgMjQ/hKMcxxbmKFTUPJZ4RCz8aq1MnL
KFBXohY11ox5pwcZwlKQSXo+aTNHdLG4=
X-Received: by 2002:a05:6820:c2d1:20b0:716:f44b:2dcc with SMTP id
006d021491bc7-719740e76c8mr830715eaf.15.1794476790507; Thu, 12 Nov 2026
01:46:30 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <179443691180.2199510.148246238688217560@kernel.org>
X-Gmail-Original-Message-ID: <CAL4WiipcxHnbZye9P8_NySU=pLfQoSrMWF3PahgSQvfeuOgmsA@mail.gmail.com>
X-Gm-Features: AclHuK_cZ9ao9G0cYjqdJ9o0VFbuRHG2Gy61oDEJ6kFhBEJLvS-rEY_T6EP_Vvc
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, willemb@google.com, horms@kernel.org, mst@redhat.com,
jasowangio@gmail.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
hassansultan@google.com, virtualization@lists.linux.dev