aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2012-08-22 17:50:59 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-23 12:24:42 -0400
commit748e2d9396a18c3fd3d07d47c1b41320acf1fbf4 (patch)
tree49bde8c370615258baada1d43acda2b3fb3625c2 /net
parent0fa7fa98dbcc2789409ed24e885485e645803d7f (diff)
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 0115e8e30d6fc (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>
Diffstat (limited to 'net')
-rw-r--r--net/core/dev.c9
-rw-r--r--net/core/fib_rules.c3
-rw-r--r--net/ipv4/devinet.c6
-rw-r--r--net/ipv4/fib_frontend.c7
-rw-r--r--net/ipv6/addrconf.c6
5 files changed, 12 insertions, 19 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 0640d2a859c6..bc857fead8c8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1466,8 +1466,7 @@ EXPORT_SYMBOL(unregister_netdevice_notifier);
1466 1466
1467int call_netdevice_notifiers(unsigned long val, struct net_device *dev) 1467int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
1468{ 1468{
1469 if (val != NETDEV_UNREGISTER_FINAL) 1469 ASSERT_RTNL();
1470 ASSERT_RTNL();
1471 return raw_notifier_call_chain(&netdev_chain, val, dev); 1470 return raw_notifier_call_chain(&netdev_chain, val, dev);
1472} 1471}
1473EXPORT_SYMBOL(call_netdevice_notifiers); 1472EXPORT_SYMBOL(call_netdevice_notifiers);
@@ -5782,7 +5781,11 @@ static void netdev_wait_allrefs(struct net_device *dev)
5782 5781
5783 /* Rebroadcast unregister notification */ 5782 /* Rebroadcast unregister notification */
5784 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 5783 call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
5784
5785 __rtnl_unlock();
5785 rcu_barrier(); 5786 rcu_barrier();
5787 rtnl_lock();
5788
5786 call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev); 5789 call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
5787 if (test_bit(__LINK_STATE_LINKWATCH_PENDING, 5790 if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
5788 &dev->state)) { 5791 &dev->state)) {
@@ -5855,7 +5858,9 @@ void netdev_run_todo(void)
5855 = list_first_entry(&list, struct net_device, todo_list); 5858 = list_first_entry(&list, struct net_device, todo_list);
5856 list_del(&dev->todo_list); 5859 list_del(&dev->todo_list);
5857 5860
5861 rtnl_lock();
5858 call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev); 5862 call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
5863 __rtnl_unlock();
5859 5864
5860 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { 5865 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
5861 pr_err("network todo '%s' but state %d\n", 5866 pr_err("network todo '%s' but state %d\n",
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 585093755c23..ab7db83236c9 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -711,16 +711,15 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
711 struct net *net = dev_net(dev); 711 struct net *net = dev_net(dev);
712 struct fib_rules_ops *ops; 712 struct fib_rules_ops *ops;
713 713
714 ASSERT_RTNL();
714 715
715 switch (event) { 716 switch (event) {
716 case NETDEV_REGISTER: 717 case NETDEV_REGISTER:
717 ASSERT_RTNL();
718 list_for_each_entry(ops, &net->rules_ops, list) 718 list_for_each_entry(ops, &net->rules_ops, list)
719 attach_rules(&ops->rules_list, dev); 719 attach_rules(&ops->rules_list, dev);
720 break; 720 break;
721 721
722 case NETDEV_UNREGISTER: 722 case NETDEV_UNREGISTER:
723 ASSERT_RTNL();
724 list_for_each_entry(ops, &net->rules_ops, list) 723 list_for_each_entry(ops, &net->rules_ops, list)
725 detach_rules(&ops->rules_list, dev); 724 detach_rules(&ops->rules_list, dev);
726 break; 725 break;
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 6a5e6e4b142c..adf273f8ad2e 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1147,12 +1147,8 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
1147 void *ptr) 1147 void *ptr)
1148{ 1148{
1149 struct net_device *dev = ptr; 1149 struct net_device *dev = ptr;
1150 struct in_device *in_dev; 1150 struct in_device *in_dev = __in_dev_get_rtnl(dev);
1151
1152 if (event == NETDEV_UNREGISTER_FINAL)
1153 goto out;
1154 1151
1155 in_dev = __in_dev_get_rtnl(dev);
1156 ASSERT_RTNL(); 1152 ASSERT_RTNL();
1157 1153
1158 if (!in_dev) { 1154 if (!in_dev) {
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index fd7d9ae64f16..acdee325d972 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1050,9 +1050,6 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1050 return NOTIFY_DONE; 1050 return NOTIFY_DONE;
1051 } 1051 }
1052 1052
1053 if (event == NETDEV_UNREGISTER_FINAL)
1054 return NOTIFY_DONE;
1055
1056 in_dev = __in_dev_get_rtnl(dev); 1053 in_dev = __in_dev_get_rtnl(dev);
1057 1054
1058 switch (event) { 1055 switch (event) {
@@ -1064,14 +1061,14 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1064 fib_sync_up(dev); 1061 fib_sync_up(dev);
1065#endif 1062#endif
1066 atomic_inc(&net->ipv4.dev_addr_genid); 1063 atomic_inc(&net->ipv4.dev_addr_genid);
1067 rt_cache_flush(dev_net(dev), -1); 1064 rt_cache_flush(net, -1);
1068 break; 1065 break;
1069 case NETDEV_DOWN: 1066 case NETDEV_DOWN:
1070 fib_disable_ip(dev, 0, 0); 1067 fib_disable_ip(dev, 0, 0);
1071 break; 1068 break;
1072 case NETDEV_CHANGEMTU: 1069 case NETDEV_CHANGEMTU:
1073 case NETDEV_CHANGE: 1070 case NETDEV_CHANGE:
1074 rt_cache_flush(dev_net(dev), 0); 1071 rt_cache_flush(net, 0);
1075 break; 1072 break;
1076 } 1073 }
1077 return NOTIFY_DONE; 1074 return NOTIFY_DONE;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index e581009cb09e..6bc85f7c31e3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2566,14 +2566,10 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
2566 void *data) 2566 void *data)
2567{ 2567{
2568 struct net_device *dev = (struct net_device *) data; 2568 struct net_device *dev = (struct net_device *) data;
2569 struct inet6_dev *idev; 2569 struct inet6_dev *idev = __in6_dev_get(dev);
2570 int run_pending = 0; 2570 int run_pending = 0;
2571 int err; 2571 int err;
2572 2572
2573 if (event == NETDEV_UNREGISTER_FINAL)
2574 return NOTIFY_DONE;
2575
2576 idev = __in6_dev_get(dev);
2577 switch (event) { 2573 switch (event) {
2578 case NETDEV_REGISTER: 2574 case NETDEV_REGISTER:
2579 if (!idev && dev->mtu >= IPV6_MIN_MTU) { 2575 if (!idev && dev->mtu >= IPV6_MIN_MTU) {