Skip to content

Commit ebb9fed

Browse files
Eric Dumazetdavem330
authored andcommitted
fib: fix fib_nl_newrule()
Some panic reports in fib_rules_lookup() show a rule could have a NULL pointer as a next pointer in the rules_list. This can actually happen because of a bug in fib_nl_newrule() : It checks if current rule is the destination of unresolved gotos. (Other rules have gotos to this about to be inserted rule) Problem is it does the resolution of the gotos before the rule is inserted in the rules_list (and has a valid next pointer) Fix this by moving the rules_list insertion before the changes on gotos. A lockless reader can not any more follow a ctarget pointer, unless destination is ready (has a valid next pointer) Reported-by: Oleg A. Arkhangelsky <sysoleg@yandex.ru> Reported-by: Joe Buehler <aspam@cox.net> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1941bf8 commit ebb9fed

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎net/core/fib_rules.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
373373

374374
fib_rule_get(rule);
375375

376+
if (last)
377+
list_add_rcu(&rule->list, &last->list);
378+
else
379+
list_add_rcu(&rule->list, &ops->rules_list);
380+
376381
if (ops->unresolved_rules) {
377382
/*
378383
* There are unresolved goto rules in the list, check if
@@ -395,11 +400,6 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
395400
if (unresolved)
396401
ops->unresolved_rules++;
397402

398-
if (last)
399-
list_add_rcu(&rule->list, &last->list);
400-
else
401-
list_add_rcu(&rule->list, &ops->rules_list);
402-
403403
notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
404404
flush_route_cache(ops);
405405
rules_ops_put(ops);

0 commit comments

Comments
 (0)