X Xia Yan #
Message details and related content
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 <redacted> --- 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
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