net: reinstate rtnl in call_netdevice_notifiers()

Eric Biederman pointed out that not holding RTNL while calling
call_netdevice_notifiers() was racy.

This patch is a direct transcription his feedback
against commit 0115e8e30d (net: remove delay at device dismantle)

Thanks Eric !

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Tom Herbert <therbert@google.com>
Cc: Mahesh Bandewar <maheshb@google.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Gao feng <gaofeng@cn.fujitsu.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Eric Dumazet 2012-08-22 21:50:59 +00:00 committed by David S. Miller
parent 0fa7fa98db
commit 748e2d9396
5 changed files with 12 additions and 19 deletions

View file

@ -1466,8 +1466,7 @@ EXPORT_SYMBOL(unregister_netdevice_notifier);
int call_netdevice_notifiers(unsigned long val, struct net_device *dev) int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
{ {
if (val != NETDEV_UNREGISTER_FINAL) ASSERT_RTNL();
ASSERT_RTNL();
return raw_notifier_call_chain(&netdev_chain, val, dev); return raw_notifier_call_chain(&netdev_chain, val, dev);
} }
EXPORT_SYMBOL(call_netdevice_notifiers); EXPORT_SYMBOL(call_netdevice_notifiers);
@ -5782,7 +5781,11 @@ static void netdev_wait_allrefs(struct net_device *dev)
/* Rebroadcast unregister notification */ /* Rebroadcast unregister notification */
call_netdevice_notifiers(NETDEV_UNREGISTER, dev); call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
__rtnl_unlock();
rcu_barrier(); rcu_barrier();
rtnl_lock();
call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev); call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
if (test_bit(__LINK_STATE_LINKWATCH_PENDING, if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
&dev->state)) { &dev->state)) {
@ -5855,7 +5858,9 @@ void netdev_run_todo(void)
= list_first_entry(&list, struct net_device, todo_list); = list_first_entry(&list, struct net_device, todo_list);
list_del(&dev->todo_list); list_del(&dev->todo_list);
rtnl_lock();
call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev); call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
__rtnl_unlock();
if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
pr_err("network todo '%s' but state %d\n", pr_err("network todo '%s' but state %d\n",

View file

@ -711,16 +711,15 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
struct fib_rules_ops *ops; struct fib_rules_ops *ops;
ASSERT_RTNL();
switch (event) { switch (event) {
case NETDEV_REGISTER: case NETDEV_REGISTER:
ASSERT_RTNL();
list_for_each_entry(ops, &net->rules_ops, list) list_for_each_entry(ops, &net->rules_ops, list)
attach_rules(&ops->rules_list, dev); attach_rules(&ops->rules_list, dev);
break; break;
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
ASSERT_RTNL();
list_for_each_entry(ops, &net->rules_ops, list) list_for_each_entry(ops, &net->rules_ops, list)
detach_rules(&ops->rules_list, dev); detach_rules(&ops->rules_list, dev);
break; break;

View file

@ -1147,12 +1147,8 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
void *ptr) void *ptr)
{ {
struct net_device *dev = ptr; struct net_device *dev = ptr;
struct in_device *in_dev; struct in_device *in_dev = __in_dev_get_rtnl(dev);
if (event == NETDEV_UNREGISTER_FINAL)
goto out;
in_dev = __in_dev_get_rtnl(dev);
ASSERT_RTNL(); ASSERT_RTNL();
if (!in_dev) { if (!in_dev) {

View file

@ -1050,9 +1050,6 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
return NOTIFY_DONE; return NOTIFY_DONE;
} }
if (event == NETDEV_UNREGISTER_FINAL)
return NOTIFY_DONE;
in_dev = __in_dev_get_rtnl(dev); in_dev = __in_dev_get_rtnl(dev);
switch (event) { switch (event) {
@ -1064,14 +1061,14 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
fib_sync_up(dev); fib_sync_up(dev);
#endif #endif
atomic_inc(&net->ipv4.dev_addr_genid); atomic_inc(&net->ipv4.dev_addr_genid);
rt_cache_flush(dev_net(dev), -1); rt_cache_flush(net, -1);
break; break;
case NETDEV_DOWN: case NETDEV_DOWN:
fib_disable_ip(dev, 0, 0); fib_disable_ip(dev, 0, 0);
break; break;
case NETDEV_CHANGEMTU: case NETDEV_CHANGEMTU:
case NETDEV_CHANGE: case NETDEV_CHANGE:
rt_cache_flush(dev_net(dev), 0); rt_cache_flush(net, 0);
break; break;
} }
return NOTIFY_DONE; return NOTIFY_DONE;

View file

@ -2566,14 +2566,10 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
void *data) void *data)
{ {
struct net_device *dev = (struct net_device *) data; struct net_device *dev = (struct net_device *) data;
struct inet6_dev *idev; struct inet6_dev *idev = __in6_dev_get(dev);
int run_pending = 0; int run_pending = 0;
int err; int err;
if (event == NETDEV_UNREGISTER_FINAL)
return NOTIFY_DONE;
idev = __in6_dev_get(dev);
switch (event) { switch (event) {
case NETDEV_REGISTER: case NETDEV_REGISTER:
if (!idev && dev->mtu >= IPV6_MIN_MTU) { if (!idev && dev->mtu >= IPV6_MIN_MTU) {