Skip to content

Commit ab1ba21

Browse files
q2vendavem330
authored andcommitted
tcp: Fix data-races around sysctl_tcp_no_ssthresh_metrics_save.
While reading sysctl_tcp_no_ssthresh_metrics_save, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 65e6d90 ("net-tcp: Disable TCP ssthresh metrics cache by default") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8499a24 commit ab1ba21

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/ipv4/tcp_metrics.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void tcp_update_metrics(struct sock *sk)
385385

386386
if (tcp_in_initial_slowstart(tp)) {
387387
/* Slow start still did not finish. */
388-
if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save &&
388+
if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
389389
!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
390390
val = tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
391391
if (val && (tcp_snd_cwnd(tp) >> 1) > val)
@@ -401,7 +401,7 @@ void tcp_update_metrics(struct sock *sk)
401401
} else if (!tcp_in_slow_start(tp) &&
402402
icsk->icsk_ca_state == TCP_CA_Open) {
403403
/* Cong. avoidance phase, cwnd is reliable. */
404-
if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save &&
404+
if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
405405
!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH))
406406
tcp_metric_set(tm, TCP_METRIC_SSTHRESH,
407407
max(tcp_snd_cwnd(tp) >> 1, tp->snd_ssthresh));
@@ -418,7 +418,7 @@ void tcp_update_metrics(struct sock *sk)
418418
tcp_metric_set(tm, TCP_METRIC_CWND,
419419
(val + tp->snd_ssthresh) >> 1);
420420
}
421-
if (!net->ipv4.sysctl_tcp_no_ssthresh_metrics_save &&
421+
if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
422422
!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
423423
val = tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
424424
if (val && tp->snd_ssthresh > val)
@@ -463,7 +463,7 @@ void tcp_init_metrics(struct sock *sk)
463463
if (tcp_metric_locked(tm, TCP_METRIC_CWND))
464464
tp->snd_cwnd_clamp = tcp_metric_get(tm, TCP_METRIC_CWND);
465465

466-
val = net->ipv4.sysctl_tcp_no_ssthresh_metrics_save ?
466+
val = READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ?
467467
0 : tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
468468
if (val) {
469469
tp->snd_ssthresh = val;

0 commit comments

Comments
 (0)