Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels
@ 2026-11-22 13:42 Xia Yan
  2026-11-22 15:12 ` Ido Schimmel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Xia Yan @ 2026-11-22 13:42 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. The same helper also handles ip6gretap
and ip6erspan devices.

An L2 tunnel can therefore change its parameters to match another L2
tunnel, and incoming packets can be delivered to the wrong interface.
An L3 tunnel with matching parameters can also make a valid L2 update
fail with EEXIST.

Use ip6gre_tunnel_find() with dev->type, as the newlink paths do. This
also matches the device-type check in IPv4 ip_tunnel_changelink().

Found while comparing the duplicate checks in newlink and changelink.
Reproduced under UML using existing netlink interfaces, without kernel
instrumentation or fault injection. With an IPv6 underlay named under
already configured:

  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. After the fix, it fails with EEXIST and tap2 is unchanged.

Tested on net-next under UML with W=1 builds before and after the change.
Standalone tests covered duplicate and valid updates for ip6gretap and
ip6erspan, including receive-interface and payload checks, plus an L3 GRE
control. Kernel selftests were not run.

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

Notes (ip6gre-v5-mail):
    Changes in v5:
    - Return to the minimal one-line v1 change, as requested by Ido Schimmel.
    - Rebase onto current net-next.
    
    v4: https://lore.kernel.org/netdev/179491056935.741041.1816208847037703396.ip6gre-v4@cmss.chinamobile.com/
    Review: https://lore.kernel.org/netdev/20261122123555.GA2812544@shredder/
    
    Current UML build and runtime baseline: eb6d6c80d35449c27471b1874f13066c09a8964d.
    The v1 x86_64 W=1 allmodconfig- and allyesconfig-derived full builds used
    net 7076f684d513. Those full builds were not repeated for this rebase.

 net/ipv6/ip6_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 26c0e1c4de18f8b44ceb05d01673aaadfbcbd5ef..9f1e58f9326afd27d097431ffe62efb0aaaaf58a 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -2064,7 +2064,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
 
 	ip6gre_netlink_parms(data, p_p);
 
-	t = ip6gre_tunnel_locate(net, p_p, 0);
+	t = ip6gre_tunnel_find(net, p_p, dev->type);
 
 	if (t) {
 		if (t->dev != dev)

base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
-- 
2.43.0




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

* Re: [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels
  2026-11-22 13:42 [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels Xia Yan
@ 2026-11-22 15:12 ` Ido Schimmel
  2026-11-23  5:07 ` Hangbin Liu
  2026-11-23 13:44 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2026-11-22 15:12 UTC (permalink / raw)
  To: Xia Yan
  Cc: netdev, dsahern, davem, edumazet, kuba, pabeni, horms,
	linux-kernel, kuniyu, xeb, yana06070, netdev-bot+sashiko

On Sun, Nov 22, 2026 at 09:42:44PM +0800, Xia Yan wrote:
> ip6gre_changelink_common() calls ip6gre_tunnel_locate(), which only
> looks for ARPHRD_IP6GRE devices. The same helper also handles ip6gretap
> and ip6erspan devices.
> 
> An L2 tunnel can therefore change its parameters to match another L2
> tunnel, and incoming packets can be delivered to the wrong interface.
> An L3 tunnel with matching parameters can also make a valid L2 update
> fail with EEXIST.
> 
> Use ip6gre_tunnel_find() with dev->type, as the newlink paths do. This
> also matches the device-type check in IPv4 ip_tunnel_changelink().
> 
> Found while comparing the duplicate checks in newlink and changelink.
> Reproduced under UML using existing netlink interfaces, without kernel
> instrumentation or fault injection. With an IPv6 underlay named under
> already configured:
> 
>   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. After the fix, it fails with EEXIST and tap2 is unchanged.
> 
> Tested on net-next under UML with W=1 builds before and after the change.
> Standalone tests covered duplicate and valid updates for ip6gretap and
> ip6erspan, including receive-interface and payload checks, plus an L3 GRE
> control. Kernel selftests were not run.
> 
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels
  2026-11-22 13:42 [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels Xia Yan
  2026-11-22 15:12 ` Ido Schimmel
