]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
fib: fix fib_nl_newrule()
authorEric Dumazet <eric.dumazet@gmail.com>
Sat, 23 Oct 2010 09:44:25 +0000 (09:44 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Oct 2010 18:42:38 +0000 (11:42 -0700)
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>
net/core/fib_rules.c

index 1bc3f253ba6c76efe7e8b97c78c2e6a72d771b23..12b43cc2f889d480238937f8bd93b9ddfaf885c6 100644 (file)
@@ -373,6 +373,11 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 
        fib_rule_get(rule);
 
+       if (last)
+               list_add_rcu(&rule->list, &last->list);
+       else
+               list_add_rcu(&rule->list, &ops->rules_list);
+
        if (ops->unresolved_rules) {
                /*
                 * 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)
        if (unresolved)
                ops->unresolved_rules++;
 
-       if (last)
-               list_add_rcu(&rule->list, &last->list);
-       else
-               list_add_rcu(&rule->list, &ops->rules_list);
-
        notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
        flush_route_cache(ops);
        rules_ops_put(ops);