🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24413

[PATCH net v2 0/3] gre: fix the headers that ipgre_header() and ip6gre_header() build

#24413
From: Kyuwon Cho
Date: Mon, 30 Nov 2026 05:56
82 lines
13663 bytes
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
Technical Details
Message-ID: <cover.1795755931.git.kyuwoncho18@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373890-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373890-linux-kernel-netdev=dewy.ru
From: kyuwoncho18@gmail.com (Kyuwon Cho)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <cover.1795755931.git.kyuwoncho18@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1347777"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:C7ufqdKA9W+6DAWCOextxuXJGeM= sha256:P3zEKW22HloEc9wRoXdKksVDCGOy6j2GsWTBF9TlBGM=
	sha1:Tj3GagmJKyYuj7H8XYrgeTZo6TE= sha256:9hsJlTlfens+d0LnK7QPdwqZuARPwqOLzTfqXHERjoA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9900A125FC8; Mon, 30 Nov 2026 08:56:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id sWshLahcmbfm;
	Mon, 30 Nov 2026 08:56:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373890-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 64A5D125FC6; Mon, 30 Nov 2026 08:56:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A97E227C25; Mon, 30 Nov 2026 05:56:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796018184;
	b=aiRK+sv7qJbKSijaoD79ggxQc3N5jOO8uBF7zJoMLr4GxTMIzM58h14FPKmrcPXPhByD
	 XnU2sFKwSYNPnc9TpxFF6P+Sef4Hb2gv73PL7D1lfGHE4n9Aw7omF/EeIKZM/6mLxxsrO
	 095EEnn26P9fh+QxJcwqEVsgHWVRyPkR70HCs+v18LdKwv5S5UAygDVPzYPG4IIPnokm2
	 X4Tquf+WtcZaTKFUKlPbft3emtrHclFZylRM/RkqfgZhJFp5J5E0heBvi9nc9AWS5fXGC
	 aA2oB9avGBDNjx7poUUiSSebiJ+iRyyRnS23bx5ArgdXDaobZLSAM/Qiw/3xHRslcPw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796018184;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=N0iaqp86ropo9bnWQm9g91wN1p68NBMDOYfg+KKFssU=;
	b=HMvqKnBYkPl124op9/8hdoxJjpl/4MQd0I2b2/Rxx+YBZaVz6uLUnF2LG17NcvJtNSwu
	 nemNJEqoHb0XpIBHKZ8HyYFYxccCESUEnaof7kX+0bhit1Fb8vWlaSFv8nCrlRuNElft+
	 NzmmuQq9OKnHSKcJNHVCkZXoAQ9cFMB6ONnWmoPg135zdGj4p8SiToFhdcW79/MwDA431
	 5PcPZtUUjPnTRSRKkiNeszkNS2Tp2yuP7HCaEGBHKWDNb6VJhcBxGD0koK0bdjL+qFngv
	 L6pGuHwHBKg7moXEEaJgeuKUgEL+XwIzCe3D7iPL8SOWhOPPDRfzl9IEoCXlb3+b8qw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rFDhXLsW;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 81CC4606A32F;
	Mon, 30 Nov 2026 05:56:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rFDhXLsW
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.174
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796018183;
	b=cW6qJA2IkrIFdahXB8TDuPTXgvbFog97BFSizf9lUQBbXt1AHVAVAYQvbPHFF7TGFn6y
	 Hu2oAF9aExeD5JK0sSET+cNgfHPLCVV81/flkMYhguO9t8YXgKeNvvopvO1eIC/nkYhUn
	 6/TDjNTzLqAmfI0HknHISFgVogIHHCq/uEs5kgyFYc42SeZpddp3LoZx3uLhUQDMH1B6h
	 RnD8av4jmOV4TTlJpwkbys3pGZPFYLytsKpEYTmvDEpOVULCgvc7gu8beeebPWmq4cJJ9
	 Bi0gYKKlJqGFBFGxRUPq16eHwMOtoflh7mkKJwJgWykWDUMNGEuDR/njeQeY5FSjZoQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796018183;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:MIME-Version:
	 Content-Transfer-Encoding;
	bh=N0iaqp86ropo9bnWQm9g91wN1p68NBMDOYfg+KKFssU=;
	b=ZFd6QrDaEq18P23I+O507kODU84zCAA/Dy82VPcKcy0paW5HH6MytCdibu33zYAlUqOV
	 si6plwyBmqLuNmD2+WukSJNusw0vmjN+/GdesMnP77tvO9Cu0JzoFTOE8ddNikx4/AewT
	 QGavB0wZ6WXfxiAFlWv5dKWIz0bOm6Ti+KtoNt2kZmlOgBzwn/UILGAs0ZzvovBuMIAjX
	 E6za2EYT39dgsDHEb8huFPydgQWPqW4AqQVyj4tFy+bMMANr56sHbmx5mvxLIMUCVDhJZ
	 Bm6R+N/4vDoXT9kwcoznc6XaLZ4RLQ4nphjWgtPQHrvCOqA6HSOi39jBDFNl0/gF/Ww==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rFDhXLsW;
	arc=none smtp.remote-ip=209.85.210.174
