Skip to content

Commit 17c3d75

Browse files
edumazetgregkh
authored andcommitted
tcp: annotate data-races around tp->linger2
[ Upstream commit 9df5335 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e639397 commit 17c3d75

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
@@ -3691,11 +3691,11 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
36913691

36923692
case TCP_LINGER2:
36933693
if (val < 0)
3694-
tp->linger2 = -1;
3694+
WRITE_ONCE(tp->linger2, -1);
36953695
else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
3696-
tp->linger2 = TCP_FIN_TIMEOUT_MAX;
3696+
WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
36973697
else
3698-
tp->linger2 = val * HZ;
3698+
WRITE_ONCE(tp->linger2, val * HZ);
36993699
break;
37003700

37013701
case TCP_DEFER_ACCEPT:
@@ -4099,7 +4099,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
40994099
READ_ONCE(net->ipv4.sysctl_tcp_syn_retries);
41004100
break;
41014101
case TCP_LINGER2:
4102-
val = tp->linger2;
4102+
val = READ_ONCE(tp->linger2);
41034103
if (val >= 0)
41044104
val = (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ;
41054105
break;

0 commit comments

Comments
 (0)