* [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 related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v3] ip6_gre: fix changelink conflict checks for L2 tunnels
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
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 7:14 UTC (permalink / raw)
To: yanxia
Cc: netdev, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
linux-kernel, kuniyu, xeb, yana06070, netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In ip6gre_changelink_common() (net/ipv6/ip6_gre.c), the new
`if (!nt->parms.collect_md)` guard (line 2051) skips the duplicate…
- [Medium] After this patch, ip6gre_changelink_common() treats any
ip6gre_tunnel_find(net, p_p, dev->type) hit on another device as…
- [Low] The patch fixes a user-visible bug in ip6gre_changelink_common()
(net/ipv6/ip6_gre.c).
--
ip6_gre: fix changelink conflict checks for L2 tunnels
This patch changes ip6gre_changelink_common(). Ordinary devices are now
checked with ip6gre_tunnel_find() using dev->type, replacing
ip6gre_tunnel_locate(), which only searched ARPHRD_IP6GRE devices.
Metadata devices skip the duplicate search entirely. The encapsulation
setup now runs after the conflict and unregistering checks.
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
[Severity: Low]
This fixes a user-visible bug: received frames go to the wrong tunnel.
Could it carry a Fixes: tag?
The L2 changelink path has used ip6gre_tunnel_locate(net, &p, 0) since
the ip6gretap kind was added. That function hardcodes ARPHRD_IP6GRE:
t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);
That looks like it would be:
Fixes: c12b395a4664 ("gre: Support GRE over IPv6")
The notes say this was tested on net-next. Whether it should go through
net instead is for the maintainers to decide, since the fix also makes
some previously accepted configurations fail.
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index b5d6ed8f0c369..0a113bc8def95 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);
>
[ ... ]
> 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) {
[Severity: Medium]
Does this guard also remove the existing duplicate check for L3 ip6gre
metadata devices?
Before this patch, every changelink went through
ip6gre_tunnel_locate(net, p_p, 0), which searched ARPHRD_IP6GRE devices.
So an ip6gre external device could not be moved onto the parameters of
an existing ip6gre tunnel:
ip link add g1 type ip6gre local A remote B key 5
ip link add md0 type ip6gre external
ip link set md0 type ip6gre external local A remote B key 5
The last command used to fail with EEXIST. With this guard the search is
skipped and the command succeeds. ip6gre_changelink() then does:
ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
ip6gre_tunnel_link_md(ign, t);
ip6gre_tunnel_link(ign, t);
ip6gre_tunnel_link() puts md0 at the head of g1's bucket with
hlist_add_head_rcu(). ip6gre_tunnel_lookup() ignores collect_md and
returns the first score-0 match.
Would md0 then receive the traffic meant for g1?
The commit message gives "A duplicate can receive traffic intended for
the original tunnel" as the reason for the fix. The subject only
mentions L2 tunnels. The message does say metadata devices skip the
search "as newlink does", but it doesn't say this relaxes a check that
L3 ip6gre already had.
Was that intended? If so, could the commit message say so?
The same applies to L2: an ip6gretap or ip6erspan metadata device can
still be changed into a duplicate of an ordinary tunnel of the same type
and take its traffic. So changelink can still create duplicates; the
check only covers ordinary devices.
> + t = ip6gre_tunnel_find(net, p_p, dev->type);
> + if (t && t->dev != dev)
> return ERR_PTR(-EEXIST);
[Severity: Medium]
Can this reject an update to an ordinary L2 tunnel that doesn't change
its hash parameters, when a metadata device with the same parameters
exists?
For metadata devices, ip6gre_newlink() and ip6erspan_newlink() never
call ip6gre_tunnel_find():
if (nt->parms.collect_md) {
if (rtnl_dereference(ign->collect_md_tun))
err = -EEXIST;
} else {
if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
err = -EEXIST;
}
So a metadata device can be linked at the head of the same bucket as an
existing ordinary device with identical parms. For example:
ip link add tap0 type ip6gretap
ip link add tapmd type ip6gretap external
ip link set tap0 type ip6gretap ttl 10
In the last command, ip6gre_netlink_parms() zeroes p_p, so laddr, raddr,
key and link all match tapmd. ip6gre_tunnel_find(net, p_p, ARPHRD_ETHER)
stops at the first match in the bucket, which is tapmd. So t->dev != dev
and this returns -EEXIST, even though tap0's hash parameters are
unchanged.
Before the patch the search used ARPHRD_IP6GRE. tapmd didn't match, and
the update succeeded.
The commit message says a match on a metadata device remains a
conflict. Is that meant to cover this case too, where the result
depends on bucket insertion order?
Returning the first match works for newlink, because the new device is
never in the table yet. Changelink needs "any match other than dev"
instead.
> - } else {
> - t = nt;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179455350258.84965.17518172977020586093.ip6gre-v3%40cmss.chinamobile.com
^ 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