Skip to content

Commit 88b9cfc

Browse files
q2venkuba-moo
authored andcommitted
net: fib_rules: Convert RTM_DELRULE to per-netns RTNL.
fib_nl_delrule() is the doit() handler for RTM_DELRULE but also called from vrf_newlink() in case something fails in vrf_add_fib_rules(). In the latter case, RTNL is already held and the 4th arg is true. Let's hold per-netns RTNL in fib_delrule() if rtnl_held is false. Now we can place ASSERT_RTNL_NET() in call_fib_rule_notifiers(). Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Tested-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250207072502.87775-9-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 1cf770d commit 88b9cfc

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

net/core/fib_rules.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ static int call_fib_rule_notifiers(struct net *net,
371371
.rule = rule,
372372
};
373373

374-
ASSERT_RTNL();
374+
ASSERT_RTNL_NET(net);
375+
375376
/* Paired with READ_ONCE() in fib_rules_seq() */
376377
WRITE_ONCE(ops->fib_rules_seq, ops->fib_rules_seq + 1);
377378
return call_fib_notifiers(net, event_type, &info.info);
@@ -944,6 +945,9 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,
944945
if (err)
945946
goto errout;
946947

948+
if (!rtnl_held)
949+
rtnl_net_lock(net);
950+
947951
err = fib_nl2rule_rtnl(nlrule, ops, tb, extack);
948952
if (err)
949953
goto errout_free;
@@ -998,17 +1002,21 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,
9981002
}
9991003
}
10001004

1001-
call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops,
1002-
NULL);
1003-
notify_rule_change(RTM_DELRULE, rule, ops, nlh,
1004-
NETLINK_CB(skb).portid);
1005+
call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops, NULL);
1006+
1007+
if (!rtnl_held)
1008+
rtnl_net_unlock(net);
1009+
1010+
notify_rule_change(RTM_DELRULE, rule, ops, nlh, NETLINK_CB(skb).portid);
10051011
fib_rule_put(rule);
10061012
flush_route_cache(ops);
10071013
rules_ops_put(ops);
10081014
kfree(nlrule);
10091015
return 0;
10101016

10111017
errout_free:
1018+
if (!rtnl_held)
1019+
rtnl_net_unlock(net);
10121020
kfree(nlrule);
10131021
errout:
10141022
rules_ops_put(ops);
@@ -1019,7 +1027,7 @@ EXPORT_SYMBOL_GPL(fib_delrule);
10191027
static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
10201028
struct netlink_ext_ack *extack)
10211029
{
1022-
return fib_delrule(sock_net(skb->sk), skb, nlh, extack, true);
1030+
return fib_delrule(sock_net(skb->sk), skb, nlh, extack, false);
10231031
}
10241032

10251033
static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
@@ -1334,7 +1342,8 @@ static struct pernet_operations fib_rules_net_ops = {
13341342
static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] __initconst = {
13351343
{.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule,
13361344
.flags = RTNL_FLAG_DOIT_PERNET},
1337-
{.msgtype = RTM_DELRULE, .doit = fib_nl_delrule},
1345+
{.msgtype = RTM_DELRULE, .doit = fib_nl_delrule,
1346+
.flags = RTNL_FLAG_DOIT_PERNET},
13381347
{.msgtype = RTM_GETRULE, .dumpit = fib_nl_dumprule,
13391348
.flags = RTNL_FLAG_DUMP_UNLOCKED},
13401349
};

0 commit comments

Comments
 (0)