Skip to content

Commit

Permalink
net: set fib rule refcount after malloc
Browse files Browse the repository at this point in the history
The configure callback of fib_rules_ops can change the refcnt of a
fib rule. For instance, mlxsw takes a refcnt when adding the processing
of the rule to a work queue. Thus the rule refcnt can not be reset to
to 1 afterwards. Move the refcnt setting to after the allocation.

Fixes: 5361e20 ("net: avoid one splat in fib_nl_delrule()")
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Ahern authored and David S. Miller committed Jul 13, 2017
1 parent 2683701 commit 5d89fb3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/core/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
err = -ENOMEM;
goto errout;
}
refcount_set(&rule->refcnt, 1);
rule->fr_net = net;

rule->pref = tb[FRA_PRIORITY] ? nla_get_u32(tb[FRA_PRIORITY])
Expand Down Expand Up @@ -517,8 +518,6 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
last = r;
}

refcount_set(&rule->refcnt, 1);

if (last)
list_add_rcu(&rule->list, &last->list);
else
Expand Down

0 comments on commit 5d89fb3

Please sign in to comment.