Skip to content

Commit

Permalink
net: annotate data-race around sk->sk_txrehash
Browse files Browse the repository at this point in the history
[ Upstream commit c76a032 ]

sk_getsockopt() runs locklessly. This means sk->sk_txrehash
can be read while other threads are changing its value.

Other locations were handled in commit cb6cd2c
("tcp: Change SYN ACK retransmit behaviour to account for rehash")

Fixes: 2685924 ("txhash: Add socket option to control TX hash rethink behavior")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Akhmat Karakotov <hmukos@yandex-team.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Eric Dumazet authored and gregkh committed Aug 11, 2023
1 parent 60d92bc commit 0317c83
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,9 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
}
if ((u8)val == SOCK_TXREHASH_DEFAULT)
val = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
/* Paired with READ_ONCE() in tcp_rtx_synack() */
/* Paired with READ_ONCE() in tcp_rtx_synack()
* and sk_getsockopt().
*/
WRITE_ONCE(sk->sk_txrehash, (u8)val);
break;

Expand Down Expand Up @@ -1927,7 +1929,8 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
break;

case SO_TXREHASH:
v.val = sk->sk_txrehash;
/* Paired with WRITE_ONCE() in sk_setsockopt() */
v.val = READ_ONCE(sk->sk_txrehash);
break;

default:
Expand Down

0 comments on commit 0317c83

Please sign in to comment.