Skip to contentSkip to conversation

net: set fib rule refcount after malloc

PATCH In review David Ahern 2 participants 2 messages Jul 13, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: set fib rule refcount after malloc

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 5361e209dd30 ("net: avoid one splat in fib_nl_delrule()")
---
 net/core/fib_rules.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/fib_rules.c +1 -2
index a0093e1b0235..fdcb1bcd2afa 100644
@@ -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])
@@ -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
Signature · 1 line
2.1.4
maintainer
#1 lore raw

From: David Ahern <[email protected]>
Date: Thu, 13 Jul 2017 13:36:40 -0700

Quoted 7 lines

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 5361e209dd30 ("net: avoid one splat in fib_nl_delrule()")

Can someone keep a scoreboard of how many bugs and arbitrary unnecessary changes get introduced because of this new refcount_t business rather than get fixed?

I'd really like to see how that pans out over the long term especially with all of the backporting pain this facility is going to cause.

Anyways, David I will apply this, thanks.