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>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2 net 08/12] inetpeer: Fix data-races around sysctl.
Date: Wed, 6 Jul 2022 16:39:59 -0700	[thread overview]
Message-ID: <20220706234003.66760-9-kuniyu@amazon.com> (raw)
In-Reply-To: <20220706234003.66760-1-kuniyu@amazon.com>

While reading inetpeer sysctl variables, they can be changed
concurrently.  So, we need to add READ_ONCE() to avoid data-races.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/inetpeer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index da21dfce24d7..e9fed83e9b3c 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -141,16 +141,20 @@ static void inet_peer_gc(struct inet_peer_base *base,
 			 struct inet_peer *gc_stack[],
 			 unsigned int gc_cnt)
 {
+	int peer_threshold, peer_maxttl, peer_minttl;
 	struct inet_peer *p;
 	__u32 delta, ttl;
 	int i;
 
-	if (base->total >= inet_peer_threshold)
+	peer_threshold = READ_ONCE(inet_peer_threshold);
+	peer_maxttl = READ_ONCE(inet_peer_maxttl);
+	peer_minttl = READ_ONCE(inet_peer_minttl);
+
+	if (base->total >= peer_threshold)
 		ttl = 0; /* be aggressive */
 	else
-		ttl = inet_peer_maxttl
-				- (inet_peer_maxttl - inet_peer_minttl) / HZ *
-					base->total / inet_peer_threshold * HZ;
+		ttl = peer_maxttl - (peer_maxttl - peer_minttl) / HZ *
+			base->total / peer_threshold * HZ;
 	for (i = 0; i < gc_cnt; i++) {
 		p = gc_stack[i];
 
-- 
2.30.2


  parent reply	other threads:[~2022-07-06 23:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 23:39 [PATCH v2 net 00/12] sysctl: Fix data-races around ipv4_table Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 01/12] sysctl: Fix data races in proc_dointvec() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 02/12] sysctl: Fix data races in proc_douintvec() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 03/12] sysctl: Fix data races in proc_dointvec_minmax() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 04/12] sysctl: Fix data races in proc_douintvec_minmax() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 05/12] sysctl: Fix data races in proc_doulongvec_minmax() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 06/12] sysctl: Fix data races in proc_dointvec_jiffies() Kuniyuki Iwashima
2022-07-06 23:39 ` [PATCH v2 net 07/12] tcp: Fix a data-race around sysctl_tcp_max_orphans Kuniyuki Iwashima
2022-07-06 23:39 ` Kuniyuki Iwashima [this message]
2022-07-06 23:40 ` [PATCH v2 net 09/12] net: Fix data-races around sysctl_mem Kuniyuki Iwashima
2022-07-09  9:11   ` Matthieu Baerts
2022-07-06 23:40 ` [PATCH v2 net 10/12] cipso: Fix data-races around sysctl Kuniyuki Iwashima
2022-07-07 19:15   ` Paul Moore
2022-07-07 22:15     ` Kuniyuki Iwashima
2022-07-08  0:24       ` Jakub Kicinski
2022-07-08  0:44         ` Kuniyuki Iwashima
2022-07-06 23:40 ` [PATCH v2 net 11/12] icmp: " Kuniyuki Iwashima
2022-07-06 23:40 ` [PATCH v2 net 12/12] ipv4: Fix a data-race around sysctl_fib_sync_mem Kuniyuki Iwashima
2022-07-08 11:50 ` [PATCH v2 net 00/12] sysctl: Fix data-races around ipv4_table 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=20220706234003.66760-9-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yzaikin@google.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.