@ 2026-11-23  5:07 ` Hangbin Liu
  2026-11-23 13:44 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Hangbin Liu @ 2026-11-23  5:07 UTC (permalink / raw)
  To: Xia Yan
  Cc: netdev, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
	linux-kernel, kuniyu, xeb, yana06070, netdev-bot+sashiko

On Sun, Nov 22, 2026 at 09:42:44PM +0800, Xia Yan wrote:
> ip6gre_changelink_common() calls ip6gre_tunnel_locate(), which only
> looks for ARPHRD_IP6GRE devices. The same helper also handles ip6gretap
> and ip6erspan devices.
> 
> An L2 tunnel can therefore change its parameters to match another L2
> tunnel, and incoming packets can be delivered to the wrong interface.
> An L3 tunnel with matching parameters can also make a valid L2 update
> fail with EEXIST.
> 
> Use ip6gre_tunnel_find() with dev->type, as the newlink paths do. This
> also matches the device-type check in IPv4 ip_tunnel_changelink().
> 
> Found while comparing the duplicate checks in newlink and changelink.
> Reproduced under UML using existing netlink interfaces, without kernel
> instrumentation or fault injection. With an IPv6 underlay named under
> already configured:
> 
>   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. After the fix, it fails with EEXIST and tap2 is unchanged.
> 
> Tested on net-next under UML with W=1 builds before and after the change.
> Standalone tests covered duplicate and valid updates for ip6gretap and
> ip6erspan, including receive-interface and payload checks, plus an L3 GRE
> control. Kernel selftests were not run.
> 
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
> ---
> 
> Notes (ip6gre-v5-mail):
>     Changes in v5:
>     - Return to the minimal one-line v1 change, as requested by Ido Schimmel.
>     - Rebase onto current net-next.
>     
>     v4: https://lore.kernel.org/netdev/179491056935.741041.1816208847037703396.ip6gre-v4@cmss.chinamobile.com/
>     Review: https://lore.kernel.org/netdev/20261122123555.GA2812544@shredder/
>     
>     Current UML build and runtime baseline: eb6d6c80d35449c27471b1874f13066c09a8964d.
>     The v1 x86_64 W=1 allmodconfig- and allyesconfig-derived full builds used
>     net 7076f684d513. Those full builds were not repeated for this rebase.
> 
>  net/ipv6/ip6_gre.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 26c0e1c4de18f8b44ceb05d01673aaadfbcbd5ef..9f1e58f9326afd27d097431ffe62efb0aaaaf58a 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -2064,7 +2064,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
>  
>  	ip6gre_netlink_parms(data, p_p);
>  
> -	t = ip6gre_tunnel_locate(net, p_p, 0);
> +	t = ip6gre_tunnel_find(net, p_p, dev->type);
>  
>  	if (t) {
>  		if (t->dev != dev)
> 
> base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
> -- 
> 2.43.0
> 
> 
> 

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>

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

* Re: [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels
  2026-11-22 13:42 [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels Xia Yan
  2026-11-22 15:12 ` Ido Schimmel
  2026-11-23  5:07 ` Hangbin Liu
@ 2026-11-23 13:44 ` netdev-bot+sashiko
  2026-11-23 18:26   ` Ido Schimmel
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 13:44 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 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · 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] The patch says changelink now checks duplicates "as the
  newlink paths do", but it copies only half of that check.
- [Low] The patch fixes a long-standing bug that users can see, but the
  commit has no Fixes: tag.

--

ip6_gre: fix changelink conflict checks for L2 tunnels

ip6gre_changelink_common() used to check for conflicting tunnels through
ip6gre_tunnel_locate(), which only searches for ARPHRD_IP6GRE devices.
This patch calls ip6gre_tunnel_find() with dev->type instead. That stops
ip6gretap and ip6erspan devices from being changelinked onto another L2
tunnel's parameters, and stops L3 tunnels from causing a spurious EEXIST
on L2 updates.

> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 26c0e1c4de18f..9f1e58f9326af 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -2064,7 +2064,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
>  
>  	ip6gre_netlink_parms(data, p_p);
>  
> -	t = ip6gre_tunnel_locate(net, p_p, 0);
> +	t = ip6gre_tunnel_find(net, p_p, dev->type);
>  
>  	if (t) {
>  		if (t->dev != dev)

[Severity: Medium]
The commit message says this matches the newlink paths. However, the
newlink paths skip ip6gre_tunnel_find() for collect_md tunnels:

net/ipv6/ip6_gre.c:ip6gre_newlink() {
    ...
	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;
	}
    ...
}

ip6erspan_newlink() does the same, using ign->collect_md_tun_erspan.

ip6gre_tunnel_link() still puts collect_md tunnels in the normal hash
buckets. So two ARPHRD_ETHER devices with the same wildcard parameters
(laddr = raddr = ::, i_key = 0, link = 0) can land in one bucket. Two
examples are an ip6gretap external device next to an ip6erspan external
device, or a plain wildcard ip6gretap created before an ip6gretap
external.

Can this lookup now return the other device and reject a valid update
with -EEXIST? For example:

  ip link add gt type ip6gretap external
  ip link add es type ip6erspan external
  ip link set gt type ip6gretap external ttl 64

hlist_add_head_rcu() puts es at the head of the bucket, so
ip6gre_tunnel_find(net, p_p, ARPHRD_ETHER) returns es. Because
es->dev != gt, ip6gre_changelink_common() returns -EEXIST.

Before this patch the lookup used ARPHRD_IP6GRE. It matched neither
device, so the update succeeded.

This seems to be the same kind of spurious EEXIST that the commit message
describes, now caused by an L2 peer instead of an L3 one. Should
changelink skip or filter collect_md peers the way newlink does?

[Severity: Low]
This isn't a bug, but should the patch carry a Fixes: tag so it gets
picked up for stable? The commit only has a Signed-off-by trailer and is
based on net-next.

The changelink lookup goes through ip6gre_tunnel_locate(), which
hard-codes ARPHRD_IP6GRE:

	t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);

That looks like it dates back to the original implementation, which added
changelink for both ip6gre and ip6gretap:

Fixes: c12b395a4664 ("gre: Support GRE over IPv6")

The lookup was later moved into ip6gre_changelink_common() by
c8632fc30bb0 ("net: ip6_gre: Split up ip6gre_changelink()").

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179535496489.1244648.10031965997557933761.ip6gre-v5%40cmss.chinamobile.com

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

* Re: [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels
  2026-11-23 13:44 ` netdev-bot+sashiko
