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: Ido Schimmel <idosch@nvidia.com>, Xin Long <lucien.xin@gmail.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, Dmitry Kozlov <xeb@mail.ru>,
netdev@vger.kernel.org
Subject: [PATCH net v2 0/3] gre: fix the headers that ipgre_header() and ip6gre_header() build
Date: Mon, 30 Nov 2026 14:56:14 +0900 [thread overview]
Message-ID: <cover.1795755931.git.kyuwoncho18@gmail.com> (raw)
ipgre_header() and ip6gre_header() build the outer IP header and the
GRE header for AF_PACKET SOCK_DGRAM sends on a GRE device with
header_ops (remote any). Neither clears the optional GRE fields, so a
packet socket bound to the device reads the key and the sequence number
from uninitialized memory (patches 1 and 2, from Ido's review of v1).
ip6gre_header() also returns 40 bytes too little, so the payload lands
on the outer IPv6 header (patch 3, which is v1).
v2:
- Add patches 1 and 2; v1 is now patch 3 (Ido).
v1: https://lore.kernel.org/netdev/179553307366.1670514.6802805102726706751@gmail.com/
Tested on a KMSAN kernel as any user under "unshare -Urn", with the
program below on three devices, each set up first:
ip link add g4 type gre local 10.0.0.1 okey 7 oseq # gre-tap g4 4
ip link add g6 type ip6gre local 2001:db8::1 okey 7 oseq # gre-tap g6 6
ip link add g6p type ip6gre local 2001:db8::3 # gre-tap g6p 6
Without the series, KMSAN reports bytes 24-31 of the g4 packet (the key
and the sequence number) and bytes 68-107 of the g6p packet as
uninitialized. With patch 3 alone, it reports bytes 44-51 of the g6
packet. With the series, it reports nothing, the optional fields are
zero and the IPv6 headers are intact.
#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>
/* gre-tap DEV 4|6: send 64 bytes of 0xaa through DEV 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 };
int v6 = argc > 2 && argv[2][0] == '6';
int proto = htons(v6 ? ETH_P_IPV6 : ETH_P_IP);
int c = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
int s = socket(AF_PACKET, SOCK_DGRAM, proto);
unsigned char payload[64], buf[256];
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 = proto;
dst->sll_ifindex = tap.sll_ifindex;
dst->sll_halen = v6 ? 16 : 4;
inet_pton(v6 ? AF_INET6 : AF_INET, v6 ? "2001:db8::2" : "10.0.0.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 < 64 && i < n; i++)
printf(" %02x", buf[i]);
printf("\n");
return 0;
}
The issue in patch 3 was found by an LLM-guided test generator that we
are developing as a research prototype.
Kyuwon Cho (3):
ip_gre: clear the optional GRE fields in ipgre_header()
ip6_gre: clear the optional GRE fields in ip6gre_header()
ip6_gre: return the full header length from ip6gre_header()
net/ipv4/ip_gre.c | 1 +
net/ipv6/ip6_gre.c | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
--
2.43.0
next reply other threads:[~2026-11-30 5:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 5:56 Kyuwon Cho [this message]
2026-11-30 5:56 ` [PATCH net v2 1/3] ip_gre: clear the optional GRE fields in ipgre_header() Kyuwon Cho
2026-11-30 5:56 ` [PATCH net v2 2/3] ip6_gre: clear the optional GRE fields in ip6gre_header() Kyuwon Cho
2026-11-30 5:56 ` [PATCH net v2 3/3] ip6_gre: return the full header length from ip6gre_header() Kyuwon Cho
2026-12-01 13:55 ` [PATCH net v2 0/3] gre: fix the headers that ipgre_header() and ip6gre_header() build 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=cover.1795755931.git.kyuwoncho18@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 \
--cc=xeb@mail.ru \
/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.