Article View: linux.kernel.netdev
Article #13282Re: [PATCH net v4 1/2] net: virtio: validate outer protocol of UDP tunnel GSO packets
From: Eric Dumazet
Date: Mon, 09 Nov 2026 16:24
Date: Mon, 09 Nov 2026 16:24
202 lines
16496 bytes
16496 bytes
Le lun. 9 nov. 2026 à 10:55, <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 · Medium: 1 · Low: 0 (1)
>
> 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 strict outer-offset check rejects UDP-tunnel GSO
> frames that the kernel's own tun TX path produces whenever the skb…
>
> Pre-existing issues:
> - [Low] In virtio_net_hdr_tnl_to_skb(), outer_l3min = ETH_HLEN +
> virtio_l3min(outer_isv6) (include/linux/virtio_net.h:491).
>
> --
>
> net: virtio: validate outer protocol of UDP tunnel GSO packets
>
> This commit makes virtio_net_hdr_tnl_to_skb() check that the frame's outer
> L3 protocol matches the declared tunnel type. It also checks that the outer
> UDP header sits exactly at outer_th_offset. Callers pass a new has_eth
> argument that says whether the frame starts with an Ethernet header. This
> closes a path where an arbitrary outer ethertype combined with
> SKB_GSO_UDP_TUNNEL could crash the host in skb_under_panic().
>
> Link: https://lore.kernel.org/netdev/93d0e37c99711bebdf60c120af03010455c2f2e2.1793276116.git.mst@redhat.com/
>
> > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > index d6466f96cdd00..b7b6b542f4763 100644
> > --- a/include/linux/virtio_net.h
> > +++ b/include/linux/virtio_net.h
>
> [ ... ]
>
> > @@ -282,9 +424,33 @@ static inline unsigned int virtio_l3min(bool is_ipv6)
> > return is_ipv6 ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
> > }
> >
> > +/* Do the tunnel offsets match the outer headers in the frame?
> > + * The L3 header the tunnel claims must be the one the frame
> > + * carries, with UDP following it at @outer_th.
> > + */
> > +static inline bool
> > +virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
> > + unsigned int outer_th)
> > +{
> > + int nhoff;
> > + __be16 proto;
> > + unsigned int thoff;
> > + int ip_proto;
> > +
> > + if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto))
> > + return false;
> > + if (outer_isv6 != (proto == htons(ETH_P_IPV6)))
> > + return false;
> > + if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
> > + return false;
> > +
> > + return ip_proto == IPPROTO_UDP && outer_th == thoff;
>
> [Severity: Medium]
>
> Can this exact match reject UDP tunnel GSO frames that tun itself produces
> when the skb carries a VLAN hwaccel tag?
>
> On the producer side, tun_put_user() writes the 802.1Q tag into the frame
> it copies to userspace or vhost-net. It calls tun_vnet_hdr_tnl_from_skb()
> with vlan_hlen = VLAN_HLEN. Only csum_start accounts for the tag:
>
> include/linux/virtio_net.h:virtio_net_hdr_from_skb() {
> ...
> hdr->csum_start = __cpu_to_virtio16(little_endian,
> skb_checksum_start_offset(skb) + vlan_hlen);
> ...
> }
>
> The tunnel offsets do not:
>
> include/linux/virtio_net.h:virtio_net_hdr_tnl_from_skb() {
> ...
> inner_nh = skb->inner_network_header - skb_headroom(skb);
> outer_th = skb->transport_header - skb_headroom(skb);
> vhdr->inner_nh_offset = cpu_to_le16(inner_nh);
> vhdr->outer_th_offset = cpu_to_le16(outer_th);
> ...
> }
>
> So outer_th_offset and inner_nh_offset both end up 4 bytes short of the
> real UDP and inner headers in the emitted frame.
>
> On the consumer side, with has_eth set, virtio_net_l3_start() walks the
> in-band VLAN tag with __vlan_get_protocol(). That gives nhoff = 18, so
> thoff points at the real UDP header (38 for IPv4). The emitted outer_th is
> 34, this comparison fails, and virtio_net_hdr_tnl_to_skb() returns -EINVAL.
>
> Before this patch the same frame was accepted. Only transport_header was
> off by 4, and ip_rcv_core() and ip6_rcv_core() reset it for local delivery.
>
> With this change, would a guest that gets these frames from a host tap
> drop them in virtnet_receive_done() as "bad gso" and bump
> rx_frame_errors? A tun/tap writer that re-injects frames it read from
> another tun would see the same rejection.
>
> This looks reachable with VLAN-tagged UDP tunnel GSO traffic. Two examples
> are a VLAN filtering bridge with a tagged egress port, and a vlan device on
> top of a tap. tun advertises NETIF_F_HW_VLAN_CTAG_TX/STAG_TX in
> hw_features and hw_enc_features, so the tag stays in hwaccel until
> tun_put_user().
>
> The later patch in this series, "tun: clear stale skb->protocol of NAPI
> frags skbs", does not seem to fix the producer side. Should
> virtio_net_hdr_tnl_from_skb() add vlan_hlen to outer_th_offset and
> inner_nh_offset, with that fix landing with or before this check?
>
Right. tun keeps the tag in hwaccel for UDP tunnel GSO packets, and only
csum_start accounts for it. The wrong offsets were already a bug: the
receiver set inner_network_header 4 bytes off, and a forwarded packet
segmented again would use the wrong inner headers.
v5 will add a patch before this one, so that virtio_net_hdr_tnl_from_skb()
adds vlan_hlen to both offsets.
> > +}
> > +
> > static inline int
> > virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
> > const struct virtio_net_hdr_v1_hash_tunnel *vhdr,
> > + bool has_eth,
> > bool tnl_hdr_negotiated,
> > bool tnl_csum_negotiated,
> > bool little_endian)
> > @@ -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: Low]
>
> This is a pre-existing issue, not one introduced by this patch, but does
> the has_eth = false path ever see ordinary IFF_TUN frames?
>
> Earlier in virtio_net_hdr_tnl_to_skb(), the minimum outer offset still
> assumes an Ethernet header, whatever has_eth says:
>
> outer_l3min = ETH_HLEN + virtio_l3min(outer_isv6);
> ...
> if (outer_th < outer_l3min ||
>
> For IFF_TUN, tun_get_user() passes has_eth = false and the network header
> is at offset 0. virtio_net_tnl_offsets_ok() therefore needs outer_th == 20
> for plain IPv4 or 40 for plain IPv6. Both values are below the 34/54 floor,
> so these frames are rejected before the new check runs.
>
> That leaves the !has_eth branch of virtio_net_l3_start() reachable only for
> outer IPv4 with at least 16 bytes of options, or outer IPv6 with at least
> 16 bytes of extension headers. The L3-relative offsets produced by tun TX
> and by the selftest helper build_virtio_net_hdr_v1_hash_tunnel()
> (eth_hlen = 0 for !is_tap) are still rejected.
>
> The ETH_HLEN floor dates from a2fb4bc4e2a6. Now that callers pass has_eth,
> should outer_l3min depend on it?
>
This predates this series: UDP tunnel GSO over IFF_TUN has never worked
with plain IPv4/IPv6 outer headers. Removing the floor would enable a
path that has never been used, which does not belong in this fix.
I will send this as a follow-up.
pw-bot: cr
Technical Details
Message-ID:
<CAL4Wiioa61dp2DXSOfJwj3avru8zBiqyx44G_JfBBfHbrAjMsg@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359417-linux-kernel-netdev=dewy.ruReferences:
<20261106095340.2113683-2-edumazet@kernel.org> <179421814766.994134.3669228181251158303@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359417-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4 1/2] net: virtio: validate outer protocol of UDP
tunnel GSO packets
Date: Mon, 9 Nov 2026 17:24:25 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiioa61dp2DXSOfJwj3avru8zBiqyx44G_JfBBfHbrAjMsg@mail.gmail.com>
References: <20261106095340.2113683-2-edumazet@kernel.org> <179421814766.994134.3669228181251158303@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="398851"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lUSjf0jaesK+ifrB0Xm90b8S5c8= sha256:+ADb1bw9E9SXnX+W+cBJBYeo+cM9uTUgq17vW81cpRM=
sha1:PiDQ34kWHQJMLaqO5byPuDUEeX8= sha256:gFS1BPOM7Z7BrWbxwop93lhzJ7LOaluu5Baqi+BKGlQ=
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 E6103113871; Mon, 9 Nov 2026 19:28:52 +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 waZ8-Fkfa_mg;
Mon, 9 Nov 2026 19:28:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359417-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 01E66113847; Mon, 9 Nov 2026 19:28:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 74B77A7D18; Mon, 9 Nov 2026 16:24:42 +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=1794241479;
b=be3FW3buAm9DJDkMQLxcXtr3tsEDyhfsq+YYeDRRRGjL21A9hlHpz7Lwv0uy49z67MYc
UlczE+nO5sr0uRw0mP7WHRi8OnIO5AfsySNmM7ArjyKm7gSEEHcmU2YwPGUox//IhM+Rh
DV8MxcxMx6/BWwoVdzLCZpxW7l2kCRLja3bJhTDAmgr0ZuU/7U4l5Co8uvSizXbgeY7ke
A0yGZPFRmDVbObXpdrv5/ze7ABBH621VinPQds6XuPKxu8iYhHBr/+1MfQ7klVuYDwrtl
Wk4cTcRcoZM5S84dkC/CEW9DdwdzjgtfWFZjfikBRb9C1Lf7ikRznSAp0mzksnHJw6w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794241479;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
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=n5wuRW+BfwesQSl9RZrQwjD+U8kT1DloxPy/4T2mCjg=;
b=EAPS1T8BWxJi/ZYk5XjxGJO66m+IVYGCqvSbB8ZtcmTWn4hep9WSBIpO9irksayCu2sZ
3eMvEK0tYSL4e8Mxa8gTkO4XYHNbrL0NLiPNo6lTMefiSDbNpF/qjbEAtEItpUWZbG8RD
gOyCrfPIdQ/GESngWO9a88722hVjYe15/k99ubfnqiBa+4y8ttcm8cVigw0q6/t8AX5JV
9Vo0LGM/XtPum3onSUqlTP/009ZQdicPBaM7xE8U5kudrk+mnnfLiZlyyj1H64C9HzWV3
BKRVkzO4Kbysfl43qhksiIQRHN6MN87U4QNIsSTdaex88C0PgcbC8uUMi12bGu5DE4A==
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="iLsvu3/I";
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 4491D606A33B;
Mon, 9 Nov 2026 16:24:39 +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=iLsvu3/I
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=1794241478;
b=We+ifnhLgMEltgRn9tRL1YLes8cLvKDbpmP7O4jFKg4Zv/ttPp9+pTjP/hqUZfNCyUe1
2zxF1KNfUTLA8VnQcK+0hhBaqFgoU/wAhw3GOirfp9pdGfX3i/2N14AAfQYTmHXqjnP+u
IV9U49cgr2F7hrfMvAAukzwkDjSfGLtLIJ4sRxroY0ZFG/RGJgc+woQKQenMkcDL8TlQJ
lFRs7dBQHpMePmS1FPRzm1lolX2JI634rSF4bQVjSPZQ+mz0yFyU1Hk+jsbSaHeuvHkzy
x3RNqvwMajzj7Phjt9DeUAjhon+RMq6meeFIY0ztxLuhU9wnEPxXTCzfi0oObrZeMyA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794241478;
h=Received:DKIM-Signature:Received: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=n5wuRW+BfwesQSl9RZrQwjD+U8kT1DloxPy/4T2mCjg=;
b=KqNwZxxWfRmyHJ/jQkaNmljwEfot61ZUf0VH2cr5u/Knd8fBDJgWgQZtqH2/Mz7sZ4Dj
aVZzQqncsxbkob1ViGSnhMSLXtxF9OSnL0BQvIk4SuwbZESbczEqkeG22SzopToPTesCY
sgmdwfWSaW2mojsadyLe8RtMO5K71OmLnjmR7uFuQ46KcDkH4nOBxvePQ9S2LHXqcezIM
hOxz6dfIZuTocCqb49WzLHnkN2TsQTAphmXMlXOBuOYcWqHb2iIMrNSSOaeUosrlwaphe
7e8tTUYsrmJVi5z5UMB47w8HDJmRcblWeEq9sBOCLdx1Ylz0ShRgIqbhjWkU56RuU5w==
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="iLsvu3/I";
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 7AB42606EE80
for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 16:24:37 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 256931F008BC
for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 16:24:37 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1794241477;
bh=n5wuRW+BfwesQSl9RZrQwjD+U8kT1DloxPy/4T2mCjg=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=iLsvu3/IT33w2+nw1tF/w838npiyt65hR1rXxS8vjaUt3qDkKBO8b5eWmYbwZ6OHJ
8Snwt3Yyv/03bfyxCdmcwa+imVXIrxZCqOWxdbDYB5XSXcNen/nPu5kraSi0kTvBCE
htS9lFwL5+zzJsEAnOFmua9OnZ6MHIAVuIx0M3zl0uoBPDAExEHjC4f/OU+ulyHnI2
h7Z3Ini3FqqPlsDjiRUJvZf9ypBD2c7AL8pZCP80U1JYgxZ4u4SwH96LuT52FqTlYk
1ZXMHHwmAUcnpoo6jTdp+dCjoWJXEiKlqdGhmAYDGbS49uaVVpTpH5q6GxYgLhLS8i
nFijdDGiI/45Q==
X-Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-46556b9e02cso705431fac.1
for <netdev@vger.kernel.org>; Mon, 09 Nov 2026 08:24:37 -0800 (PST)
X-Gm-Message-State: APuU4Z+BZUwbmfYyg4cgVVfNsYLT/bjqcp7WHHGxS5JDJV6CL9lprNB+
ptbLPFU+3qNvIwCbJ81/QV2zweBUoXnHzzUzs6FX2tvNVwu8bAkkOKtxHwmn+eRtl6J2Bs8eqjk
XKcN0Z7ISO+FtB55nD3T7RT39zCF0lAA=
X-Received: by 2002:a05:6870:e311:b0:46a:c673:a16c with SMTP id
586e51a60fabf-4ae1fe6de5cmr5970fac.5.1794241476458; Mon, 09 Nov 2026 08:24:36
-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: <179421814766.994134.3669228181251158303@kernel.org>
X-Gmail-Original-Message-ID: <CAL4Wiioa61dp2DXSOfJwj3avru8zBiqyx44G_JfBBfHbrAjMsg@mail.gmail.com>
X-Gm-Features: AclHuK83hY0GSMGeOmqZ2p3f1VOqev2f_DFnXet7mIxLfflYJSQXAipPxiQLIMA
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, willemb@google.com, mst@redhat.com,
jasowangio@gmail.com, eperezma@redhat.com, hassansultan@google.com,
virtualization@lists.linux.dev