Skip to content

Commit

Permalink
fib: use atomic_inc_not_zero() in fib_rules_lookup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and davem330 committed Sep 28, 2010
1 parent 15fc1f7 commit 7fa7cb7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/core/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
err = ops->action(rule, fl, flags, arg);

if (err != -EAGAIN) {
fib_rule_get(rule);
arg->rule = rule;
goto out;
if (likely(atomic_inc_not_zero(&rule->refcnt))) {
arg->rule = rule;
goto out;
}
break;
}
}

Expand Down

0 comments on commit 7fa7cb7

Please sign in to comment.