netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex
@ 2025-02-06  8:30 Eric Dumazet
  2025-02-06  9:40 ` Kuniyuki Iwashima
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2025-02-06  8:30 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, David Ahern, Simon Horman, eric.dumazet, Eric Dumazet

rule->iifindex and rule->oifindex can be read without holding RTNL.

Add READ_ONCE()/WRITE_ONCE() annotations where needed.

Fixes: 32affa5578f0 ("fib: rules: no longer hold RTNL in fib_nl_dumprule()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/fib_rules.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index e684ba3ebb38563abefc034c16ba381635285953..94a7872ab231855dd9965efb099c09fe3728e1a2 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -37,8 +37,8 @@ static const struct fib_kuid_range fib_kuid_range_unset = {
 
 bool fib_rule_matchall(const struct fib_rule *rule)
 {
-	if (rule->iifindex || rule->oifindex || rule->mark || rule->tun_id ||
-	    rule->flags)
+	if (READ_ONCE(rule->iifindex) || READ_ONCE(rule->oifindex) ||
+	    rule->mark || rule->tun_id || rule->flags)
 		return false;
 	if (rule->suppress_ifgroup != -1 || rule->suppress_prefixlen != -1)
 		return false;
@@ -261,12 +261,14 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
 			  struct flowi *fl, int flags,
 			  struct fib_lookup_arg *arg)
 {
-	int ret = 0;
+	int iifindex, oifindex, ret = 0;
 
-	if (rule->iifindex && (rule->iifindex != fl->flowi_iif))
+	iifindex = READ_ONCE(rule->iifindex);
+	if (iifindex && (iifindex != fl->flowi_iif))
 		goto out;
 
-	if (rule->oifindex && (rule->oifindex != fl->flowi_oif))
+	oifindex = READ_ONCE(rule->oifindex);
+	if (oifindex && (oifindex != fl->flowi_oif))
 		goto out;
 
 	if ((rule->mark ^ fl->flowi_mark) & rule->mark_mask)
@@ -1041,14 +1043,14 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
 	if (rule->iifname[0]) {
 		if (nla_put_string(skb, FRA_IIFNAME, rule->iifname))
 			goto nla_put_failure;
-		if (rule->iifindex == -1)
+		if (READ_ONCE(rule->iifindex) == -1)
 			frh->flags |= FIB_RULE_IIF_DETACHED;
 	}
 
 	if (rule->oifname[0]) {
 		if (nla_put_string(skb, FRA_OIFNAME, rule->oifname))
 			goto nla_put_failure;
-		if (rule->oifindex == -1)
+		if (READ_ONCE(rule->oifindex) == -1)
 			frh->flags |= FIB_RULE_OIF_DETACHED;
 	}
 
@@ -1220,10 +1222,10 @@ static void attach_rules(struct list_head *rules, struct net_device *dev)
 	list_for_each_entry(rule, rules, list) {
 		if (rule->iifindex == -1 &&
 		    strcmp(dev->name, rule->iifname) == 0)
-			rule->iifindex = dev->ifindex;
+			WRITE_ONCE(rule->iifindex, dev->ifindex);
 		if (rule->oifindex == -1 &&
 		    strcmp(dev->name, rule->oifname) == 0)
-			rule->oifindex = dev->ifindex;
+			WRITE_ONCE(rule->oifindex, dev->ifindex);
 	}
 }
 
@@ -1233,9 +1235,9 @@ static void detach_rules(struct list_head *rules, struct net_device *dev)
 
 	list_for_each_entry(rule, rules, list) {
 		if (rule->iifindex == dev->ifindex)
-			rule->iifindex = -1;
+			WRITE_ONCE(rule->iifindex, -1);
 		if (rule->oifindex == dev->ifindex)
-			rule->oifindex = -1;
+			WRITE_ONCE(rule->oifindex, -1);
 	}
 }
 
-- 
2.48.1.362.g079036d154-goog


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

* Re: [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex
  2025-02-06  8:30 [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex Eric Dumazet
@ 2025-02-06  9:40 ` Kuniyuki Iwashima
  2025-02-06 12:00 ` Ido Schimmel
  2025-02-07 22:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2025-02-06  9:40 UTC (permalink / raw)
  To: edumazet
  Cc: davem, dsahern, eric.dumazet, horms, kuba, netdev, pabeni,
	Kuniyuki Iwashima

From: Eric Dumazet <edumazet@google.com>
Date: Thu,  6 Feb 2025 08:30:51 +0000
> rule->iifindex and rule->oifindex can be read without holding RTNL.
> 
> Add READ_ONCE()/WRITE_ONCE() annotations where needed.
> 
> Fixes: 32affa5578f0 ("fib: rules: no longer hold RTNL in fib_nl_dumprule()")
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

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

* Re: [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex
  2025-02-06  8:30 [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex Eric Dumazet
  2025-02-06  9:40 ` Kuniyuki Iwashima
@ 2025-02-06 12:00 ` Ido Schimmel
  2025-02-07 22:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Ido Schimmel @ 2025-02-06 12:00 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	David Ahern, Simon Horman, eric.dumazet

On Thu, Feb 06, 2025 at 08:30:51AM +0000, Eric Dumazet wrote:
> rule->iifindex and rule->oifindex can be read without holding RTNL.
> 
> Add READ_ONCE()/WRITE_ONCE() annotations where needed.
> 
> Fixes: 32affa5578f0 ("fib: rules: no longer hold RTNL in fib_nl_dumprule()")
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex
  2025-02-06  8:30 [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex Eric Dumazet
  2025-02-06  9:40 ` Kuniyuki Iwashima
  2025-02-06 12:00 ` Ido Schimmel
@ 2025-02-07 22:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-02-07 22:00 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, netdev, dsahern, horms, eric.dumazet

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  6 Feb 2025 08:30:51 +0000 you wrote:
> rule->iifindex and rule->oifindex can be read without holding RTNL.
> 
> Add READ_ONCE()/WRITE_ONCE() annotations where needed.
> 
> Fixes: 32affa5578f0 ("fib: rules: no longer hold RTNL in fib_nl_dumprule()")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> 
> [...]

Here is the summary with links:
  - [net] net: fib_rules: annotate data-races around rule->[io]ifindex
    https://git.kernel.org/netdev/net/c/cb827db50a88

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:[~2025-02-07 22:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-06  8:30 [PATCH net] net: fib_rules: annotate data-races around rule->[io]ifindex Eric Dumazet
2025-02-06  9:40 ` Kuniyuki Iwashima
2025-02-06 12:00 ` Ido Schimmel
2025-02-07 22:00 ` 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).