🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17779

[PATCH net-next v4] ip6_gre: fix changelink conflict checks for L2 tunnels

#17779
From: Xia Yan
Date: Tue, 17 Nov 2026 10:16
189 lines
15111 bytes
ip6gre_changelink_common() calls ip6gre_tunnel_locate(), which only looks
for ARPHRD_IP6GRE devices. This lets an ip6gretap or ip6erspan update
create a duplicate L2 tunnel, or rejects a valid update because an
unrelated L3 tunnel has the requested parameters. A duplicate can receive
traffic intended for the original tunnel.

When the addresses, input key or link change, check for a conflict using
dev->type, including updates to metadata devices.

A metadata device can be created with the same receive parameters as an
existing ordinary device. Allow updates that leave those parameters
unchanged, and keep the hash entry in place. Otherwise a TTL update can
either fail because another entry matches first, or move the updated
device to the head and change which device receives packets. Do this for
both GRE and ERSPAN changelink.

Check conflicts and unregistering before applying encapsulation
parameters. Leave the shared find helper, newlink, legacy ioctls and
receive lookup unchanged.

Found during code review of the newlink and changelink duplicate checks.
Reproduced under UML with an IPv6 underlay named under:

  ip link add tap1 type ip6gretap local fd26:106::1 \
      remote fd26:106::2 key 100 dev under
  ip link add tap2 type ip6gretap local fd26:106::1 \
      remote fd26:106::2 key 200 dev under
  ip link set tap1 up
  ip link set tap2 up
  ip link set tap2 type ip6gretap key 100

Before the fix, the last command succeeds and received frames move from
tap1 to tap2. With the fix, it fails with EEXIST and tap2 is unchanged.
Custom UML tests covered conflicting and valid updates, metadata
overlaps, and receive interfaces for GRE, GRE TAP and ERSPAN. TTL,
fwmark and output-key updates kept the same receive interface. Kernel
selftests were not run.

Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---

Notes (ip6gre-v4-mail):
    Changes in v4:
    - Check changed receive parameters for metadata devices too.
    - Skip the duplicate lookup when receive parameters are unchanged.
    - Keep unchanged receive parameters in place in the hash table for both
      GRE and ERSPAN, so an update does not change receive priority.
    - Rebase onto current net-next; keep the shared find helper unchanged.
    
    v3: https://lore.kernel.org/netdev/179455350258.84965.17518172977020586093.ip6gre-v3@cmss.chinamobile.com/
    Review: https://lore.kernel.org/netdev/179489968486.3136.18372818760197436344@kernel.org/
    
    Tested on net-next 6ff4c5942a301675eb12e5b49d53a81e604624a1 with
    W=1 UML builds. The main checks passed 194/194 assertions; eight
    additional cases passed 92/92. Packet checks verified the receive
    interface and payload before and after updates.

 net/ipv6/ip6_gre.c | 64 +++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 24 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 26c0e1c4de18f8b44ceb05d01673aaadfbcbd5ef..af08041b6c498bcf25885acd09328eac4ae7b668 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -2042,12 +2042,21 @@ static int ip6gre_newlink(struct net_device *dev,
 	return err;
 }
 
+/* Match the fields used by ip6gre_tunnel_find(), except the device type. */
+static bool ip6gre_tunnel_same_rx_key(const struct __ip6_tnl_parm *a,
+				      const struct __ip6_tnl_parm *b)
+{
+	return ipv6_addr_equal(&a->laddr, &b->laddr) &&
+	       ipv6_addr_equal(&a->raddr, &b->raddr) &&
+	       a->i_key == b->i_key && a->link == b->link;
+}
+
 static struct ip6_tnl *
 ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
 			 struct nlattr *data[], struct __ip6_tnl_parm *p_p,
 			 struct netlink_ext_ack *extack)
 {
-	struct ip6_tnl *t, *nt = netdev_priv(dev);
+	struct ip6_tnl *nt = netdev_priv(dev);
 	struct net *net = nt->net;
 	struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
 	struct ip_tunnel_encap ipencap;
@@ -2055,6 +2064,15 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
 	if (dev == ign->fb_tunnel_dev)
 		return ERR_PTR(-EINVAL);
 
+	if (ip6gre_tunnel_unregistering(nt))
+		return ERR_PTR(-ENODEV);
+
+	ip6gre_netlink_parms(data, p_p);
+
+	if (!ip6gre_tunnel_same_rx_key(&nt->parms, p_p) &&
+	    ip6gre_tunnel_find(net, p_p, dev->type))
+		return ERR_PTR(-EEXIST);
+
 	if (ip6gre_netlink_encap_parms(data, &ipencap)) {
 		int err = ip6_tnl_encap_setup(nt, &ipencap);
 
@@ -2062,21 +2080,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
 			return ERR_PTR(err);
 	}
 
-	ip6gre_netlink_parms(data, p_p);
-
-	t = ip6gre_tunnel_locate(net, p_p, 0);
-
-	if (t) {
-		if (t->dev != dev)
-			return ERR_PTR(-EEXIST);
-	} else {
-		t = nt;
-	}
-
-	if (ip6gre_tunnel_unregistering(t))
-		return ERR_PTR(-ENODEV);
-
-	return t;
+	return nt;
 }
 
 static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
