From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>
Cc: Xin Long <lucien.xin@gmail.com>, Ido Schimmel <idosch@nvidia.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org
Subject: [PATCH net] ip6_gre: return the full header length from ip6gre_header()
Date: Wed, 25 Nov 2026 11:04:42 +0900 [thread overview]
Message-ID: <179553307366.1670514.6802805102726706751@gmail.com> (raw)
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:
BUG: KMSAN: kernel-infoleak in _copy_to_iter (lib/iov_iter.c:197)
_copy_to_iter (lib/iov_iter.c:197)
__skb_datagram_iter (net/core/datagram.c:402)
packet_recvmsg (net/packet/af_packet.c:3573)
sock_recvmsg (net/socket.c:1176)
__sys_recvfrom (net/socket.c:2333)
Uninit was created at:
__alloc_skb (net/core/skbuff.c:716)
alloc_skb_with_frags (net/core/skbuff.c:6940)
sock_alloc_send_pskb (net/core/sock.c:3096)
packet_sendmsg (net/packet/af_packet.c:3023 af_packet.c:3209)
Bytes 68-107 of 108 are uninitialized
Return the length that was pushed, as ipgre_header() does. With the
payload in place, the tap also shows that ip6gre_header() never sets
payload_len, so set it as well.
Fixes: 76cc0d3282d4 ("ip6_gre: skb_push ipv6hdr before packing the header in ip6gre_header")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. A reproducer, which runs as any
user; ip6gre-tap sends 64 bytes of 0xaa through an AF_PACKET SOCK_DGRAM
socket and prints the first 48 bytes that a packet tap on the device
sees:
$ cat ip6gre-tap.c
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
/* send 64 bytes of 0xaa through argv[1] and print what a tap on it sees */
int main(int argc, char **argv)
{
unsigned char sa[offsetof(struct sockaddr_ll, sll_addr) + 16] = {};
struct sockaddr_ll *dst = (void *)sa, tap = { .sll_family = AF_PACKET };
unsigned char payload[64], buf[256];
int c = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
int s = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6));
int n;
tap.sll_protocol = htons(ETH_P_ALL);
tap.sll_ifindex = if_nametoindex(argv[1]);
bind(c, (void *)&tap, sizeof(tap));
dst->sll_family = AF_PACKET;
dst->sll_protocol = htons(ETH_P_IPV6);
dst->sll_ifindex = tap.sll_ifindex;
dst->sll_halen = 16;
inet_pton(AF_INET6, "2001:db8::2", sa + offsetof(struct sockaddr_ll, sll_addr));
memset(payload, 0xaa, sizeof(payload));
sendto(s, payload, sizeof(payload), 0, (void *)sa, sizeof(sa));
n = recv(c, buf, sizeof(buf), 0);
printf("%d bytes:", n);
for (int i = 0; i < 48; i++)
printf(" %02x", buf[i]);
printf("\n");
return 0;
}
$ unshare -Urn sh -e <<'END'
ip link add g6 type ip6gre local 2001:db8::1
ip link set g6 up
./ip6gre-tap g6
END
Without the patch the outer IPv6 header is 0xaa from byte 4 on and
KMSAN reports the infoleak above. With it:
108 bytes: 60 0c f6 22 00 44 2f 40 20 01 0d b8 00 00 00 00 00 00 00 00
00 00 00 01 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 02 00 00 86 dd
aa aa aa aa
The patch was written with LLM assistance; we reviewed and tested it.
net/ipv6/ip6_gre.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b5d6ed8f0c36..9b30fb2f4bcf 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);
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;
- return -t->hlen;
+ return -needed;
}
static const struct header_ops ip6gre_header_ops = {
--
2.43.0
next reply other threads:[~2026-11-25 2:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 2:04 Kyuwon Cho [this message]
2026-11-26 15:27 ` [PATCH net] ip6_gre: return the full header length from ip6gre_header() Ido Schimmel
2026-11-29 2:26 ` netdev-bot+sashiko
2026-11-29 8:08 ` Ido Schimmel
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=179553307366.1670514.6802805102726706751@gmail.com \
--to=kyuwoncho18@gmail.com \
--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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.