aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2015-03-31 14:01:46 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-02 20:52:34 -0400
commit419df12fb5fa558451319276838c1842f2b11f8f (patch)
tree711c055fc40c8972b9f3cf91c572a00ca80ed7cb
parented785309c94445dd90e242370e1f7bb034e008fd (diff)
net: move fib_rules_unregister() under rtnl lock
We have to hold rtnl lock for fib_rules_unregister() otherwise the following race could happen: fib_rules_unregister(): fib_nl_delrule(): ... ... ... ops = lookup_rules_ops(); list_del_rcu(&ops->list); list_for_each_entry(ops->rules) { fib_rules_cleanup_ops(ops); ... list_del_rcu(); list_del_rcu(); } Note, net->rules_mod_lock is actually not needed at all, either upper layer netns code or rtnl lock guarantees we are safe. Cc: Alexander Duyck <alexander.h.duyck@redhat.com> Cc: Thomas Graf <tgraf@suug.ch> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/fib_rules.c2
-rw-r--r--net/decnet/dn_rules.c2
-rw-r--r--net/ipv4/fib_frontend.c3
-rw-r--r--net/ipv4/ipmr.c2
-rw-r--r--net/ipv6/fib6_rules.c2
-rw-r--r--net/ipv6/ip6mr.c2
6 files changed, 8 insertions, 5 deletions
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 44706e81b2e0..e4fdc9dfb2c7 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -175,9 +175,9 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
175 175
176 spin_lock(&net->rules_mod_lock); 176 spin_lock(&net->rules_mod_lock);
177 list_del_rcu(&ops->list); 177 list_del_rcu(&ops->list);
178 fib_rules_cleanup_ops(ops);
179 spin_unlock(&net->rules_mod_lock); 178 spin_unlock(&net->rules_mod_lock);
180 179
180 fib_rules_cleanup_ops(ops);
181 call_rcu(&ops->rcu, fib_rules_put_rcu); 181 call_rcu(&ops->rcu, fib_rules_put_rcu);
182} 182}
183EXPORT_SYMBOL_GPL(fib_rules_unregister); 183EXPORT_SYMBOL_GPL(fib_rules_unregister);
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c
index faf7cc3483fe..9d66a0f72f90 100644
--- a/net/decnet/dn_rules.c
+++ b/net/decnet/dn_rules.c
@@ -248,7 +248,9 @@ void __init dn_fib_rules_init(void)
248 248
249void __exit dn_fib_rules_cleanup(void) 249void __exit dn_fib_rules_cleanup(void)
250{ 250{
251 rtnl_lock();
251 fib_rules_unregister(dn_fib_rules_ops); 252 fib_rules_unregister(dn_fib_rules_ops);
253 rtnl_unlock();
252 rcu_barrier(); 254 rcu_barrier();
253} 255}
254 256
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 57be71dd6a9e..23b9b3e86f4c 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1111,11 +1111,10 @@ static void ip_fib_net_exit(struct net *net)
1111{ 1111{
1112 unsigned int i; 1112 unsigned int i;
1113 1113
1114 rtnl_lock();
1114#ifdef CONFIG_IP_MULTIPLE_TABLES 1115#ifdef CONFIG_IP_MULTIPLE_TABLES
1115 fib4_rules_exit(net); 1116 fib4_rules_exit(net);
1116#endif 1117#endif
1117
1118 rtnl_lock();
1119 for (i = 0; i < FIB_TABLE_HASHSZ; i++) { 1118 for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
1120 struct fib_table *tb; 1119 struct fib_table *tb;
1121 struct hlist_head *head; 1120 struct hlist_head *head;
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index bc40115bc394..fe54eba6d00d 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -283,8 +283,8 @@ static void __net_exit ipmr_rules_exit(struct net *net)
283 list_del(&mrt->list); 283 list_del(&mrt->list);
284 ipmr_free_table(mrt); 284 ipmr_free_table(mrt);
285 } 285 }
286 rtnl_unlock();
287 fib_rules_unregister(net->ipv4.mr_rules_ops); 286 fib_rules_unregister(net->ipv4.mr_rules_ops);
287 rtnl_unlock();
288} 288}
289#else 289#else
290#define ipmr_for_each_table(mrt, net) \ 290#define ipmr_for_each_table(mrt, net) \
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 27ca79682efb..70bc6abc0639 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -322,7 +322,9 @@ out_fib6_rules_ops:
322 322
323static void __net_exit fib6_rules_net_exit(struct net *net) 323static void __net_exit fib6_rules_net_exit(struct net *net)
324{ 324{
325 rtnl_lock();
325 fib_rules_unregister(net->ipv6.fib6_rules_ops); 326 fib_rules_unregister(net->ipv6.fib6_rules_ops);
327 rtnl_unlock();
326} 328}
327 329
328static struct pernet_operations fib6_rules_net_ops = { 330static struct pernet_operations fib6_rules_net_ops = {
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 52028f449a89..2f1fd9ffcb34 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -267,8 +267,8 @@ static void __net_exit ip6mr_rules_exit(struct net *net)
267 list_del(&mrt->list); 267 list_del(&mrt->list);
268 ip6mr_free_table(mrt); 268 ip6mr_free_table(mrt);
269 } 269 }
270 rtnl_unlock();
271 fib_rules_unregister(net->ipv6.mr6_rules_ops); 270 fib_rules_unregister(net->ipv6.mr6_rules_ops);
271 rtnl_unlock();
272} 272}
273#else 273#else
274#define ip6mr_for_each_table(mrt, net) \ 274#define ip6mr_for_each_table(mrt, net) \