Skip to content

Commit 7fa7cb7

Browse files
Eric Dumazetdavem330
authored andcommitted
fib: use atomic_inc_not_zero() in fib_rules_lookup
It seems we dont use appropriate refcount increment in an rcu_read_lock() protected section. fib_rule_get() might increment a null refcount and bad things could happen. While fib_nl_delrule() respects an rcu grace period before calling fib_rule_put(), fib_rules_cleanup_ops() calls fib_rule_put() without a grace period. Note : after this patch, we might avoid the synchronize_rcu() call done in fib_nl_delrule() Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 15fc1f7 commit 7fa7cb7

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎net/core/fib_rules.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
225225
err = ops->action(rule, fl, flags, arg);
226226

227227
if (err != -EAGAIN) {
228-
fib_rule_get(rule);
229-
arg->rule = rule;
230-
goto out;
228+
if (likely(atomic_inc_not_zero(&rule->refcnt))) {
229+
arg->rule = rule;
230+
goto out;
231+
}
232+
break;
231233
}
232234
}
233235

0 commit comments

Comments
 (0)