@@ -2086,6 +2090,7 @@ static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct __ip6_tnl_parm p;
 	struct ip6gre_net *ign;
+	bool rehash;
 	int err = 0;
 
 	ign = net_generic(t->net, ip6gre_net_id);
@@ -2101,11 +2106,16 @@ static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
 		goto unlock;
 	}
 
-	ip6gre_tunnel_unlink_md(ign, t);
-	ip6gre_tunnel_unlink(ign, t);
+	rehash = !ip6gre_tunnel_same_rx_key(&t->parms, &p);
+	if (rehash) {
+		ip6gre_tunnel_unlink_md(ign, t);
+		ip6gre_tunnel_unlink(ign, t);
+	}
 	ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
-	ip6gre_tunnel_link_md(ign, t);
-	ip6gre_tunnel_link(ign, t);
+	if (rehash) {
+		ip6gre_tunnel_link_md(ign, t);
+		ip6gre_tunnel_link(ign, t);
+	}
 unlock:
 	mutex_unlock(&ign->tunnels_lock);
 
@@ -2350,6 +2360,7 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct __ip6_tnl_parm p;
 	struct ip6gre_net *ign;
+	bool rehash;
 	int err = 0;
 
 	if (!rtnl_dev_link_net_capable(dev, t->net))
@@ -2366,11 +2377,16 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
 	}
 
 	ip6erspan_set_version(data, &p);
-	ip6erspan_tunnel_unlink_md(ign, t);
-	ip6gre_tunnel_unlink(ign, t);
+	rehash = !ip6gre_tunnel_same_rx_key(&t->parms, &p);
+	if (rehash) {
+		ip6erspan_tunnel_unlink_md(ign, t);
+		ip6gre_tunnel_unlink(ign, t);
+	}
 	ip6erspan_tnl_change(t, &p, !tb[IFLA_MTU]);
-	ip6erspan_tunnel_link_md(ign, t);
-	ip6gre_tunnel_link(ign, t);
+	if (rehash) {
+		ip6erspan_tunnel_link_md(ign, t);
+		ip6gre_tunnel_link(ign, t);
+	}
 unlock:
 	mutex_unlock(&ign->tunnels_lock);
 

base-commit: 6ff4c5942a301675eb12e5b49d53a81e604624a1
-- 
2.43.0
Technical Details
Message-ID: <179491056935.741041.1816208847037703396.ip6gre-v4@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365152-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365152-linux-kernel-netdev=dewy.ru
From: yanxia@cmss.chinamobile.com (Xia Yan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4] ip6_gre: fix changelink conflict checks for L2
 tunnels
