* [PATCH net] ip6_gre: return the full header length from ip6gre_header()
@ 2026-11-25 2:04 Kyuwon Cho
0 siblings, 0 replies; only message in thread
From: Kyuwon Cho @ 2026-11-25 2:04 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
David Ahern
Cc: Xin Long, Ido Schimmel, Willem de Bruijn, Simon Horman, netdev
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 2:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 2:04 [PATCH net] ip6_gre: return the full header length from ip6gre_header() Kyuwon Cho
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox