netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t
@ 2021-12-02  2:26 Eric Dumazet
  2021-12-02  2:42 ` David Ahern
  2021-12-02 12:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-12-02  2:26 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski
  Cc: netdev, Eric Dumazet, Eric Dumazet, David Ahern

From: Eric Dumazet <edumazet@google.com>

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.

Fixes: faa041a40b9f ("ipv4: Create cleanup helper for fib_nh")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: David Ahern <dsahern@kernel.org>
---
 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(-)

diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index ab5348e57db1a627cbce2dededb2e9b754d1f2cd..3417ba2d27ad6a1b5612a8855d2788f10d9fdf25 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -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)
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 2f65701a43c953bd3a9a9e3d491882cb7bb11859..6c5b2efc4f17d0d17be750d0c1a2e1d169ec063e 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -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;
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 9fe13e4f5d08a5cf9cd9ff15033b9f6e0dc9e492..4d61ddd8a0ecfc4cc47b4802eb5a573beb84ee44 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -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)
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 364ad3446b2f3c056ea5dafea1542e4d3306ddb6..d279cb8ac1584487885f66819634b421c01bf819 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -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;
 
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 3364cb9c67e018fea2b2e370046de5252581b996..fde7797b580694bb3924c5c6e9560cf04fd67387 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -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;
-- 
2.34.0.rc2.393.gf8c9666880-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t
  2021-12-02  2:26 [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t Eric Dumazet
@ 2021-12-02  2:42 ` David Ahern
  2021-12-02  2:58   ` Eric Dumazet
  2021-12-02 12:20 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: David Ahern @ 2021-12-02  2:42 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski
  Cc: netdev, Eric Dumazet, David Ahern

On 12/1/21 7:26 PM, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> 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.
> 
> Fixes: faa041a40b9f ("ipv4: Create cleanup helper for fib_nh")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: David Ahern <dsahern@kernel.org>
> ---
>  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?

Reviewed-by: David Ahern <dsahern@kernel.org>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t
  2021-12-02  2:42 ` David Ahern
@ 2021-12-02  2:58   ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-12-02  2:58 UTC (permalink / raw)
  To: David Ahern
  Cc: Eric Dumazet, David S . Miller, Jakub Kicinski, netdev,
	David Ahern

On Wed, Dec 1, 2021 at 6:42 PM David Ahern <dsahern@gmail.com> wrote:
>
> On 12/1/21 7:26 PM, Eric Dumazet wrote:
> > From: Eric Dumazet <edumazet@google.com>
> >
> > 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.
> >
> > Fixes: faa041a40b9f ("ipv4: Create cleanup helper for fib_nh")
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: David Ahern <dsahern@kernel.org>
> > ---
> >  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?
>

Code inspection, while plumbing my dev_hold_track() and dev_put_track() helpers.


> Reviewed-by: David Ahern <dsahern@kernel.org>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t
  2021-12-02  2:26 [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t Eric Dumazet
  2021-12-02  2:42 ` David Ahern
@ 2021-12-02 12:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-02 12:20 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, netdev, edumazet, dsahern

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Wed,  1 Dec 2021 18:26:35 -0800 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> 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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-02 12:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-02  2:26 [PATCH net] ipv4: convert fib_num_tclassid_users to atomic_t Eric Dumazet
2021-12-02  2:42 ` David Ahern
2021-12-02  2:58   ` Eric Dumazet
2021-12-02 12:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).