All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4).
@ 2022-07-18 17:26 Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh Kuniyuki Iwashima
                   ` (15 more replies)
  0 siblings, 16 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

This series fixes data-races around 17 knobs after fib_multipath_use_neigh
in ipv4_net_table.

tcp_fack was skipped because it's obsolete and there's no readers.

So, round 5 will start with tcp_dsack, 2 rounds left for 27 knobs.


Kuniyuki Iwashima (15):
  ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh.
  ipv4: Fix data-races around sysctl_fib_multipath_hash_policy.
  ipv4: Fix data-races around sysctl_fib_multipath_hash_fields.
  ip: Fix data-races around sysctl_ip_prot_sock.
  udp: Fix a data-race around sysctl_udp_l3mdev_accept.
  tcp: Fix data-races around sysctl knobs related to SYN option.
  tcp: Fix a data-race around sysctl_tcp_early_retrans.
  tcp: Fix data-races around sysctl_tcp_recovery.
  tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts.
  tcp: Fix data-races around sysctl_tcp_slow_start_after_idle.
  tcp: Fix a data-race around sysctl_tcp_retrans_collapse.
  tcp: Fix a data-race around sysctl_tcp_stdurg.
  tcp: Fix a data-race around sysctl_tcp_rfc1337.
  tcp: Fix a data-race around sysctl_tcp_abort_on_overflow.
  tcp: Fix data-races around sysctl_tcp_max_reordering.

 .../chelsio/inline_crypto/chtls/chtls_cm.c       |  6 +++---
 .../ethernet/mellanox/mlxsw/spectrum_router.c    |  4 ++--
 include/net/ip.h                                 |  2 +-
 include/net/tcp.h                                |  4 ++--
 include/net/udp.h                                |  2 +-
 net/core/secure_seq.c                            |  4 ++--
 net/ipv4/fib_semantics.c                         |  2 +-
 net/ipv4/route.c                                 |  8 ++++----
 net/ipv4/syncookies.c                            |  6 +++---
 net/ipv4/sysctl_net_ipv4.c                       |  6 +++---
 net/ipv4/tcp_input.c                             | 15 ++++++++-------
 net/ipv4/tcp_minisocks.c                         |  4 ++--
 net/ipv4/tcp_output.c                            | 16 ++++++++--------
 net/ipv4/tcp_recovery.c                          |  6 ++++--
 net/ipv4/tcp_timer.c                             |  2 +-
 15 files changed, 45 insertions(+), 42 deletions(-)

-- 
2.30.2


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

* [PATCH v1 net 01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 02/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy Kuniyuki Iwashima
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: a6db4494d218 ("net: ipv4: Consider failed nexthops in multipath routes")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/fib_semantics.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index d9fdcbae16ee..db7b2503f068 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -2216,7 +2216,7 @@ void fib_select_multipath(struct fib_result *res, int hash)
 	}
 
 	change_nexthops(fi) {
-		if (net->ipv4.sysctl_fib_multipath_use_neigh) {
+		if (READ_ONCE(net->ipv4.sysctl_fib_multipath_use_neigh)) {
 			if (!fib_good_nh(nexthop_nh))
 				continue;
 			if (!first) {
-- 
2.30.2


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

* [PATCH v1 net 02/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields Kuniyuki Iwashima
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Nikolay Aleksandrov

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

Fixes: bf4e0a3db97e ("net: ipv4: add support for ECMP hash policy choice")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 net/ipv4/route.c                                      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 868d28f3b4e1..de63a5f3b767 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -10324,7 +10324,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
 	unsigned long *fields = config->fields;
 	u32 hash_fields;
 
-	switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
+	switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) {
 	case 0:
 		mlxsw_sp_mp4_hash_outer_addr(config);
 		break;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 91c4f60de75a..521194dd1c99 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2048,7 +2048,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
 	struct flow_keys hash_keys;
 	u32 mhash = 0;
 
-	switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
+	switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) {
 	case 0:
 		memset(&hash_keys, 0, sizeof(hash_keys));
 		hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
-- 
2.30.2


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

* [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 02/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-19  9:38   ` Ido Schimmel
  2022-07-18 17:26 ` [PATCH v1 net 04/15] ip: Fix data-races around sysctl_ip_prot_sock Kuniyuki Iwashima
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Ido Schimmel

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

Fixes: ce5c9c20d364 ("ipv4: Add a sysctl to control multipath hash fields")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Ido Schimmel <idosch@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 net/ipv4/route.c                                      | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index de63a5f3b767..85aa1c468cd4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -10342,7 +10342,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
 		mlxsw_sp_mp_hash_inner_l3(config);
 		break;
 	case 3:
-		hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
+		hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
 		/* Outer */
 		MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP);
 		MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 521194dd1c99..4702c61207a8 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1929,7 +1929,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net,
 					   const struct sk_buff *skb,
 					   bool *p_has_inner)
 {
-	u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
+	u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
 	struct flow_keys keys, hash_keys;
 
 	if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))
@@ -1958,7 +1958,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net,
 					   const struct sk_buff *skb,
 					   bool has_inner)
 {
-	u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
+	u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
 	struct flow_keys keys, hash_keys;
 
 	/* We assume the packet carries an encapsulation, but if none was
@@ -2018,7 +2018,7 @@ static u32 fib_multipath_custom_hash_skb(const struct net *net,
 static u32 fib_multipath_custom_hash_fl4(const struct net *net,
 					 const struct flowi4 *fl4)
 {
-	u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
+	u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
 	struct flow_keys hash_keys;
 
 	if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))
-- 
2.30.2


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

* [PATCH v1 net 04/15] ip: Fix data-races around sysctl_ip_prot_sock.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (2 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 05/15] udp: Fix a data-race around sysctl_udp_l3mdev_accept Kuniyuki Iwashima
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Krister Johansen

sysctl_ip_prot_sock is accessed concurrently, and there is always a chance
of data-race.  So, all readers and writers need some basic protection to
avoid load/store-tearing.

Fixes: 4548b683b781 ("Introduce a sysctl that modifies the value of PROT_SOCK.")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Krister Johansen <kjlx@templeofstupid.com>
---
 include/net/ip.h           | 2 +-
 net/ipv4/sysctl_net_ipv4.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/ip.h b/include/net/ip.h
index 4a15b6bcb4b8..1c979fd1904c 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -357,7 +357,7 @@ static inline bool sysctl_dev_name_is_allowed(const char *name)
 
 static inline bool inet_port_requires_bind_service(struct net *net, unsigned short port)
 {
-	return port < net->ipv4.sysctl_ip_prot_sock;
+	return port < READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
 }
 
 #else
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 130e9c130311..5490c285668b 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -84,7 +84,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
 		 * port limit.
 		 */
 		if ((range[1] < range[0]) ||
-		    (range[0] < net->ipv4.sysctl_ip_prot_sock))
+		    (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
 			ret = -EINVAL;
 		else
 			set_local_port_range(net, range);
@@ -110,7 +110,7 @@ static int ipv4_privileged_ports(struct ctl_table *table, int write,
 		.extra2 = &ip_privileged_port_max,
 	};
 
-	pports = net->ipv4.sysctl_ip_prot_sock;
+	pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
 
 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 
@@ -122,7 +122,7 @@ static int ipv4_privileged_ports(struct ctl_table *table, int write,
 		if (range[0] < pports)
 			ret = -EINVAL;
 		else
-			net->ipv4.sysctl_ip_prot_sock = pports;
+			WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
 	}
 
 	return ret;
-- 
2.30.2


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

* [PATCH v1 net 05/15] udp: Fix a data-race around sysctl_udp_l3mdev_accept.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (3 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 04/15] ip: Fix data-races around sysctl_ip_prot_sock Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 06/15] tcp: Fix data-races around sysctl knobs related to SYN option Kuniyuki Iwashima
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Robert Shearman

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

Fixes: 63a6fff353d0 ("net: Avoid receiving packets with an l3mdev on unbound UDP sockets")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Robert Shearman <rshearma@brocade.com>
---
 include/net/udp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/udp.h b/include/net/udp.h
index bb4c227299cc..8dd4aa1485a6 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -238,7 +238,7 @@ static inline bool udp_sk_bound_dev_eq(struct net *net, int bound_dev_if,
 				       int dif, int sdif)
 {
 #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
-	return inet_bound_dev_eq(!!net->ipv4.sysctl_udp_l3mdev_accept,
+	return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_udp_l3mdev_accept),
 				 bound_dev_if, dif, sdif);
 #else
 	return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
-- 
2.30.2


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

* [PATCH v1 net 06/15] tcp: Fix data-races around sysctl knobs related to SYN option.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (4 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 05/15] udp: Fix a data-race around sysctl_udp_l3mdev_accept Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 07/15] tcp: Fix a data-race around sysctl_tcp_early_retrans Kuniyuki Iwashima
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

While reading these knobs, they can be changed concurrently.
Thus, we need to add READ_ONCE() to their readers.

  - tcp_sack
  - tcp_window_scaling
  - tcp_timestamps

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 .../ethernet/chelsio/inline_crypto/chtls/chtls_cm.c    |  6 +++---
 net/core/secure_seq.c                                  |  4 ++--
 net/ipv4/syncookies.c                                  |  6 +++---
 net/ipv4/tcp_input.c                                   |  6 +++---
 net/ipv4/tcp_output.c                                  | 10 +++++-----
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
index 7c760aa65540..ddfe9208529a 100644
--- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
+++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
@@ -1236,8 +1236,8 @@ static struct sock *chtls_recv_sock(struct sock *lsk,
 	csk->sndbuf = newsk->sk_sndbuf;
 	csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx;
 	RCV_WSCALE(tp) = select_rcv_wscale(tcp_full_space(newsk),
-					   sock_net(newsk)->
-						ipv4.sysctl_tcp_window_scaling,
+					   READ_ONCE(sock_net(newsk)->
+						     ipv4.sysctl_tcp_window_scaling),
 					   tp->window_clamp);
 	neigh_release(n);
 	inet_inherit_port(&tcp_hashinfo, lsk, newsk);
@@ -1384,7 +1384,7 @@ static void chtls_pass_accept_request(struct sock *sk,
 #endif
 	}
 	if (req->tcpopt.wsf <= 14 &&
-	    sock_net(sk)->ipv4.sysctl_tcp_window_scaling) {
+	    READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling)) {
 		inet_rsk(oreq)->wscale_ok = 1;
 		inet_rsk(oreq)->snd_wscale = req->tcpopt.wsf;
 	}
diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
index 5f85e01d4093..b0ff6153be62 100644
--- a/net/core/secure_seq.c
+++ b/net/core/secure_seq.c
@@ -64,7 +64,7 @@ u32 secure_tcpv6_ts_off(const struct net *net,
 		.daddr = *(struct in6_addr *)daddr,
 	};
 
-	if (net->ipv4.sysctl_tcp_timestamps != 1)
+	if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) != 1)
 		return 0;
 
 	ts_secret_init();
@@ -120,7 +120,7 @@ EXPORT_SYMBOL(secure_ipv6_port_ephemeral);
 #ifdef CONFIG_INET
 u32 secure_tcp_ts_off(const struct net *net, __be32 saddr, __be32 daddr)
 {
-	if (net->ipv4.sysctl_tcp_timestamps != 1)
+	if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) != 1)
 		return 0;
 
 	ts_secret_init();
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 9b234b42021e..942d2dfa1115 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -247,12 +247,12 @@ bool cookie_timestamp_decode(const struct net *net,
 		return true;
 	}
 
-	if (!net->ipv4.sysctl_tcp_timestamps)
+	if (!READ_ONCE(net->ipv4.sysctl_tcp_timestamps))
 		return false;
 
 	tcp_opt->sack_ok = (options & TS_OPT_SACK) ? TCP_SACK_SEEN : 0;
 
-	if (tcp_opt->sack_ok && !net->ipv4.sysctl_tcp_sack)
+	if (tcp_opt->sack_ok && !READ_ONCE(net->ipv4.sysctl_tcp_sack))
 		return false;
 
 	if ((options & TS_OPT_WSCALE_MASK) == TS_OPT_WSCALE_MASK)
@@ -261,7 +261,7 @@ bool cookie_timestamp_decode(const struct net *net,
 	tcp_opt->wscale_ok = 1;
 	tcp_opt->snd_wscale = options & TS_OPT_WSCALE_MASK;
 
-	return net->ipv4.sysctl_tcp_window_scaling != 0;
+	return READ_ONCE(net->ipv4.sysctl_tcp_window_scaling) != 0;
 }
 EXPORT_SYMBOL(cookie_timestamp_decode);
 
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d451248bebec..92626e15115c 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4060,7 +4060,7 @@ void tcp_parse_options(const struct net *net,
 				break;
 			case TCPOPT_WINDOW:
 				if (opsize == TCPOLEN_WINDOW && th->syn &&
-				    !estab && net->ipv4.sysctl_tcp_window_scaling) {
+				    !estab && READ_ONCE(net->ipv4.sysctl_tcp_window_scaling)) {
 					__u8 snd_wscale = *(__u8 *)ptr;
 					opt_rx->wscale_ok = 1;
 					if (snd_wscale > TCP_MAX_WSCALE) {
@@ -4076,7 +4076,7 @@ void tcp_parse_options(const struct net *net,
 			case TCPOPT_TIMESTAMP:
 				if ((opsize == TCPOLEN_TIMESTAMP) &&
 				    ((estab && opt_rx->tstamp_ok) ||
-				     (!estab && net->ipv4.sysctl_tcp_timestamps))) {
+				     (!estab && READ_ONCE(net->ipv4.sysctl_tcp_timestamps)))) {
 					opt_rx->saw_tstamp = 1;
 					opt_rx->rcv_tsval = get_unaligned_be32(ptr);
 					opt_rx->rcv_tsecr = get_unaligned_be32(ptr + 4);
@@ -4084,7 +4084,7 @@ void tcp_parse_options(const struct net *net,
 				break;
 			case TCPOPT_SACK_PERM:
 				if (opsize == TCPOLEN_SACK_PERM && th->syn &&
-				    !estab && net->ipv4.sysctl_tcp_sack) {
+				    !estab && READ_ONCE(net->ipv4.sysctl_tcp_sack)) {
 					opt_rx->sack_ok = TCP_SACK_SEEN;
 					tcp_sack_reset(opt_rx);
 				}
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 3b3552d292a5..38a71e711edc 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -791,18 +791,18 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 	opts->mss = tcp_advertise_mss(sk);
 	remaining -= TCPOLEN_MSS_ALIGNED;
 
-	if (likely(sock_net(sk)->ipv4.sysctl_tcp_timestamps && !*md5)) {
+	if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps) && !*md5)) {
 		opts->options |= OPTION_TS;
 		opts->tsval = tcp_skb_timestamp(skb) + tp->tsoffset;
 		opts->tsecr = tp->rx_opt.ts_recent;
 		remaining -= TCPOLEN_TSTAMP_ALIGNED;
 	}
-	if (likely(sock_net(sk)->ipv4.sysctl_tcp_window_scaling)) {
+	if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling))) {
 		opts->ws = tp->rx_opt.rcv_wscale;
 		opts->options |= OPTION_WSCALE;
 		remaining -= TCPOLEN_WSCALE_ALIGNED;
 	}
-	if (likely(sock_net(sk)->ipv4.sysctl_tcp_sack)) {
+	if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_sack))) {
 		opts->options |= OPTION_SACK_ADVERTISE;
 		if (unlikely(!(OPTION_TS & opts->options)))
 			remaining -= TCPOLEN_SACKPERM_ALIGNED;
@@ -3647,7 +3647,7 @@ static void tcp_connect_init(struct sock *sk)
 	 * See tcp_input.c:tcp_rcv_state_process case TCP_SYN_SENT.
 	 */
 	tp->tcp_header_len = sizeof(struct tcphdr);
-	if (sock_net(sk)->ipv4.sysctl_tcp_timestamps)
+	if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps))
 		tp->tcp_header_len += TCPOLEN_TSTAMP_ALIGNED;
 
 #ifdef CONFIG_TCP_MD5SIG
@@ -3683,7 +3683,7 @@ static void tcp_connect_init(struct sock *sk)
 				  tp->advmss - (tp->rx_opt.ts_recent_stamp ? tp->tcp_header_len - sizeof(struct tcphdr) : 0),
 				  &tp->rcv_wnd,
 				  &tp->window_clamp,
-				  sock_net(sk)->ipv4.sysctl_tcp_window_scaling,
+				  READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling),
 				  &rcv_wscale,
 				  rcv_wnd);
 
-- 
2.30.2


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

* [PATCH v1 net 07/15] tcp: Fix a data-race around sysctl_tcp_early_retrans.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (5 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 06/15] tcp: Fix data-races around sysctl knobs related to SYN option Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 08/15] tcp: Fix data-races around sysctl_tcp_recovery Kuniyuki Iwashima
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Yuchung Cheng

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

Fixes: eed530b6c676 ("tcp: early retransmit")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Yuchung Cheng <ycheng@google.com>
---
 net/ipv4/tcp_output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 38a71e711edc..898fcdcb7989 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2741,7 +2741,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto)
 	if (rcu_access_pointer(tp->fastopen_rsk))
 		return false;
 
-	early_retrans = sock_net(sk)->ipv4.sysctl_tcp_early_retrans;
+	early_retrans = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_early_retrans);
 	/* Schedule a loss probe in 2*RTT for SACK capable connections
 	 * not in loss recovery, that are either limited by cwnd or application.
 	 */
-- 
2.30.2


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

* [PATCH v1 net 08/15] tcp: Fix data-races around sysctl_tcp_recovery.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (6 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 07/15] tcp: Fix a data-race around sysctl_tcp_early_retrans Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 09/15] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts Kuniyuki Iwashima
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Yuchung Cheng

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

Fixes: 4f41b1c58a32 ("tcp: use RACK to detect losses")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Yuchung Cheng <ycheng@google.com>
---
 net/ipv4/tcp_input.c    | 3 ++-
 net/ipv4/tcp_recovery.c | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 92626e15115c..36eabd109e7c 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -2095,7 +2095,8 @@ static inline void tcp_init_undo(struct tcp_sock *tp)
 
 static bool tcp_is_rack(const struct sock *sk)
 {
-	return sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_LOSS_DETECTION;
+	return READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) &
+		TCP_RACK_LOSS_DETECTION;
 }
 
 /* If we detect SACK reneging, forget all SACK information
diff --git a/net/ipv4/tcp_recovery.c b/net/ipv4/tcp_recovery.c
index 48f30e7209f2..50abaa941387 100644
--- a/net/ipv4/tcp_recovery.c
+++ b/net/ipv4/tcp_recovery.c
@@ -14,7 +14,8 @@ static u32 tcp_rack_reo_wnd(const struct sock *sk)
 			return 0;
 
 		if (tp->sacked_out >= tp->reordering &&
-		    !(sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_NO_DUPTHRESH))
+		    !(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) &
+		      TCP_RACK_NO_DUPTHRESH))
 			return 0;
 	}
 
@@ -187,7 +188,8 @@ void tcp_rack_update_reo_wnd(struct sock *sk, struct rate_sample *rs)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 
-	if (sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_STATIC_REO_WND ||
+	if ((READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) &
+	     TCP_RACK_STATIC_REO_WND) ||
 	    !rs->prior_delivered)
 		return;
 
-- 
2.30.2


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

* [PATCH v1 net 09/15] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (7 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 08/15] tcp: Fix data-races around sysctl_tcp_recovery Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 10/15] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle Kuniyuki Iwashima
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Andreas Petlund

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

Fixes: 36e31b0af587 ("net: TCP thin linear timeouts")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
CC: Andreas Petlund <apetlund@simula.no>
---
 net/ipv4/tcp_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index ec5277becc6a..50bba370486e 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -578,7 +578,7 @@ void tcp_retransmit_timer(struct sock *sk)
 	 * linear-timeout retransmissions into a black hole
 	 */
 	if (sk->sk_state == TCP_ESTABLISHED &&
-	    (tp->thin_lto || net->ipv4.sysctl_tcp_thin_linear_timeouts) &&
+	    (tp->thin_lto || READ_ONCE(net->ipv4.sysctl_tcp_thin_linear_timeouts)) &&
 	    tcp_stream_is_thin(tp) &&
 	    icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) {
 		icsk->icsk_backoff = 0;
-- 
2.30.2


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

* [PATCH v1 net 10/15] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (8 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 09/15] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 11/15] tcp: Fix a data-race around sysctl_tcp_retrans_collapse Kuniyuki Iwashima
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: 35089bb203f4 ("[TCP]: Add tcp_slow_start_after_idle sysctl.")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/net/tcp.h     | 4 ++--
 net/ipv4/tcp_output.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 6ee1fb4fb292..071735e10872 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1403,8 +1403,8 @@ static inline void tcp_slow_start_after_idle_check(struct sock *sk)
 	struct tcp_sock *tp = tcp_sk(sk);
 	s32 delta;
 
-	if (!sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle || tp->packets_out ||
-	    ca_ops->cong_control)
+	if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) ||
+	    tp->packets_out || ca_ops->cong_control)
 		return;
 	delta = tcp_jiffies32 - tp->lsndtime;
 	if (delta > inet_csk(sk)->icsk_rto)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 898fcdcb7989..51120407c570 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1898,7 +1898,7 @@ static void tcp_cwnd_validate(struct sock *sk, bool is_cwnd_limited)
 		if (tp->packets_out > tp->snd_cwnd_used)
 			tp->snd_cwnd_used = tp->packets_out;
 
-		if (sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle &&
+		if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) &&
 		    (s32)(tcp_jiffies32 - tp->snd_cwnd_stamp) >= inet_csk(sk)->icsk_rto &&
 		    !ca_ops->cong_control)
 			tcp_cwnd_application_limited(sk);
-- 
2.30.2


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

* [PATCH v1 net 11/15] tcp: Fix a data-race around sysctl_tcp_retrans_collapse.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (9 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 10/15] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 12/15] tcp: Fix a data-race around sysctl_tcp_stdurg Kuniyuki Iwashima
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/tcp_output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 51120407c570..c38e07b50639 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3105,7 +3105,7 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
 	struct sk_buff *skb = to, *tmp;
 	bool first = true;
 
-	if (!sock_net(sk)->ipv4.sysctl_tcp_retrans_collapse)
+	if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retrans_collapse))
 		return;
 	if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)
 		return;
-- 
2.30.2


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

* [PATCH v1 net 12/15] tcp: Fix a data-race around sysctl_tcp_stdurg.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (10 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 11/15] tcp: Fix a data-race around sysctl_tcp_retrans_collapse Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_rfc1337 Kuniyuki Iwashima
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 36eabd109e7c..31a9d2b8ecdc 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5572,7 +5572,7 @@ static void tcp_check_urg(struct sock *sk, const struct tcphdr *th)
 	struct tcp_sock *tp = tcp_sk(sk);
 	u32 ptr = ntohs(th->urg_ptr);
 
-	if (ptr && !sock_net(sk)->ipv4.sysctl_tcp_stdurg)
+	if (ptr && !READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_stdurg))
 		ptr--;
 	ptr += ntohl(th->seq);
 
-- 
2.30.2


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

* [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_rfc1337.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (11 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 12/15] tcp: Fix a data-race around sysctl_tcp_stdurg Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 14/15] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow Kuniyuki Iwashima
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/tcp_minisocks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 6854bb1fb32b..700ea548d125 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -173,7 +173,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 			 * Oh well... nobody has a sufficient solution to this
 			 * protocol bug yet.
 			 */
-			if (twsk_net(tw)->ipv4.sysctl_tcp_rfc1337 == 0) {
+			if (!READ_ONCE(twsk_net(tw)->ipv4.sysctl_tcp_rfc1337)) {
 kill:
 				inet_twsk_deschedule_put(tw);
 				return TCP_TW_SUCCESS;
-- 
2.30.2


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

* [PATCH v1 net 14/15] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (12 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_rfc1337 Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-18 17:26 ` [PATCH v1 net 15/15] tcp: Fix data-races around sysctl_tcp_max_reordering Kuniyuki Iwashima
  2022-07-20  9:30 ` [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) patchwork-bot+netdevbpf
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/tcp_minisocks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 700ea548d125..cb95d88497ae 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -781,7 +781,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 	if (sk != req->rsk_listener)
 		__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQFAILURE);
 
-	if (!sock_net(sk)->ipv4.sysctl_tcp_abort_on_overflow) {
+	if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_abort_on_overflow)) {
 		inet_rsk(req)->acked = 1;
 		return NULL;
 	}
-- 
2.30.2


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

* [PATCH v1 net 15/15] tcp: Fix data-races around sysctl_tcp_max_reordering.
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (13 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 14/15] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow Kuniyuki Iwashima
@ 2022-07-18 17:26 ` Kuniyuki Iwashima
  2022-07-20  9:30 ` [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) patchwork-bot+netdevbpf
  15 siblings, 0 replies; 18+ messages in thread
From: Kuniyuki Iwashima @ 2022-07-18 17:26 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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

Fixes: dca145ffaa8d ("tcp: allow for bigger reordering level")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/tcp_input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 31a9d2b8ecdc..07dbcbae7782 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1051,7 +1051,7 @@ static void tcp_check_sack_reordering(struct sock *sk, const u32 low_seq,
 			 tp->undo_marker ? tp->undo_retrans : 0);
 #endif
 		tp->reordering = min_t(u32, (metric + mss - 1) / mss,
-				       sock_net(sk)->ipv4.sysctl_tcp_max_reordering);
+				       READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering));
 	}
 
 	/* This exciting event is worth to be remembered. 8) */
@@ -2030,7 +2030,7 @@ static void tcp_check_reno_reordering(struct sock *sk, const int addend)
 		return;
 
 	tp->reordering = min_t(u32, tp->packets_out + addend,
-			       sock_net(sk)->ipv4.sysctl_tcp_max_reordering);
+			       READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering));
 	tp->reord_seen++;
 	NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRENOREORDER);
 }
-- 
2.30.2


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

* Re: [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields.
  2022-07-18 17:26 ` [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields Kuniyuki Iwashima
@ 2022-07-19  9:38   ` Ido Schimmel
  0 siblings, 0 replies; 18+ messages in thread
From: Ido Schimmel @ 2022-07-19  9:38 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern, Kuniyuki Iwashima, netdev

On Mon, Jul 18, 2022 at 10:26:41AM -0700, Kuniyuki Iwashima wrote:
> While reading sysctl_fib_multipath_hash_fields, it can be changed
> concurrently.  Thus, we need to add READ_ONCE() to its readers.
> 
> Fixes: ce5c9c20d364 ("ipv4: Add a sysctl to control multipath hash fields")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> CC: Ido Schimmel <idosch@nvidia.com>

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

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

* Re: [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4).
  2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
                   ` (14 preceding siblings ...)
  2022-07-18 17:26 ` [PATCH v1 net 15/15] tcp: Fix data-races around sysctl_tcp_max_reordering Kuniyuki Iwashima
@ 2022-07-20  9:30 ` patchwork-bot+netdevbpf
  15 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-20  9:30 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: davem, edumazet, kuba, pabeni, dsahern, kuni1840, netdev

Hello:

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

On Mon, 18 Jul 2022 10:26:38 -0700 you wrote:
> This series fixes data-races around 17 knobs after fib_multipath_use_neigh
> in ipv4_net_table.
> 
> tcp_fack was skipped because it's obsolete and there's no readers.
> 
> So, round 5 will start with tcp_dsack, 2 rounds left for 27 knobs.
> 
> [...]

Here is the summary with links:
  - [v1,net,01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh.
    https://git.kernel.org/netdev/net/c/87507bcb4f5d
  - [v1,net,02/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy.
    https://git.kernel.org/netdev/net/c/7998c12a08c9
  - [v1,net,03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields.
    https://git.kernel.org/netdev/net/c/8895a9c2ac76
  - [v1,net,04/15] ip: Fix data-races around sysctl_ip_prot_sock.
    https://git.kernel.org/netdev/net/c/9b55c20f8336
  - [v1,net,05/15] udp: Fix a data-race around sysctl_udp_l3mdev_accept.
    https://git.kernel.org/netdev/net/c/3d72bb4188c7
  - [v1,net,06/15] tcp: Fix data-races around sysctl knobs related to SYN option.
    https://git.kernel.org/netdev/net/c/3666f666e996
  - [v1,net,07/15] tcp: Fix a data-race around sysctl_tcp_early_retrans.
    https://git.kernel.org/netdev/net/c/52e65865deb6
  - [v1,net,08/15] tcp: Fix data-races around sysctl_tcp_recovery.
    https://git.kernel.org/netdev/net/c/e7d2ef837e14
  - [v1,net,09/15] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts.
    https://git.kernel.org/netdev/net/c/7c6f2a86ca59
  - [v1,net,10/15] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle.
    https://git.kernel.org/netdev/net/c/4845b5713ab1
  - [v1,net,11/15] tcp: Fix a data-race around sysctl_tcp_retrans_collapse.
    https://git.kernel.org/netdev/net/c/1a63cb91f0c2
  - [v1,net,12/15] tcp: Fix a data-race around sysctl_tcp_stdurg.
    https://git.kernel.org/netdev/net/c/4e08ed41cb11
  - [v1,net,13/15] tcp: Fix a data-race around sysctl_tcp_rfc1337.
    https://git.kernel.org/netdev/net/c/0b484c91911e
  - [v1,net,14/15] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow.
    https://git.kernel.org/netdev/net/c/2d17d9c73823
  - [v1,net,15/15] tcp: Fix data-races around sysctl_tcp_max_reordering.
    https://git.kernel.org/netdev/net/c/a11e5b3e7a59

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] 18+ messages in thread

end of thread, other threads:[~2022-07-20  9:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 17:26 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 01/15] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 02/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 03/15] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields Kuniyuki Iwashima
2022-07-19  9:38   ` Ido Schimmel
2022-07-18 17:26 ` [PATCH v1 net 04/15] ip: Fix data-races around sysctl_ip_prot_sock Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 05/15] udp: Fix a data-race around sysctl_udp_l3mdev_accept Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 06/15] tcp: Fix data-races around sysctl knobs related to SYN option Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 07/15] tcp: Fix a data-race around sysctl_tcp_early_retrans Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 08/15] tcp: Fix data-races around sysctl_tcp_recovery Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 09/15] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 10/15] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 11/15] tcp: Fix a data-race around sysctl_tcp_retrans_collapse Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 12/15] tcp: Fix a data-race around sysctl_tcp_stdurg Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_rfc1337 Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 14/15] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow Kuniyuki Iwashima
2022-07-18 17:26 ` [PATCH v1 net 15/15] tcp: Fix data-races around sysctl_tcp_max_reordering Kuniyuki Iwashima
2022-07-20  9:30 ` [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 4) patchwork-bot+netdevbpf

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.