Skip to content

Commit 11bf284

Browse files
Kirill Tkhaidavem330
authored andcommitted
net: Protect iterations over net::fib_notifier_ops in fib_seq_sum()
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 <ktkhai@virtuozzo.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0940095 commit 11bf284

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/core/fib_notifier.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ static unsigned int fib_seq_sum(void)
3434

3535
rtnl_lock();
3636
for_each_net(net) {
37-
list_for_each_entry(ops, &net->fib_notifier_ops, list) {
37+
rcu_read_lock();
38+
list_for_each_entry_rcu(ops, &net->fib_notifier_ops, list) {
3839
if (!try_module_get(ops->owner))
3940
continue;
4041
fib_seq += ops->fib_seq_read(net);
4142
module_put(ops->owner);
4243
}
44+
rcu_read_unlock();
4345
}
4446
rtnl_unlock();
4547

0 commit comments

Comments
 (0)