Skip to content

Commit

Permalink
netns: fix addrconf_ifdown kernel panic
Browse files Browse the repository at this point in the history
When a network namespace is destroyed the network interfaces are
all unregistered, making addrconf_ifdown called by the netdevice
notifier. 
In the other hand, the addrconf exit method does a loop on the network
devices and does addrconf_ifdown on each of them. But the ordering of 
the netns subsystem is not right because it uses the register_pernet_device
instead of register_pernet_subsys. If we handle the loopback as
any network device, we can safely use register_pernet_subsys.

But if we use register_pernet_subsys, the addrconf exit method will do
exactly what was already done with the unregistering of the network
devices. So in definitive, this code is pointless.

I removed the netns addrconf exit method and moved the code to the
addrconf cleanup function.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Lezcano authored and David S. Miller committed Mar 3, 2009
1 parent b325fdd commit 176c39a
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2611,9 +2611,6 @@ static int addrconf_ifdown(struct net_device *dev, int how)

ASSERT_RTNL();

if ((dev->flags & IFF_LOOPBACK) && how == 1)
how = 0;

rt6_ifdown(net, dev);
neigh_ifdown(&nd_tbl, dev);

Expand Down Expand Up @@ -4448,25 +4445,6 @@ int unregister_inet6addr_notifier(struct notifier_block *nb)

EXPORT_SYMBOL(unregister_inet6addr_notifier);

static void addrconf_net_exit(struct net *net)
{
struct net_device *dev;

rtnl_lock();
/* clean dev list */
for_each_netdev(net, dev) {
if (__in6_dev_get(dev) == NULL)
continue;
addrconf_ifdown(dev, 1);
}
addrconf_ifdown(net->loopback_dev, 2);
rtnl_unlock();
}

static struct pernet_operations addrconf_net_ops = {
.exit = addrconf_net_exit,
};

/*
* Init / cleanup code
*/
Expand Down Expand Up @@ -4508,10 +4486,6 @@ int __init addrconf_init(void)
if (err)
goto errlo;

err = register_pernet_device(&addrconf_net_ops);
if (err)
return err;

register_netdevice_notifier(&ipv6_dev_notf);

addrconf_verify(0);
Expand Down Expand Up @@ -4541,15 +4515,22 @@ int __init addrconf_init(void)
void addrconf_cleanup(void)
{
struct inet6_ifaddr *ifa;
struct net_device *dev;
int i;

unregister_netdevice_notifier(&ipv6_dev_notf);
unregister_pernet_device(&addrconf_net_ops);

unregister_pernet_subsys(&addrconf_ops);

rtnl_lock();

/* clean dev list */
for_each_netdev(&init_net, dev) {
if (__in6_dev_get(dev) == NULL)
continue;
addrconf_ifdown(dev, 1);
}
addrconf_ifdown(init_net.loopback_dev, 2);

/*
* Check hash table.
*/
Expand All @@ -4570,6 +4551,4 @@ void addrconf_cleanup(void)

del_timer(&addr_chk_timer);
rtnl_unlock();

unregister_pernet_subsys(&addrconf_net_ops);
}

0 comments on commit 176c39a

Please sign in to comment.