gre: fix the headers that ipgre_header() and ip6gre_header() build
Get series with b4
b4 am [email protected]Versions newest first
- v2 Latest3 patches 0 repliesNew
Changes in v2 from the cover letter
- Add patches 1 and 2; v1 is now patch 3 (Ido).
v1: https://lore.kernel.org/netdev/[email protected]/
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | ip_gre: clear the optional GRE fields in ipgre_header()net/ | +1 | 0 replies | |
| 2/3 | ip6_gre: clear the optional GRE fields in ip6gre_header()net/ | +1 | 0 replies | |
| 3/3 | ip6_gre: return the full header length from ip6gre_header()net/ | +3 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH net v2 0/3] gre: fix the headers that ipgre_header() and ip6gre_header() build
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/[email protected]/
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(-)
Signature · 1 line
2.43.0