Skip to content

Commit 311fdd2

Browse files
maoyixiegregkh
authored andcommitted
ip6_gre: Use cached t->net in ip6erspan_changelink().
commit 1d324c2 upstream. After commit 5e72ce3 ("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: 2d66503 ("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> Link: https://patch.msgid.link/20260430103318.3206018-1-maoyi.xie@ntu.edu.sg Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f6e656f commit 311fdd2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

net/ipv6/ip6_gre.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,10 +2296,11 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
22962296
struct nlattr *data[],
22972297
struct netlink_ext_ack *extack)
22982298
{
2299-
struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
2299+
struct ip6_tnl *t = netdev_priv(dev);
23002300
struct __ip6_tnl_parm p;
2301-
struct ip6_tnl *t;
2301+
struct ip6gre_net *ign;
23022302

2303+
ign = net_generic(t->net, ip6gre_net_id);
23032304
t = ip6gre_changelink_common(dev, tb, data, &p, extack);
23042305
if (IS_ERR(t))
23052306
return PTR_ERR(t);

0 commit comments

Comments
 (0)