Netdev List
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH net] ip6_gre: return the full header length from ip6gre_header()
Date: Sun, 29 Nov 2026 02:26:52 +0000	[thread overview]
Message-ID: <179591921239.3135.6275849297644683022@kernel.org> (raw)
In-Reply-To: <179553307366.1670514.6802805102726706751@gmail.com>

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

      parent reply	other threads:[~2026-11-29  2:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  2:04 [PATCH net] ip6_gre: return the full header length from ip6gre_header() Kyuwon Cho
2026-11-26 15:27 ` Ido Schimmel
2026-11-29  2:26 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179591921239.3135.6275849297644683022@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kyuwoncho18@gmail.com \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox