ipv4: convert fib_num_tclassid_users to atomic_t
Subsystems (3)
PATCH 1/1 ipv4: convert fib_num_tclassid_users to atomic_t
From: Eric Dumazet <[email protected]>
Before commit faa041a40b9f ("ipv4: Create cleanup helper for fib_nh") changes to net->ipv4.fib_num_tclassid_users were protected by RTNL.
After the change, this is no longer the case, as free_fib_info_rcu() runs after rcu grace period, without rtnl being held.
--- include/net/ip_fib.h | 2 +- include/net/netns/ipv4.h | 2 +- net/ipv4/fib_frontend.c | 2 +- net/ipv4/fib_rules.c | 4 ++-- net/ipv4/fib_semantics.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-)
include/net/ip_fib.h +1 -1
@@ -438,7 +438,7 @@ int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,#ifdef CONFIG_IP_ROUTE_CLASSID static inline int fib_num_tclassid_users (struct net *net) { -return net->ipv4.fib_num_tclassid_users; +return atomic_read (&net->ipv4.fib_num_tclassid_users); }#else static inline int fib_num_tclassid_users (struct net *net)
include/net/netns/ipv4.h +1 -1
@@ -65,7 +65,7 @@ struct netns_ipv4 {bool fib_has_custom_local_routes;bool fib_offload_disabled;#ifdef CONFIG_IP_ROUTE_CLASSID -int fib_num_tclassid_users; +atomic_t fib_num_tclassid_users;#endif struct hlist_head *fib_table_hash;struct sock *fibnl;
net/ipv4/fib_frontend.c +1 -1
@@ -1582,7 +1582,7 @@ static int __net_init fib_net_init(struct net *net)int error;#ifdef CONFIG_IP_ROUTE_CLASSID - net->ipv4.fib_num_tclassid_users =0 ; +atomic_set (&net->ipv4.fib_num_tclassid_users,0 );#endif error =ip_fib_net_init (net);if (error <0 )
net/ipv4/fib_rules.c +2 -2
@@ -264,7 +264,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,if (tb[FRA_FLOW ]) { rule4->tclassid =nla_get_u32 (tb[FRA_FLOW ]);if (rule4->tclassid) - net->ipv4.fib_num_tclassid_users++; +atomic_inc (&net->ipv4.fib_num_tclassid_users); }#endif
@@ -296,7 +296,7 @@ static int fib4_rule_delete(struct fib_rule *rule)#ifdef CONFIG_IP_ROUTE_CLASSID if (((struct fib4_rule *)rule)->tclassid) - net->ipv4.fib_num_tclassid_users--; +atomic_dec (&net->ipv4.fib_num_tclassid_users);#endif net->ipv4.fib_has_custom_rules = true;
net/ipv4/fib_semantics.c +2 -2
@@ -220,7 +220,7 @@ void fib_nh_release(struct net *net, struct fib_nh *fib_nh) {#ifdef CONFIG_IP_ROUTE_CLASSID if (fib_nh->nh_tclassid) - net->ipv4.fib_num_tclassid_users--; +atomic_dec (&net->ipv4.fib_num_tclassid_users);#endif fib_nh_common_release (&fib_nh->nh_common); }
@@ -632,7 +632,7 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,#ifdef CONFIG_IP_ROUTE_CLASSID nh->nh_tclassid = cfg->fc_flow;if (nh->nh_tclassid) - net->ipv4.fib_num_tclassid_users++; +atomic_inc (&net->ipv4.fib_num_tclassid_users);#endif #ifdef CONFIG_IP_ROUTE_MULTIPATH nh->fib_nh_weight = nh_weight;
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Quoted 11 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
Before commit
faa041a40b9f("ipv4: Create cleanup helper forfib_nh") changes tonet->ipv4.fib_num_tclassid_userswere protected by RTNL.After the change, this is no longer the case, as
free_fib_info_rcu()runs after rcu grace period, without rtnl being held.Fixes faa041a40b9f ("ipv4: Create cleanup helper for fib_nh")Signed-off-by Eric Dumazet <[email protected]>Cc David Ahern <[email protected]>
Quoted 8 lines
--- include/net/ip_fib.h | 2 +- include/net/netns/ipv4.h | 2 +- net/ipv4/fib_frontend.c | 2 +- net/ipv4/fib_rules.c | 4 ++-- net/ipv4/fib_semantics.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-)
Thanks, Eric. Was this found by syzbot or code inspection?
Quoted 22 lines · David Ahern
Quoted 11 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
Before commit
faa041a40b9f("ipv4: Create cleanup helper forfib_nh") changes tonet->ipv4.fib_num_tclassid_userswere protected by RTNL.After the change, this is no longer the case, as
free_fib_info_rcu()runs after rcu grace period, without rtnl being held.Fixes faa041a40b9f ("ipv4: Create cleanup helper for fib_nh")Signed-off-by Eric Dumazet <[email protected]>Cc David Ahern <[email protected]>Quoted 8 lines
--- include/net/ip_fib.h | 2 +- include/net/netns/ipv4.h | 2 +- net/ipv4/fib_frontend.c | 2 +- net/ipv4/fib_rules.c | 4 ++-- net/ipv4/fib_semantics.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-)
Quoted 2 lines
Thanks, Eric. Was this found by syzbot or code inspection?
Code inspection, while plumbing my dev_hold_track() and dev_put_track() helpers.
Quoted 3 lines
Reviewed-by David Ahern <[email protected]>
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:
Quoted 9 lines · On Wed, 1 Dec 2021 18:26:35 -0800 you wrote:
From: Eric Dumazet <[email protected]>
Before commit
faa041a40b9f("ipv4: Create cleanup helper forfib_nh") changes tonet->ipv4.fib_num_tclassid_userswere protected by RTNL.After the change, this is no longer the case, as
free_fib_info_rcu()runs after rcu grace period, without rtnl being held.[...]
Here is the summary with links:
- [net] ipv4: convert fib_num_tclassid_users to atomic_t
https://git.kernel.org/netdev/net/c/213f5f8f31f1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html