Skip to content

Commit

Permalink
net: Protect iterations over net::fib_notifier_ops in fib_seq_sum()
Browse files Browse the repository at this point in the history
There is at least unlocked deletion of net->ipv4.fib_notifier_ops
from net::fib_notifier_ops:

ip_fib_net_exit()
  rtnl_unlock()
  fib4_notifier_exit()
    fib_notifier_ops_unregister(net->ipv4.notifier_ops)
      list_del_rcu(&ops->list)

So fib_seq_sum() can't use rtnl_lock() only for protection.

The possible solution could be to use rtnl_lock()
in fib_notifier_ops_unregister(), but this adds
a possible delay during net namespace creation,
so we better use rcu_read_lock() till someone
really needs the mutex (if that happens).

Signed-off-by: Kirill Tkhai <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Kirill Tkhai authored and davem330 committed Nov 15, 2017
1 parent 0940095 commit 11bf284
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/core/fib_notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ static unsigned int fib_seq_sum(void)

rtnl_lock();
for_each_net(net) {
list_for_each_entry(ops, &net->fib_notifier_ops, list) {
rcu_read_lock();
list_for_each_entry_rcu(ops, &net->fib_notifier_ops, list) {
if (!try_module_get(ops->owner))
continue;
fib_seq += ops->fib_seq_read(net);
module_put(ops->owner);
}
rcu_read_unlock();
}
rtnl_unlock();

Expand Down

0 comments on commit 11bf284

Please sign in to comment.