sysctl: Fix data-races around ipv4_net_table (Round 5).
Subsystems (4)
cover sysctl: Fix data-races around ipv4_net_table (Round 5).
This series fixes data-races around 15 knobs after tcp_dsack in ipv4_net_table.
tcp_tso_win_divisor was skipped because it already uses READ_ONCE().
So, the final round for ipv4_net_table will start with tcp_pacing_ss_ratio.
Kuniyuki Iwashima (15):
tcp: Fix data-races around sysctl_tcp_dsack.
tcp: Fix a data-race around sysctl_tcp_app_win.
tcp: Fix a data-race around sysctl_tcp_adv_win_scale.
tcp: Fix a data-race around sysctl_tcp_frto.
tcp: Fix a data-race around sysctl_tcp_nometrics_save.
tcp: Fix data-races around sysctl_tcp_no_ssthresh_metrics_save.
tcp: Fix data-races around sysctl_tcp_moderate_rcvbuf.
tcp: Fix data-races around sysctl_tcp_workaround_signed_windows.
tcp: Fix a data-race around sysctl_tcp_limit_output_bytes.
tcp: Fix a data-race around sysctl_tcp_challenge_ack_limit.
tcp: Fix a data-race around sysctl_tcp_min_tso_segs.
tcp: Fix a data-race around sysctl_tcp_tso_rtt_log.
tcp: Fix a data-race around sysctl_tcp_min_rtt_wlen.
tcp: Fix a data-race around sysctl_tcp_autocorking.
tcp: Fix a data-race around sysctl_tcp_invalid_ratelimit.
include/net/tcp.h | 2 +- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 17 +++++++++-------- net/ipv4/tcp_metrics.c | 10 +++++----- net/ipv4/tcp_output.c | 10 +++++----- net/mptcp/options.c | 2 +- net/mptcp/protocol.c | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/15 tcp: Fix data-races around sysctl_tcp_dsack.
While reading sysctl_tcp_dsack, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/ipv4/tcp_input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +2 -2
@@ -4426,7 +4426,7 @@ static void tcp_dsack_set(struct sock *sk, u32 seq, u32 end_seq) {struct tcp_sock *tp =tcp_sk (sk); -if (tcp_is_sack (tp) &&sock_net (sk)->ipv4.sysctl_tcp_dsack) { +if (tcp_is_sack (tp) &&READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_dsack)) {int mib_idx;if (before (seq, tp->rcv_nxt))
@@ -4473,7 +4473,7 @@ static void tcp_send_dupack(struct sock *sk, const struct sk_buff *skb)NET_INC_STATS (sock_net (sk),LINUX_MIB_DELAYEDACKLOST );tcp_enter_quickack_mode (sk,TCP_MAX_QUICKACKS ); -if (tcp_is_sack (tp) &&sock_net (sk)->ipv4.sysctl_tcp_dsack) { +if (tcp_is_sack (tp) &&READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_dsack)) {u32 end_seq =TCP_SKB_CB (skb)->end_seq;tcp_rcv_spurious_retrans (sk, skb);
Signature · 1 line
2.30.2
PATCH 2/15 tcp: Fix a data-race around sysctl_tcp_app_win.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_app_win, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
@@ -534,7 +534,7 @@ static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb,*/ static void tcp_init_buffer_space (struct sock *sk) { -int tcp_app_win =sock_net (sk)->ipv4.sysctl_tcp_app_win; +int tcp_app_win =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_app_win);struct tcp_sock *tp =tcp_sk (sk);int maxwin;
Signature · 1 line
2.30.2
PATCH 3/15 tcp: Fix a data-race around sysctl_tcp_adv_win_scale.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_adv_win_scale, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- include/net/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/tcp.h +1 -1
@@ -1419,7 +1419,7 @@ void tcp_select_initial_window(const struct sock *sk, int __space,static inline int tcp_win_from_space (const struct sock *sk,int space) { -int tcp_adv_win_scale =sock_net (sk)->ipv4.sysctl_tcp_adv_win_scale; +int tcp_adv_win_scale =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_adv_win_scale);return tcp_adv_win_scale <=0 ? (space>>(-tcp_adv_win_scale)) :
Signature · 1 line
2.30.2
PATCH 4/15 tcp: Fix a data-race around sysctl_tcp_frto.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_frto, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
@@ -2175,7 +2175,7 @@ void tcp_enter_loss(struct sock *sk)* loss recovery is underway except recurring timeout(s) on * the same SND.UNA (sec 3.2). Disable F-RTO on path MTU probing */ - tp->frto = net->ipv4.sysctl_tcp_frto && + tp->frto =READ_ONCE (net->ipv4.sysctl_tcp_frto) && (new_recovery || icsk->icsk_retransmits) && !inet_csk (sk)->icsk_mtup.probe_size; }
Signature · 1 line
2.30.2
PATCH 5/15 tcp: Fix a data-race around sysctl_tcp_nometrics_save.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_nometrics_save, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_metrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_metrics.c +1 -1
@@ -329,7 +329,7 @@ void tcp_update_metrics(struct sock *sk)int m;sk_dst_confirm (sk); -if (net->ipv4.sysctl_tcp_nometrics_save || !dst) +if (READ_ONCE (net->ipv4.sysctl_tcp_nometrics_save) || !dst)return ;rcu_read_lock ();
Signature · 1 line
2.30.2
PATCH 6/15 tcp: Fix data-races around sysctl_tcp_no_ssthresh_metrics_save.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_no_ssthresh_metrics_save, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
---
CC: Kevin(Yudong) Yang <[email protected]>
--- net/ipv4/tcp_metrics.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/tcp_metrics.c +4 -4
@@ -385,7 +385,7 @@ void tcp_update_metrics(struct sock *sk)if (tcp_in_initial_slowstart (tp)) {/* Slow start still did not finish. */ -if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save && +if (!READ_ONCE (net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) && !tcp_metric_locked (tm,TCP_METRIC_SSTHRESH )) { val =tcp_metric_get (tm,TCP_METRIC_SSTHRESH );if (val && (tcp_snd_cwnd (tp) >>1 ) > val)
@@ -401,7 +401,7 @@ void tcp_update_metrics(struct sock *sk) }else if (!tcp_in_slow_start (tp) && icsk->icsk_ca_state == TCP_CA_Open) {/* Cong. avoidance phase, cwnd is reliable. */ -if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save && +if (!READ_ONCE (net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) && !tcp_metric_locked (tm,TCP_METRIC_SSTHRESH ))tcp_metric_set (tm,TCP_METRIC_SSTHRESH ,max (tcp_snd_cwnd (tp) >>1 , tp->snd_ssthresh));
@@ -418,7 +418,7 @@ void tcp_update_metrics(struct sock *sk)tcp_metric_set (tm,TCP_METRIC_CWND , (val + tp->snd_ssthresh) >>1 ); } -if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save && +if (!READ_ONCE (net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) && !tcp_metric_locked (tm,TCP_METRIC_SSTHRESH )) { val =tcp_metric_get (tm,TCP_METRIC_SSTHRESH );if (val && tp->snd_ssthresh > val)
@@ -463,7 +463,7 @@ void tcp_init_metrics(struct sock *sk)if (tcp_metric_locked (tm,TCP_METRIC_CWND )) tp->snd_cwnd_clamp =tcp_metric_get (tm,TCP_METRIC_CWND ); - val = net->ipv4.sysctl_tcp_no_ssthresh_metrics_save ? + val =READ_ONCE (net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ?0 :tcp_metric_get (tm,TCP_METRIC_SSTHRESH );if (val) { tp->snd_ssthresh = val;
Signature · 1 line
2.30.2
PATCH 7/15 tcp: Fix data-races around sysctl_tcp_moderate_rcvbuf.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_moderate_rcvbuf, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/ipv4/tcp_input.c | 2 +- net/mptcp/protocol.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +1 -1
@@ -724,7 +724,7 @@ void tcp_rcv_space_adjust(struct sock *sk)* <prev RTT . ><current RTT .. ><next RTT .... > */ -if (sock_net (sk)->ipv4.sysctl_tcp_moderate_rcvbuf && +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_moderate_rcvbuf) && !(sk->sk_userlocks &SOCK_RCVBUF_LOCK )) {int rcvmem, rcvbuf;u64 rcvwin, grow;
net/mptcp/protocol.c +1 -1
@@ -1908,7 +1908,7 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)if (msk->rcvq_space.copied <= msk->rcvq_space.space) goto new_measure; -if (sock_net (sk)->ipv4.sysctl_tcp_moderate_rcvbuf && +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_moderate_rcvbuf) && !(sk->sk_userlocks &SOCK_RCVBUF_LOCK )) {int rcvmem, rcvbuf;u64 rcvwin, grow;
Signature · 1 line
2.30.2
PATCH 8/15 tcp: Fix data-races around sysctl_tcp_workaround_signed_windows.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_workaround_signed_windows, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
---
CC: Rick Jones <[email protected]>
--- net/ipv4/tcp_output.c | 4 ++-- net/mptcp/options.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/tcp_output.c +2 -2
@@ -230,7 +230,7 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,* which we interpret as a sign the remote TCP is not * misinterpreting the window field as a signed quantity. */ -if (sock_net (sk)->ipv4.sysctl_tcp_workaround_signed_windows) +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_workaround_signed_windows)) (*rcv_wnd) =min (space,MAX_TCP_WINDOW );else (*rcv_wnd) =min_t (u32, space,U16_MAX );
@@ -285,7 +285,7 @@ static u16 tcp_select_window(struct sock *sk)* scaled window. */ if (!tp->rx_opt.rcv_wscale && -sock_net (sk)->ipv4.sysctl_tcp_workaround_signed_windows) +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_workaround_signed_windows)) new_win =min (new_win,MAX_TCP_WINDOW );else new_win =min (new_win, (65535U << tp->rx_opt.rcv_wscale));
net/mptcp/options.c +1 -1
@@ -1271,7 +1271,7 @@ static void mptcp_set_rwin(struct tcp_sock *tp, struct tcphdr *th)if (unlikely (th->syn)) new_win =min (new_win,65535U ) << tp->rx_opt.rcv_wscale;if (!tp->rx_opt.rcv_wscale && -sock_net (ssk)->ipv4.sysctl_tcp_workaround_signed_windows) +READ_ONCE (sock_net (ssk)->ipv4.sysctl_tcp_workaround_signed_windows)) new_win =min (new_win,MAX_TCP_WINDOW );else new_win =min (new_win, (65535U << tp->rx_opt.rcv_wscale));
Signature · 1 line
2.30.2
PATCH 9/15 tcp: Fix a data-race around sysctl_tcp_limit_output_bytes.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_limit_output_bytes, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
@@ -2507,7 +2507,7 @@ static bool tcp_small_queue_check(struct sock *sk, const struct sk_buff *skb, sk->sk_pacing_rate >> READ_ONCE(sk->sk_pacing_shift));if (sk->sk_pacing_status ==SK_PACING_NONE ) limit = min_t(unsigned long, limit, -sock_net (sk)->ipv4.sysctl_tcp_limit_output_bytes); +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_limit_output_bytes)); limit <<= factor; if (static_branch_unlikely(&tcp_tx_delay_enabled) &&
Signature · 1 line
2.30.2
PATCH 10/15 tcp: Fix a data-race around sysctl_tcp_challenge_ack_limit.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_challenge_ack_limit, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
@@ -3629,7 +3629,7 @@ static void tcp_send_challenge_ack(struct sock *sk)/* Then check host-wide RFC 5961 rate limit. */ now = jiffies /HZ ;if (now != challenge_timestamp) { -u32 ack_limit = net->ipv4.sysctl_tcp_challenge_ack_limit; +u32 ack_limit =READ_ONCE (net->ipv4.sysctl_tcp_challenge_ack_limit);u32 half = (ack_limit +1 ) >>1 ; challenge_timestamp = now;
Signature · 1 line
2.30.2
PATCH 11/15 tcp: Fix a data-race around sysctl_tcp_min_tso_segs.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_min_tso_segs, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
@@ -1995,7 +1995,7 @@ static u32 tcp_tso_segs(struct sock *sk, unsigned int mss_now) min_tso = ca_ops->min_tso_segs ? ca_ops->min_tso_segs (sk) : -sock_net (sk)->ipv4.sysctl_tcp_min_tso_segs; +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_min_tso_segs); tso_segs =tcp_tso_autosize (sk, mss_now, min_tso);return min_t (u32, tso_segs, sk->sk_gso_max_segs);
Signature · 1 line
2.30.2
PATCH 12/15 tcp: Fix a data-race around sysctl_tcp_tso_rtt_log.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_tso_rtt_log, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
@@ -1976,7 +1976,7 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, bytes = sk->sk_pacing_rate >>READ_ONCE (sk->sk_pacing_shift); - r =tcp_min_rtt (tcp_sk (sk)) >>sock_net (sk)->ipv4.sysctl_tcp_tso_rtt_log; + r =tcp_min_rtt (tcp_sk (sk)) >>READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_tso_rtt_log);if (r <BITS_PER_TYPE (sk->sk_gso_max_size)) bytes += sk->sk_gso_max_size >> r;
Signature · 1 line
2.30.2
PATCH 13/15 tcp: Fix a data-race around sysctl_tcp_min_rtt_wlen.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_min_rtt_wlen, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
---
CC: Yuchung Cheng <[email protected]>
--- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
@@ -3058,7 +3058,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,static void tcp_update_rtt_min (struct sock *sk,u32 rtt_us,const int flag) { -u32 wlen =sock_net (sk)->ipv4.sysctl_tcp_min_rtt_wlen *HZ ; +u32 wlen =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_min_rtt_wlen) *HZ ;struct tcp_sock *tp =tcp_sk (sk);if ((flag &FLAG_ACK_MAYBE_DELAYED ) && rtt_us >tcp_min_rtt (tp)) {
Signature · 1 line
2.30.2
PATCH 14/15 tcp: Fix a data-race around sysctl_tcp_autocorking.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_autocorking, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -686,7 +686,7 @@ static bool tcp_should_autocork(struct sock *sk, struct sk_buff *skb, int size_goal) {return skb->len < size_goal && -sock_net (sk)->ipv4.sysctl_tcp_autocorking && +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_autocorking) && !tcp_rtx_queue_empty (sk) &&refcount_read (&sk->sk_wmem_alloc) > skb->truesize &&tcp_skb_can_collapse_to (skb);
Signature · 1 line
2.30.2
PATCH 15/15 tcp: Fix a data-race around sysctl_tcp_invalid_ratelimit.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_invalid_ratelimit, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
---
CC: Neal Cardwell <[email protected]>
--- net/ipv4/tcp_input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +2 -1
@@ -3581,7 +3581,8 @@ static bool __tcp_oow_rate_limited(struct net *net, int mib_idx,if (*last_oow_ack_time) {s32 elapsed = (s32)(tcp_jiffies32 - *last_oow_ack_time); -if (0 <= elapsed && elapsed < net->ipv4.sysctl_tcp_invalid_ratelimit) { +if (0 <= elapsed && + elapsed <READ_ONCE (net->ipv4.sysctl_tcp_invalid_ratelimit)) {NET_INC_STATS (net, mib_idx);return true;/* rate-limited: don't send yet! */ }
Signature · 1 line
2.30.2
Quoted 9 lines · Kuniyuki Iwashima
This series fixes data-races around 15 knobs after
tcp_dsackinipv4_net_table.
tcp_tso_win_divisorwas skipped because it already usesREAD_ONCE().So, the final round for
ipv4_net_tablewill start withtcp_pacing_ss_ratio.
For the series:
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Quoted 8 lines · On Wed, 20 Jul 2022 09:50:11 -0700 you wrote:
This series fixes data-races around 15 knobs after
tcp_dsackinipv4_net_table.
tcp_tso_win_divisorwas skipped because it already usesREAD_ONCE().So, the final round for
ipv4_net_tablewill start withtcp_pacing_ss_ratio.[...]
Here is the summary with links:
- [v1,net,01/15] tcp: Fix data-races around sysctl_tcp_dsack.
https://git.kernel.org/netdev/net/c/58ebb1c8b35a - [v1,net,02/15] tcp: Fix a data-race around sysctl_tcp_app_win. https://git.kernel.org/netdev/net/c/02ca527ac558 - [v1,net,03/15] tcp: Fix a data-race around sysctl_tcp_adv_win_scale. https://git.kernel.org/netdev/net/c/36eeee75ef01 - [v1,net,04/15] tcp: Fix a data-race around sysctl_tcp_frto. https://git.kernel.org/netdev/net/c/706c6202a358 - [v1,net,05/15] tcp: Fix a data-race around sysctl_tcp_nometrics_save. https://git.kernel.org/netdev/net/c/8499a2454d9e - [v1,net,06/15] tcp: Fix data-races around sysctl_tcp_no_ssthresh_metrics_save. https://git.kernel.org/netdev/net/c/ab1ba21b523a - [v1,net,07/15] tcp: Fix data-races around sysctl_tcp_moderate_rcvbuf. https://git.kernel.org/netdev/net/c/780476488844 - [v1,net,08/15] tcp: Fix data-races around sysctl_tcp_workaround_signed_windows. https://git.kernel.org/netdev/net/c/0f1e4d06591d - [v1,net,09/15] tcp: Fix a data-race around sysctl_tcp_limit_output_bytes. https://git.kernel.org/netdev/net/c/9fb90193fbd6 - [v1,net,10/15] tcp: Fix a data-race around sysctl_tcp_challenge_ack_limit. https://git.kernel.org/netdev/net/c/db3815a2fa69 - [v1,net,11/15] tcp: Fix a data-race around sysctl_tcp_min_tso_segs. https://git.kernel.org/netdev/net/c/e0bb4ab9dfdd - [v1,net,12/15] tcp: Fix a data-race around sysctl_tcp_tso_rtt_log. https://git.kernel.org/netdev/net/c/2455e61b85e9 - [v1,net,13/15] tcp: Fix a data-race around sysctl_tcp_min_rtt_wlen. https://git.kernel.org/netdev/net/c/1330ffacd05f - [v1,net,14/15] tcp: Fix a data-race around sysctl_tcp_autocorking. https://git.kernel.org/netdev/net/c/85225e6f0a76 - [v1,net,15/15] tcp: Fix a data-race around sysctl_tcp_invalid_ratelimit. https://git.kernel.org/netdev/net/c/2afdbe7b8de8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html