mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
net: fib_rules: Don't dump dying fib_rule in fib_rules_dump().
[ Upstream commit2821e85c05] rocker_router_fib_event() calls fib_rule_get() during RCU dump. If the fib_rule is dying, refcount_inc() will complain about it. Let's call refcount_inc_not_zero() in fib_rules_dump(). Fixes:5d7bfd1419("ipv4: fib_rules: Dump FIB rules when registering FIB notifier") Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://patch.msgid.link/20260610061744.2030996-3-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
0a8b5b74f0
commit
bb4a5b3c91
@@ -111,6 +111,11 @@ static inline void fib_rule_get(struct fib_rule *rule)
|
||||
refcount_inc(&rule->refcnt);
|
||||
}
|
||||
|
||||
static inline bool fib_rule_get_safe(struct fib_rule *rule)
|
||||
{
|
||||
return refcount_inc_not_zero(&rule->refcnt);
|
||||
}
|
||||
|
||||
static inline void fib_rule_put(struct fib_rule *rule)
|
||||
{
|
||||
if (refcount_dec_and_test(&rule->refcnt))
|
||||
|
||||
@@ -349,7 +349,7 @@ jumped:
|
||||
|
||||
if (err != -EAGAIN) {
|
||||
if ((arg->flags & FIB_LOOKUP_NOREF) ||
|
||||
likely(refcount_inc_not_zero(&rule->refcnt))) {
|
||||
likely(fib_rule_get_safe(rule))) {
|
||||
arg->rule = rule;
|
||||
goto out;
|
||||
}
|
||||
@@ -410,8 +410,12 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family,
|
||||
if (!ops)
|
||||
return -EAFNOSUPPORT;
|
||||
list_for_each_entry_rcu(rule, &ops->rules_list, list) {
|
||||
if (!fib_rule_get_safe(rule))
|
||||
continue;
|
||||
|
||||
err = call_fib_rule_notifier(nb, FIB_EVENT_RULE_ADD,
|
||||
rule, family, extack);
|
||||
fib_rule_put(rule);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user