@ 2026-11-23 18:26   ` Ido Schimmel
  0 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2026-11-23 18:26 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: yanxia, netdev, dsahern, davem, edumazet, kuba, pabeni, horms,
	linux-kernel, kuniyu, xeb, yana06070

On Mon, Nov 23, 2026 at 01:44:10PM +0000, netdev-bot+sashiko@kernel.org wrote:
> [Severity: Medium]
> The commit message says this matches the newlink paths. However, the
> newlink paths skip ip6gre_tunnel_find() for collect_md tunnels:
> 
> net/ipv6/ip6_gre.c:ip6gre_newlink() {
>     ...
> 	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;
> 	}
>     ...
> }
> 
> ip6erspan_newlink() does the same, using ign->collect_md_tun_erspan.
> 
> ip6gre_tunnel_link() still puts collect_md tunnels in the normal hash
> buckets. So two ARPHRD_ETHER devices with the same wildcard parameters
> (laddr = raddr = ::, i_key = 0, link = 0) can land in one bucket. Two
> examples are an ip6gretap external device next to an ip6erspan external
> device, or a plain wildcard ip6gretap created before an ip6gretap
> external.
> 
> Can this lookup now return the other device and reject a valid update
> with -EEXIST? For example:
> 
>   ip link add gt type ip6gretap external
>   ip link add es type ip6erspan external
>   ip link set gt type ip6gretap external ttl 64
> 
> hlist_add_head_rcu() puts es at the head of the bucket, so
> ip6gre_tunnel_find(net, p_p, ARPHRD_ETHER) returns es. Because
> es->dev != gt, ip6gre_changelink_common() returns -EEXIST.
> 
> Before this patch the lookup used ARPHRD_IP6GRE. It matched neither
> device, so the update succeeded.

No:

# uname -a
Linux virtme-ng 7.4.0-rc3-virtme-g57f165ff2f30 #103 SMP PREEMPT_DYNAMIC 0 x86_64 GNU/Linux
# ip link add gt type ip6gretap external
# ip link add es type ip6erspan external
# ip link set gt type ip6gretap external ttl 64
RTNETLINK answers: File exists

It failed even before the patch since the lookup resolved the fallback
tunnel (ip6gre0).

Regardless, unclear what's the use case for configuring two such
external devices in a single netns. By the amount of reviews that these
drivers are getting (unless the patch is simple of course), I guess
nobody has such a setup.

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

end of thread, other threads:[~2026-11-23 18:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 13:42 [PATCH net-next v5] ip6_gre: fix changelink conflict checks for L2 tunnels Xia Yan
2026-11-22 15:12 ` Ido Schimmel
2026-11-23  5:07 ` Hangbin Liu
2026-11-23 13:44 ` netdev-bot+sashiko
2026-11-23 18:26   ` Ido Schimmel

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