All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	David Ahern <dsahern@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
	Amit Cohen <amcohen@nvidia.com>
Subject: [PATCH v1 net 7/7] ipv4: Fix data-races around sysctl_fib_notify_on_flag_change.
Date: Fri, 22 Jul 2022 11:22:05 -0700	[thread overview]
Message-ID: <20220722182205.96838-8-kuniyu@amazon.com> (raw)
In-Reply-To: <20220722182205.96838-1-kuniyu@amazon.com>

While reading sysctl_fib_notify_on_flag_change, it can be changed
concurrently.  Thus, we need to add READ_ONCE() to its readers.

Fixes: 680aea08e78c ("net: ipv4: Emit notification when fib hardware flags are changed")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Amit Cohen <amcohen@nvidia.com>
---
 net/ipv4/fib_trie.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 46e8a5125853..452ff177e4da 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1042,6 +1042,7 @@ fib_find_matching_alias(struct net *net, const struct fib_rt_info *fri)
 
 void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri)
 {
+	u8 fib_notify_on_flag_change;
 	struct fib_alias *fa_match;
 	struct sk_buff *skb;
 	int err;
@@ -1063,14 +1064,16 @@ void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri)
 	WRITE_ONCE(fa_match->offload, fri->offload);
 	WRITE_ONCE(fa_match->trap, fri->trap);
 
+	fib_notify_on_flag_change = READ_ONCE(net->ipv4.sysctl_fib_notify_on_flag_change);
+
 	/* 2 means send notifications only if offload_failed was changed. */
-	if (net->ipv4.sysctl_fib_notify_on_flag_change == 2 &&
+	if (fib_notify_on_flag_change == 2 &&
 	    READ_ONCE(fa_match->offload_failed) == fri->offload_failed)
 		goto out;
 
 	WRITE_ONCE(fa_match->offload_failed, fri->offload_failed);
 
-	if (!net->ipv4.sysctl_fib_notify_on_flag_change)
+	if (!fib_notify_on_flag_change)
 		goto out;
 
 	skb = nlmsg_new(fib_nlmsg_size(fa_match->fa_info), GFP_ATOMIC);
-- 
2.30.2


  parent reply	other threads:[~2022-07-22 18:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 18:21 [PATCH v1 net 0/7] sysctl: Fix data-races around ipv4_net_table (Round 6, Final) Kuniyuki Iwashima
2022-07-22 18:21 ` [PATCH v1 net 1/7] tcp: Fix data-races around sk_pacing_rate Kuniyuki Iwashima
2022-07-22 18:22 ` [PATCH v1 net 2/7] net: Fix data-races around sysctl_[rw]mem(_offset)? Kuniyuki Iwashima
2022-07-22 18:22 ` [PATCH v1 net 3/7] tcp: Fix a data-race around sysctl_tcp_comp_sack_delay_ns Kuniyuki Iwashima
2022-07-22 18:22 ` [PATCH v1 net 4/7] tcp: Fix a data-race around sysctl_tcp_comp_sack_slack_ns Kuniyuki Iwashima
2022-07-22 18:22 ` [PATCH v1 net 5/7] tcp: Fix a data-race around sysctl_tcp_comp_sack_nr Kuniyuki Iwashima
2022-07-22 18:22 ` [PATCH v1 net 6/7] tcp: Fix data-races around sysctl_tcp_reflect_tos Kuniyuki Iwashima
2022-07-22 18:58   ` Wei Wang
2022-07-22 18:22 ` Kuniyuki Iwashima [this message]
2022-07-25 12:30 ` [PATCH v1 net 0/7] sysctl: Fix data-races around ipv4_net_table (Round 6, Final) patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722182205.96838-8-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=amcohen@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.