From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Sun, 29 Nov 2026 02:26:53 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E76F81F00896; Sun, 29 Nov 2026 02:26:52 +0000 (UTC) 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== Subject: Re: [PATCH net] ip6_gre: return the full header length from ip6gre_header() From: netdev-bot+sashiko@kernel.org To: kyuwoncho18@gmail.com 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 Date: Sun, 29 Nov 2026 02:26:52 +0000 Message-ID: <179591921239.3135.6275849297644683022@kernel.org> In-Reply-To: <179553307366.1670514.6802805102726706751@gmail.com> References: <179553307366.1670514.6802805102726706751@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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