Skip to content

Commit aacd467

Browse files
edumazetdavem330
authored andcommitted
tcp: annotate data-race around tcp_md5sig_pool_populated
tcp_md5sig_pool_populated can be read while another thread changes its value. The race has no consequence because allocations are protected with tcp_md5sig_mutex. This patch adds READ_ONCE() and WRITE_ONCE() to document the race and silence KCSAN. Reported-by: Abhishek Shah <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 73ef239 commit aacd467

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/ipv4/tcp.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,12 +4433,16 @@ static void __tcp_alloc_md5sig_pool(void)
44334433
* to memory. See smp_rmb() in tcp_get_md5sig_pool()
44344434
*/
44354435
smp_wmb();
4436-
tcp_md5sig_pool_populated = true;
4436+
/* Paired with READ_ONCE() from tcp_alloc_md5sig_pool()
4437+
* and tcp_get_md5sig_pool().
4438+
*/
4439+
WRITE_ONCE(tcp_md5sig_pool_populated, true);
44374440
}
44384441

44394442
bool tcp_alloc_md5sig_pool(void)
44404443
{
4441-
if (unlikely(!tcp_md5sig_pool_populated)) {
4444+
/* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */
4445+
if (unlikely(!READ_ONCE(tcp_md5sig_pool_populated))) {
44424446
mutex_lock(&tcp_md5sig_mutex);
44434447

44444448
if (!tcp_md5sig_pool_populated) {
@@ -4449,7 +4453,8 @@ bool tcp_alloc_md5sig_pool(void)
44494453

44504454
mutex_unlock(&tcp_md5sig_mutex);
44514455
}
4452-
return tcp_md5sig_pool_populated;
4456+
/* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */
4457+
return READ_ONCE(tcp_md5sig_pool_populated);
44534458
}
44544459
EXPORT_SYMBOL(tcp_alloc_md5sig_pool);
44554460

@@ -4465,7 +4470,8 @@ struct tcp_md5sig_pool *tcp_get_md5sig_pool(void)
44654470
{
44664471
local_bh_disable();
44674472

4468-
if (tcp_md5sig_pool_populated) {
4473+
/* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */
4474+
if (READ_ONCE(tcp_md5sig_pool_populated)) {
44694475
/* coupled with smp_wmb() in __tcp_alloc_md5sig_pool() */
44704476
smp_rmb();
44714477
return this_cpu_ptr(&tcp_md5sig_pool);

0 commit comments

Comments
 (0)