mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v3] ip6_gre: fix changelink conflict checks for L2 tunnels
@ 2026-11-13  7:05 Xia Yan
  2026-11-17  7:14 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Xia Yan @ 2026-11-13  7:05 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
	linux-kernel, kuniyu, xeb, yana06070, netdev-bot+sashiko

ip6gre_changelink_common() calls ip6gre_tunnel_locate(), which only looks
for ARPHRD_IP6GRE devices. For ip6gretap and ip6erspan, this lets an
update create a duplicate L2 tunnel or makes a valid update fail because
of an unrelated L3 tunnel. A duplicate can receive traffic intended for
the original tunnel.

Use ip6gre_tunnel_find() with dev->type for ordinary devices. A match on
another device, including a metadata device, remains a conflict. For
metadata devices, update the device itself without the ordinary
duplicate search, as newlink does. Leave the shared find helper,
newlink, legacy ioctls and receive lookup unchanged.

Check conflicts and unregistering before applying encapsulation
parameters, so these rejected requests leave the encapsulation 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 both L2 kinds, metadata updates with ip6gre0
present, receive interfaces and tunnel metadata, legacy ioctls, and
encapsulation state after a rejected update.

Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---
Changes in v3:
- Keep the shared ip6gre_tunnel_find() unchanged, including metadata
  matches, so newlink and legacy ioctls keep their existing behavior.
- Skip the ordinary duplicate search when updating a metadata device,
  as suggested by Jakub.
- Reject an ordinary update that matches another device, including a
  metadata device, without changing receive lookup or allowing new
  same-key combinations.
- Check conflicts and unregistering before changing encapsulation.

v2: https://lore.kernel.org/netdev/20261104150330.70963-1-yanxia@cmss.chinamobile.com/
Review: https://lore.kernel.org/netdev/20261110205838.2246603-1-kuba@kernel.org/

Tested on net-next c88fd6989aea9237a60a4859139a265bfb7ddc0b with
W=1 UML builds of the baseline and this patch. Runtime checks used
custom netlink, ioctl and packet tests; kernel selftests were not run.

 net/ipv6/ip6_gre.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b5d6ed8..0a113bc 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -2046,28 +2046,25 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
 	if (dev == ign->fb_tunnel_dev)
 		return ERR_PTR(-EINVAL);
 
-	if (ip6gre_netlink_encap_parms(data, &ipencap)) {
-		int err = ip6_tnl_encap_setup(nt, &ipencap);
-
-		if (err < 0)
-			return ERR_PTR(err);
-	}
-
 	ip6gre_netlink_parms(data, p_p);
 
-	t = ip6gre_tunnel_locate(net, p_p, 0);
-
-	if (t) {
-		if (t->dev != dev)
+	if (!nt->parms.collect_md) {
+		t = ip6gre_tunnel_find(net, p_p, dev->type);
+		if (t && t->dev != dev)
 			return ERR_PTR(-EEXIST);
-	} else {
-		t = nt;
 	}
 
-	if (ip6gre_tunnel_unregistering(t))
+	if (ip6gre_tunnel_unregistering(nt))
 		return ERR_PTR(-ENODEV);
 
-	return t;
+	if (ip6gre_netlink_encap_parms(data, &ipencap)) {
+		int err = ip6_tnl_encap_setup(nt, &ipencap);
+
+		if (err < 0)
+			return ERR_PTR(err);
+	}
+
+	return nt;
 }
 
 static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],

base-commit: c88fd6989aea9237a60a4859139a265bfb7ddc0b



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-17  7:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13  7:05 [PATCH net-next v3] ip6_gre: fix changelink conflict checks for L2 tunnels Xia Yan
2026-11-17  7:14 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®