Skip to content

Commit

Permalink
tcp: annotate data-races around tp->linger2
Browse files Browse the repository at this point in the history
[ 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 <edumazet@google.com>
Link: https://lore.kernel.org/r/20230719212857.3943972-8-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Eric Dumazet authored and Greg Kroah-Hartman committed Jul 27, 2023
1 parent b1cd565 commit 3121d64
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3066,11 +3066,11 @@ static int do_tcp_setsockopt(struct sock *sk, int level,

case TCP_LINGER2:
if (val < 0)
tp->linger2 = -1;
WRITE_ONCE(tp->linger2, -1);
else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
tp->linger2 = TCP_FIN_TIMEOUT_MAX;
WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
else
tp->linger2 = val * HZ;
WRITE_ONCE(tp->linger2, val * HZ);
break;

case TCP_DEFER_ACCEPT:
Expand Down Expand Up @@ -3476,7 +3476,7 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
val = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries;
break;
case TCP_LINGER2:
val = tp->linger2;
val = READ_ONCE(tp->linger2);
if (val >= 0)
val = (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ;
break;
Expand Down

0 comments on commit 3121d64

Please sign in to comment.