X-Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59E90606A325
	for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 05:56:23 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59E90606A325
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8c20d68c83fso5722663b3a.0
        for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 21:56:23 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796018183; x=1796622983; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=N0iaqp86ropo9bnWQm9g91wN1p68NBMDOYfg+KKFssU=;
        b=rFDhXLsWyuJ4UQHf24WT7OMvmphFaxKOJXGvg3JiRPvXkTZPS7WOCOnVhVY+JSDIJr
         FQUtU2bSTbJ9y/M90vsv3n8bSghRYe4aYc28fmh+l8x+5WzctwuLzRg4/mDKZ6Wz4TW5
         5cB949xusddwfNT78t8bbfLW8XLkn1B+AdH36dZfLa+WPCTDHtcG0BpNRLzCPa7mpXfw
         wk06UUR+k5VGEFm0r61IR9G2MgeiO4gGp1SZNMws8xTLJrGKivCuIITC2FhQH5mbyJLC
         yvfHbUek0nnExvX2wxCiiNTbIYPANSOVozeEqP4pPvEyzZvzDQDQ3P24NzVUnHQUy9HX
         +KDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796018183; x=1796622983;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=N0iaqp86ropo9bnWQm9g91wN1p68NBMDOYfg+KKFssU=;
        b=UtAuNAZeKpZNmkcbhdkJ+xD3dYuL8/iulk0gtV+PZzYMJHLRYFPL62N7i2bK6QXRJh
         zZcYra8OIkP4uCbxUVbu8HxriXA44LjIKLPxKOvxQNJwonRfDrxiDDHikAhAAM4GtzcT
         JEOxAidWbGEChrJzbo3LjnOUmTRUM3hTc1ihy4X46nmj1Rr6TAZ74vbp4/2j2xlYTDAw
         8PpVpMHG8yVzVmz1o4lc0l3sYPjYGEe8/nqdCSVDmD6nXqR0FyXbQqBSZysUvE4y2jAN
         7QCGKiyEK+Aa6gM7ez+Q0USfb/bIKLv4zbb/TgV5BAfUDcPLZIPM29K285XIYtEYbheS
         4pvw==
X-Forwarded-Encrypted: i=1; AL+hErGRTruzisA1KDPaqQZkPeKu8FRp/UovEF0g3RHeV/F598lEkbmcAVomFu8sW1bSnIAgLOGEwvA=@vger.kernel.org
X-Gm-Message-State: APuU4Z9nobkrXO494Hmo3wD/LpTg55GmAC0ZV6slA2w7NFc3oLYBAoQ+
	19Kwmp5VNqDchnyWPUf8dOszXvuQfBqYvxqIMyRU2bUusdEUMDQYy5JYQIjkiw==
X-Gm-Gg: AZFdTZfRBn+cb5JFAT4qUsZz6ovmUSJHy2XyGK77C9pVvFfyCuukOwgY/ObLN95AKND
	CPTFDzHP3vRW0yRQr0Chak8LRU9NvEyy5/7ehXmgcwRQcbmylE2Dffl4H8Gx3HmRhmpDFXqgfwQ
	NboBoVSxbzTcao+h/DOUupLYIGUMelnWZ5X+SrELoRf8uJfgWwZNd5cxUoIcrr+KN/QTa3MzOaB
	6jR2QEQjT6s5Nihn5uGXIzNots/bSEy5H3MDbrLoEq62pQ9q3DIllnbK4TLkn5IS5uyjv3YSfda
	+7ScMwlrMGuNFWoTBTbQHzFniWcMKxK5caTWl6e+JTlUldfYQTN7FpSkNGGObe5/OWzXLvmgpBY
	nYHWwzikXSItLGlb/DySFSYsLQ+llcSIpNIlDrfMiPTxdjK+FvV9hyPd75nF6RtR2gMFxbYnXKg
	7z27vUyJDG5CafEWdVAHnrCyF9/3DbcMpZdaTz4Y7L/nAVYNUDEhtj32f+t40qItFQrM7TFQkPH
	kc+wkHKxQGzSwSoBbeFnojjmOSftQROt4kJJ3enVEAOV+oYimBdKRXLXtEwBQ3k8qygHRb0tapg
	DGOz0YRwyvXbAfoOj6qJf2yVo3AhQ1YQUXTncSABCElpVHWMR2gNJBhp9FzABEwuMpU=
X-Received: by 2002:a05:6a21:3b8e:b0:3fe:c355:b92a with SMTP id adf61e73a8af0-400ad19dee3mr26179952637.14.1796018182601;
        Sun, 29 Nov 2026 21:56:22 -0800 (PST)
X-Received: from d20be28ee783.tail196be.ts.net (vldb.skku.ac.kr. [115.145.173.180])
        by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6cea770asm17578233a12.3.2026.11.29.21.56.19
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 29 Nov 2026 21:56:22 -0800 (PST)
X-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
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list