From 864150dfa31dceab6ec5ca4579a2d35ede985cb7 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Fri, 1 Sep 2017 12:15:17 +0300 Subject: net: Add module reference to FIB notifiers When a listener registers to the FIB notification chain it receives a dump of the FIB entries and rules from existing address families by invoking their dump operations. While we call into these modules we need to make sure they aren't removed. Do that by increasing their reference count before invoking their dump operations and decrease it afterwards. Fixes: 04b1d4e50e82 ("net: core: Make the FIB notification chain generic") Signed-off-by: Ido Schimmel Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller --- net/core/fib_notifier.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'net/core/fib_notifier.c') diff --git a/net/core/fib_notifier.c b/net/core/fib_notifier.c index 292aab83702f..4fc202dbdfb6 100644 --- a/net/core/fib_notifier.c +++ b/net/core/fib_notifier.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -33,8 +34,12 @@ static unsigned int fib_seq_sum(void) rtnl_lock(); for_each_net(net) { - list_for_each_entry(ops, &net->fib_notifier_ops, list) + list_for_each_entry(ops, &net->fib_notifier_ops, list) { + if (!try_module_get(ops->owner)) + continue; fib_seq += ops->fib_seq_read(net); + module_put(ops->owner); + } } rtnl_unlock(); @@ -46,8 +51,12 @@ static int fib_net_dump(struct net *net, struct notifier_block *nb) struct fib_notifier_ops *ops; list_for_each_entry_rcu(ops, &net->fib_notifier_ops, list) { - int err = ops->fib_dump(net, nb); + int err; + if (!try_module_get(ops->owner)) + continue; + err = ops->fib_dump(net, nb); + module_put(ops->owner); if (err) return err; } -- cgit v1.2.3-59-g8ed1b