public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] ip6_gre: Use cached t->net in ip6erspan_changelink().
@ 2026-04-30 10:33 Maoyi Xie
  2026-05-02 18:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Maoyi Xie @ 2026-04-30 10:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, pabeni, edumazet, dsahern, horms, willemb, kuniyu,
	shaw.leon, linux-kernel, stable

After commit 5e72ce3e3980 ("net: ipv6: Use link netns in newlink() of
rtnl_link_ops"), ip6erspan_newlink() correctly resolves the per-netns
ip6gre hash via link_net. ip6erspan_changelink() was not converted in
that series and still uses dev_net(dev), which diverges from the
device's creation netns after IFLA_NET_NS_FD migration.

This re-inserts the tunnel into the wrong per-netns hash. The
original netns keeps a stale entry. When that netns is later
destroyed, ip6gre_exit_rtnl_net() walks the stale entry, producing a
slab-use-after-free reported by KASAN, followed by a kernel BUG at
net/core/dev.c (LIST_POISON1) in unregister_netdevice_many_notify().

Reachable from an unprivileged user namespace (unshare --user
--map-root-user --net).

ip6gre_changelink() earlier in the same file already uses the cached
t->net; only ip6erspan_changelink() has the wrong shape.

Fixes: 2d665034f239 ("net: ip6_gre: Fix ip6erspan hlen calculation")
Cc: stable@vger.kernel.org # v5.15+
Signed-off-by: Maoyi Xie <maoyi.xie@ntu.edu.sg>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
---
v2 (this submission, addressing v1 review):
    - Fixes: changed to 2d665034f239 ("net: ip6_gre: Fix ip6erspan
      hlen calculation"), the commit that introduced the divergent
      ip6erspan_changelink() shape (per Xiao Liang).
    - dropped Reported-by since the SOB is the same person
      (per Kuniyuki Iwashima).
    - reverse xmas tree local variable order; reused *t instead of
      shadowing it (per Kuniyuki Iwashima).
    - added Reviewed-by Eric Dumazet, Reviewed-by Kuniyuki Iwashima.
v1: originally posted as [PATCH net 2/2] of the
    "ipv6: tunnel changelink: use cached netns pointer" series.
    The sibling patch ([PATCH net 1/2] vti6_changelink) is being
    handled in its own thread.

 net/ipv6/ip6_gre.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index dafcc0dcd..0097d4784 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -2261,10 +2261,11 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
 				struct nlattr *data[],
 				struct netlink_ext_ack *extack)
 {
-	struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
+	struct ip6_tnl *t = netdev_priv(dev);
 	struct __ip6_tnl_parm p;
-	struct ip6_tnl *t;
+	struct ip6gre_net *ign;
 
+	ign = net_generic(t->net, ip6gre_net_id);
 	t = ip6gre_changelink_common(dev, tb, data, &p, extack);
 	if (IS_ERR(t))
 		return PTR_ERR(t);
-- 
2.34.1


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

* Re: [PATCH net v2] ip6_gre: Use cached t->net in ip6erspan_changelink().
  2026-04-30 10:33 [PATCH net v2] ip6_gre: Use cached t->net in ip6erspan_changelink() Maoyi Xie
@ 2026-05-02 18:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-02 18:20 UTC (permalink / raw)
  To: Maoyi Xie
  Cc: netdev, davem, kuba, pabeni, edumazet, dsahern, horms, willemb,
	kuniyu, shaw.leon, linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 30 Apr 2026 18:33:18 +0800 you wrote:
> After commit 5e72ce3e3980 ("net: ipv6: Use link netns in newlink() of
> rtnl_link_ops"), ip6erspan_newlink() correctly resolves the per-netns
> ip6gre hash via link_net. ip6erspan_changelink() was not converted in
> that series and still uses dev_net(dev), which diverges from the
> device's creation netns after IFLA_NET_NS_FD migration.
> 
> This re-inserts the tunnel into the wrong per-netns hash. The
> original netns keeps a stale entry. When that netns is later
> destroyed, ip6gre_exit_rtnl_net() walks the stale entry, producing a
> slab-use-after-free reported by KASAN, followed by a kernel BUG at
> net/core/dev.c (LIST_POISON1) in unregister_netdevice_many_notify().
> 
> [...]

Here is the summary with links:
  - [net,v2] ip6_gre: Use cached t->net in ip6erspan_changelink().
    https://git.kernel.org/netdev/net/c/1d324c2f43f7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-05-02 18:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 10:33 [PATCH net v2] ip6_gre: Use cached t->net in ip6erspan_changelink() Maoyi Xie
2026-05-02 18:20 ` patchwork-bot+netdevbpf

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