Date: Tue, 17 Nov 2026 18:16:09 +0800
Organization: Usenet Network
Message-ID: <179491056935.741041.1816208847037703396.ip6gre-v4@cmss.chinamobile.com>
Injection-Info: usenet.network;
	logging-data="2301179"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:V95Mqfhajok1rL/vlh7TntmWCUw= sha256:8C5vGpzK70bGBQEYL7bzULO6LR+Zs+wV6XX99oyAdZ0=
	sha1:JEVqntWpHgz6daDnnCTg1gPrJ7Y= sha256:AzIUe1pzmrHkzDdU2mjuiiVqg7an7E5hWX3+OiDxQCM=
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 191CC114EE2; Tue, 17 Nov 2026 13:17:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.851
X-Spam-Status: No, score=-2.851 tagged_above=-9999 required=6.31
	tests=[DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	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=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.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 8OWShJDd0DyB;
	Tue, 17 Nov 2026 13:17:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-365152-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 982EB114EAB; Tue, 17 Nov 2026 13:16:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id B9793602AE1; Tue, 17 Nov 2026 10:16:50 +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=1794910610;
	b=CH4xTEhFZBw59IdEcJzi1YB+oqm+RHah9mEZHNQREMXIPxOfEAhZH6sgm1aZEAfoyF6y
	 8nrZpjV1OZxs8R/CY5nY6XUtaIf5Nxqr8UYlpZ7/nGgItuB9SPxNN+vAkl2/XqLrH/OL9
	 FE2sc37EXpwzZzPrX33rkNdZ9x1OFyenOQGIWl2Mxp38ArP9WmRTo/gvYuiF4KwwnZmoc
	 PNCzkuciQGpnwRcc9IKa1tYCcww0KyoMC1Hegqf2496eIirldnTeJB98crxK+npGHKMqB
	 AODWupeRP119T7tAnb82FgF/EKdqALYA4KEzRWa3K2MQUU9j+2kLS7P3xv4Ey1odoAg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794910610;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:Subject:To:Cc:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence;
	bh=00d0rKx625EmsqUQ7jJLXhBseG3RZ075q6KfkxAtgN4=;
	b=Jjj0/oJcJddm1VwpcWSbpdRqIarRraWOF+ayP5xGq16towBJPVH9nxHnJR5VH+vn3/vq
	 8t83SIDNOMVjKRo0uhE8CbF/0AoNgGJUFdI33/k4diXFzq7vIDEmUDnzOLON9sDbnfeUE
	 fVSPJYsFkaeMZ//4+914Mbix0VdgTsTAhHTa6gw37ZCXH4W6gPXQ9agrafEZEwGlAFKcJ
	 LYFm75+Y3tnDLOG4hc0zRiOynN/GKm20Bj5I6D9EscYWb3HM15+nH+hPCeXDPMZ5pYDDK
	 O7Ao7kVlbkzXsCUUW5U9fY03uhcttrxFHmKCrsmUY7JVAi6KPp2cczgTYc5YbSN0BYA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=CKx+ZM9S;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.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 16CA4606A336;
	Tue, 17 Nov 2026 10:16:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=CKx+ZM9S
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.139
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794910609;
	b=PL9P9xzWBeYWJXx1cWYCfzdas6JSibyu2qc4mtnSi+FEjw+fvetVXyh50ab84neIovsu
	 uzzLSvNhLnZpa21Kh5oDNjwhWnJXkgfqqmpLseK3x107kGqWEkw3bW6FFcBaFSmBr3l5L
	 z7HFNpWa3ENhKe9/3+oZlpHTcDfXcv2ZPTtfYvytpC1meqUHrGANVZmaK70gshVjrwIBx
	 +rev5Bvm+eXSbQc/z2EoJEkm8OFgs3cXcH96NNfBlZ467mY8enSUC+FQTRKZ2JDSVB7OQ
	 7JJQUTV3WTz6NVvnDZ/C5Pak5r9dZl+Yz42RnJNnEV2Fk4MG4Pp1+isrKyGNSLJ+iew==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794910609;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 Subject:To:Cc:Date:Message-ID;
	bh=00d0rKx625EmsqUQ7jJLXhBseG3RZ075q6KfkxAtgN4=;
	b=sVpGtGJerBk/xPw1uWpNlRCeR09D7bxZYZVpemk5pvn8Eiy6h7oZe3bAD8/3xwtx3cyi
	 MYJ464BtCZGIpkB8twHD5ROl5qrC1Sekyh/vqKX2ndXXZuPR7kEcIuUcKtC9BGO1Q5Gb/
	 TKM07wtohGuFMvrKzIPlOW7vYThe8R937ueEVcbjVkWSrZq16zZIZo55mfn1OKdde2XDo
	 V/HT6pqJXLg05VCqiVoT/JSHGUAapNsagsSjOjWZLI5ljsGm8qh67fzZ3OBJ+RrscGwnp
	 TuxdLvHwwFTpNxL8p0L/iA7gSLbX8yJqVfSpumhWiISFqY9RLs834Htt4V3YXIK0/dQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=CKx+ZM9S;
	arc=none smtp.remote-ip=111.22.67.139
X-Received: from cmccmta6.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B392606A31C;
	Tue, 17 Nov 2026 10:16:47 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B392606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=CKx+ZM9StnyRJteDfdPI7NMboCDv/TEXfaFzqJ+PHrDmb7gIQFnZtjw9fDc5ZYoh1MlWCfkvroolz
	 hJnzze18wbmehSgYuhX/Iurwz5NwcyVH8pxe6SvkIJyn5Wk0jlBb8tclLWCB/HKRnBTx1OliE+wI3H
	 e60nMdjH+x7hlS80=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app01-12001 (RichMail) with SMTP id 2ee16afc298a11f-e5a34;
	Tue, 17 Nov 2026 18:16:46 +0800 (CST)
X-RM-TRANSID: 2ee16afc298a11f-e5a34
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from [198.18.0.50] (unknown[223.108.79.102])
	by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16afc298c43c-ad895;
	Tue, 17 Nov 2026 18:16:46 +0800 (CST)
X-RM-TRANSID: 2ee16afc298c43c-ad895
X-Cc: dsahern@kernel.org,
    idosch@nvidia.com,
    davem@davemloft.net,
    edumazet@kernel.org,
    kuba@kernel.org,
    pabeni@redhat.com,
    horms@kernel.org,
    linux-kernel@vger.kernel.org,
    kuniyu@google.com,
    xeb@mail.ru,
    yana06070@163.com,
    netdev-bot+sashiko@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