Skip to content

Commit 9df5335

Browse files
edumazetkuba-moo
authored andcommitted
tcp: annotate data-races around tp->linger2
do_tcp_getsockopt() reads tp->linger2 while another cpu might change its value. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3a037f0 commit 9df5335

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/ipv4/tcp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,11 +3585,11 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
35853585

35863586
case TCP_LINGER2:
35873587
if (val < 0)
3588-
tp->linger2 = -1;
3588+
WRITE_ONCE(tp->linger2, -1);
35893589
else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
3590-
tp->linger2 = TCP_FIN_TIMEOUT_MAX;
3590+
WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
35913591
else
3592-
tp->linger2 = val * HZ;
3592+
WRITE_ONCE(tp->linger2, val * HZ);
35933593
break;
35943594

35953595
case TCP_DEFER_ACCEPT:
@@ -3997,7 +3997,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
39973997
READ_ONCE(net->ipv4.sysctl_tcp_syn_retries);
39983998
break;
39993999
case TCP_LINGER2:
4000-
val = tp->linger2;
4000+
val = READ_ONCE(tp->linger2);
40014001
if (val >= 0)
40024002
val = (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ;
40034003
break;

0 commit comments

Comments
 (0)