Article View: linux.kernel.netdev
Article #24043Re: [PATCH net] ip6_gre: return the full header length from ip6gre_header()
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 02:26
Date: Sun, 29 Nov 2026 02:26
176 lines
14724 bytes
14724 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 (1) ยท Low: 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).
- [High] The fix leaves part of the leak in place.
- [Low] The commit message understates the impact.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the creator
and consumer of the header disagree.
--
ip6_gre: return the full header length from ip6gre_header()
This commit changes ip6gre_header() to return the full number of bytes it
pushes (t->hlen + sizeof(struct ipv6hdr)) instead of t->hlen. With that,
packet_snd() copies the AF_PACKET payload after the outer IPv6 and GRE
headers. It also sets payload_len in the outer IPv6 header.
> ip6_gre: return the full header length from ip6gre_header()
>
> Since commit 76cc0d3282d4 ("ip6_gre: skb_push ipv6hdr before packing
> the header in ip6gre_header"), ip6gre_header() pushes the outer IPv6
> header and the GRE header, t->hlen + sizeof(struct ipv6hdr) bytes, but
> it still returns t->hlen. packet_snd() copies the user's payload at the
> offset dev_hard_header() returns, so an AF_PACKET SOCK_DGRAM send on an
> ip6gre device with header_ops (remote any) writes the payload over the
> outer IPv6 header and leaves the last 40 bytes of the packet
> uninitialized. A packet tap on the device then copies those bytes to
> user space:
[Severity: Low]
Is a local packet tap the only place these bytes end up?
The ip6gre xmit path never strips the header that ip6gre_header() builds.
__gre6_xmit() only reads daddr from it:
net/ipv6/ip6_gre.c:__gre6_xmit() {
...
if (dev->header_ops && dev->type == ARPHRD_IP6GRE)
fl6->daddr = ((struct ipv6hdr *)skb->data)->daddr;
...
}
After that, gre_build_header() and ip6_tnl_xmit() push a new GRE header and
a new IPv6 header in front of it.
The reproducer sends ETH_P_IPV6, so its packet is dropped. The NBMA branch
of ip6_tnl_xmit() takes tx_err_link_failure because the AF_PACKET skb has
no dst.
Any other sll_protocol (ETH_P_MPLS_UC, for example) goes through
ip6gre_xmit_other()->__gre6_xmit()->ip6_tnl_xmit(). That path routes to the
daddr from sll_addr, so the previously uninitialized bytes go out on the
wire.
Also, before the fix, prepare_ip6gre_xmit_ipv6() parsed ipv6_hdr(skb).
packet_snd() resets the network header before calling dev_hard_header(), so
that pointer sits at data + needed and overlaps the uninitialized tail.
Could the commit message say that these bytes can leave the host, so
stable and security triage see the full impact?
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index b5d6ed8f0c369..9b30fb2f4bcfc 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -1397,6 +1397,7 @@ static int ip6gre_header(struct sk_buff *skb, struct net_device *dev,
> ip6_flow_hdr(ipv6h, 0, ip6_make_flowlabel(dev_net(dev), skb,
> t->fl.u.ip6.flowlabel,
> true, &t->fl.u.ip6));
> + ipv6h->payload_len = htons(t->hlen + len);
[Severity: Medium]
This isn't a bug introduced by this patch, but is the header built here
ever removed on the transmit side?
ip6gre_header() pushes t->hlen + 40 bytes. The ndo_start_xmit path
ip6gre_tunnel_xmit()->ip6gre_xmit_{ipv4,ipv6,other}()->__gre6_xmit() never
pulls them. gre_build_header() then calls skb_push(skb, hdr_len), and
ip6_tnl_xmit() pushes another IPv6 header. The packet goes out as:
IPv6 | GRE | IPv6 | GRE | payload
The IPv4 version strips the header before it transmits:
net/ipv4/ip_gre.c:ipgre_xmit() {
...
if (dev->header_ops) {
int pull_len = tunnel->hlen + sizeof(struct iphdr);
...
/* ip_tunnel_xmit() needs skb->data pointing to gre header. */
skb_pull(skb, pull_len);
...
}
So the comparison with ipgre_header() in the commit message holds for the
return value, but not for the transmit side.
Now that payload_len is valid, a Linux peer may decapsulate twice. The
second set of headers also adds 40 + t->hlen bytes per packet that the MTU
calculation doesn't count, so packets close to the MTU can fail with
EMSGSIZE or PMTU errors.
> ipv6h->hop_limit = t->parms.hop_limit;
> ipv6h->nexthdr = NEXTHDR_GRE;
> ipv6h->saddr = t->parms.laddr;
> @@ -1415,9 +1416,9 @@ static int ip6gre_header(struct sk_buff *skb, struct net_device *dev,
> if (daddr)
> memcpy(&ipv6h->daddr, daddr, sizeof(struct in6_addr));
> if (!ipv6_addr_any(&ipv6h->daddr))
> - return t->hlen;
> + return needed;
[Severity: High]
With needed returned, packet_snd() now copies the payload after the full
t->hlen + 40 bytes. Doesn't that leave the GRE option bytes uninitialized
when okey, oseq or ocsum is set, or when a FOU/GUE encap is used?
ip6gre_header() writes the IPv6 header and only the 4-byte GRE base
header:
p = (__be16 *)(ipv6h + 1);
p[0] = ip_tunnel_flags_to_be16(t->parms.o_flags);
p[1] = htons(type);
However, t->hlen also counts the optional fields and encap_hlen:
net/ipv6/ip6_gre.c:ip6gre_calc_hlen() {
tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
...
}
Nothing writes the pushed bytes from offset 44 up to 40 + t->hlen. Before
this patch, the payload copy at offset t->hlen happened to cover them. Now
nothing does, yet p[0] still sets the key, sequence and checksum flag bits
for that space.
ip6gre_tunnel_validate() rejects only GRE_VERSION and GRE_ROUTING, so these
output flags are allowed on remote-any devices that use header_ops. Try
the reproducer from the commit message against this device:
ip link add g6 type ip6gre local 2001:db8::1 okey 1
Bytes 44-47 of the captured frame should stay uninitialized. They reach
the tap through dev_queue_xmit_nit(), and the same KMSAN kernel-infoleak
should fire. __gre6_xmit() doesn't strip this header, so with a non-IP
sll_protocol these bytes would also be transmitted.
Would it make sense for ip6gre_header() to zero the region after the GRE
base header, or to fill in o_key and the sequence number?
The IPv4 ipgre_header() in net/ipv4/ip_gre.c, which the commit message
uses as the model, also writes only greh->flags and greh->protocol. The
same uninitialized option bytes can reach a tap there before ipgre_xmit()
pulls the header. That one is pre-existing.
>
> - return -t->hlen;
> + return -needed;
> }
>
> static const struct header_ops ip6gre_header_ops = {
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179553307366.1670514.6802805102726706751%40gmail.com
Technical Details
Message-ID:
<179591921239.3135.6275849297644683022@kernel.org>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373342-linux-kernel-netdev=dewy.ruReferences:
<179553307366.1670514.6802805102726706751@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373342-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] ip6_gre: return the full header length from ip6gre_header() Date: Sun, 29 Nov 2026 02:26:52 +0000 Organization: Usenet Network Message-ID: <179591921239.3135.6275849297644683022@kernel.org> References: <179553307366.1670514.6802805102726706751@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1084259"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:2414HcUueSye0u7oP4Y06hkEnBg= sha256:g65R6AdAvZQW4FuBiilCBRh1lstfrFljH56v5PenV5w= sha1:7msuL8K2ZA5WGgwXcQwRe4dW4xU= sha256:+3gTzEWpi6wyeYt878bP36HecfEs1Bso5S2IICJdyuQ= 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 09ED3125F90; Sun, 29 Nov 2026 05:27:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 uXEgIOOwOOoQ; Sun, 29 Nov 2026 05:27:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373342-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 8F147125F8C; Sun, 29 Nov 2026 05:26:59 +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 114B726359; Sun, 29 Nov 2026 02:26:55 +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=1795919214; b=1YU5QfH8ZTEuXchRWE8iG6WmqXRfeNLW4gSJ7orgedJQUqapZLvuS7DpOfD1x5o7gOcm ZmG4Lh22SQpgmW/Tjswr09RRH3GmV+BqCpEfvQnhvVaC5WxkfuMzenaeZEdQaaZJbEKKh omLThCnnOfNDBkpAkxKgDSjkbobVykIWLMW8AjZXmWYKLZjWf5HmZws4AclYV3nUPUgYD XFLTG2EqL8dqRwLWyOKv5doukjJB4jG+RYEqqQxKIIWMUTFvzQt0xIUTUj3920oZA+gRC sk0viIWNtZhOW076FxPImQPVB51EOarhYzhP80SkDK0B45yEwplyQRsU43iJItTTsRQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795919214; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=cy/6j8ATzYpn2ACRfoHtKk9+OjsWRJ2gYGVSHrSUkKI=; b=mpnSbIiRX0nl839REWMH2K2Epe6COoNd4Im5KtVjd0urydVplZX8aw/HZKjZOKid7WMc ZSS2cp8XUxeRZsA7fVFvT35qu5I435jZ+z0t575MeMP/51j+6eU/aaYrTFPDlaGOf0rhp SPzTEn62/wgcRy0LUamVem6TfycPoKQW5fZ7gwk6zcyZCJvQdJ8C/e8qymlXs5+iyMi2p 2HEDdpXg10rZUFZFYj+5TxVqtJB66htycUlglRCX4HqujM4JWgMyA5NcHmg24N7ZyRQQV 5au+fCiWUSGU5MkzYJb1BtAl73UUB9G5+5H+pHte3jFa8Kh8FU3S/vFBCAUIVtkm4wA== 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=N3xvvrKD; 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 CB043606A329; Sun, 29 Nov 2026 02:26:54 +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=N3xvvrKD 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=1795919214; b=Ltu6oVv0rQGOdGK4m9M2wO/IvXin1ybsLt1B4SADyIyLTJ7ojPtQzzT/Z0PhI8ZzoK1d mKk6MXD8REkac0UA8eceOy4A/fzF3Gljds7V7dOqvtZdlw7vQUdUYasG2LdSocMdGUDvT R0wrXD6X+h+9tLNRF8ckaeSEObUyXbuCJAG2LrD2jWTiKOxTu4+0Dwm4MkW1np5B0G0/+ CcvmtY4FpgsBYD+kH8HoAA34iV/YgXfuXKcY6YyYlAY/w1uUPYXkXuQIcMbeHO3Nx/NA+ CRMPyTXDq1IQ6sAkYBqc+B3UaAaEi1mxQjuM0026h/kAD4ovpP1InYWt2J+SyA1aswg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795919214; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=cy/6j8ATzYpn2ACRfoHtKk9+OjsWRJ2gYGVSHrSUkKI=; b=vsUSvyszl5jiduXVNw1zkcttWtUshZ+HJ2pF1bhV0AlGNf009pwUFKZnd2XXyreJI+so ZYkqTRkD6/QEaT2HZ4Ln7r2y6VB0n/2B6YoWoaEijdHwMsVxDYWe9rTdhj9Lqq+DRq6Td gv1kj45v9hQRrTilRemAjumIx1T7NZWfwRu8882Nmk5IzYOijeNKP8swRMj9qLAw9PeW9 /i8iZOEkgia+ggBT1ifyoP2P8Uj/K/y968L4RugRvfxR8D/BVnZkY1kNU+zjdUTSDnZF6 SvlGhjd57rHF++NToIcXynJZckM4pfAmCWwl+HMyUsvznEPF/3RSr3Sc6/lMgg1/aww== 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=N3xvvrKD; 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 EAD3A606A31C for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 02:26:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E76F81F00896; Sun, 29 Nov 2026 02:26:52 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795919213; bh=cy/6j8ATzYpn2ACRfoHtKk9+OjsWRJ2gYGVSHrSUkKI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=N3xvvrKD5v06AMILyXpuyLOUNR0l+vpc03qMSOrnfv3V57l8Xv4gDK2bFU0z+Jz+g ty3A3sDYXtnZs6jcUS9/ilm8TgvX37qVwNLT1j+K75ZBsXu18QBgLBTzDWXghxoVPW sic8g7H9oD6u8lKaFeQT1eEZ/bxfakROfoUkHVO0dAn2wiRExnA3ik28hHRAlA1g+V ZOr2WC1XMDJA+HWB3tgMXx+gGdUyKt+4Ws58ZC79fkoRaW2Fwp0j4nW5m8RXeFXQ0k Gvu6fmxgcSnpX/1eKdqEKWMngu8Vu+9f1WHhysPvgia7P7Kp7UUXbnbNSKUds8rGz0 R0iFb/LktdrTQ== X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, lucien.xin@gmail.com, idosch@nvidia.com, willemb@google.com, horms@kernel.org, netdev@vger.kernel.org X-In-Reply-To: <179553307366.1670514.6802805102726706751@gmail.com> X-sashiko-severity: High 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