• Nicolas Dichtel's avatar
    ip6tnl: fix double free of fb_tnl_dev on exit · 38c963f2
    Nicolas Dichtel authored
    [ No relevant upstream commit. ]
    
    This problem was fixed upstream by commit 1e9f3d6f ("ip6tnl: fix use after
    free of fb_tnl_dev").
    The upstream patch depends on upstream commit 0bd87628
    
     ("ip6tnl: add x-netns
    support"), which was not backported into 3.10 branch.
    
    First, explain the problem: when the ip6_tunnel module is unloaded,
    ip6_tunnel_cleanup() is called.
    rmmod ip6_tunnel
    => ip6_tunnel_cleanup()
      => rtnl_link_unregister()
        => __rtnl_kill_links()
          => for_each_netdev(net, dev) {
            if (dev->rtnl_link_ops == ops)
            	ops->dellink(dev, &list_kill);
            }
    At this point, the FB device is deleted (and all ip6tnl tunnels).
      => unregister_pernet_device()
        => unregister_pernet_operations()
          => ops_exit_list()
            => ip6_tnl_exit_net()
              => ip6_tnl_destroy_tunnels()
                => t = rtnl_dereference(ip6n->tnls_wc[0]);
                   unregister_netdevice_queue(t->dev, &list);
    We delete the FB device a second time here!
    
    The previous fix removes these lines, which fix this double free. But the patch
    introduces a memory leak when a netns is destroyed, because the FB device is
    never deleted. By adding an rtnl ops which delete all ip6tnl device excepting
    the FB device, we can keep this exlicit removal in ip6_tnl_destroy_tunnels().
    
    CC: Steven Rostedt <rostedt@goodmis.org>
    CC: Willem de Bruijn <willemb@google.com>
    Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
    Reported-by: default avatarSteven Rostedt <srostedt@redhat.com>
    Tested-by: Steven Rostedt <srostedt@redhat.com> (and our entire MRG team)
    Tested-by: default avatar"Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
    Tested-by: default avatarJohn Kacur <jkacur@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    38c963f2
ip6_tunnel.c 43.5 KB