Skip to content

Commit 998127c

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: annotate data races in __tcp_oow_rate_limited()
request sockets are lockless, __tcp_oow_rate_limited() could be called on the same object from different cpus. This is harmless. Add READ_ONCE()/WRITE_ONCE() annotations to avoid a KCSAN report. Fixes: 4ce7e93 ("tcp: rate limit ACK sent by SYN_RECV request sockets") Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c94683e commit 998127c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/ipv4/tcp_input.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,8 +3590,11 @@ static int tcp_ack_update_window(struct sock *sk, const struct sk_buff *skb, u32
35903590
static bool __tcp_oow_rate_limited(struct net *net, int mib_idx,
35913591
u32 *last_oow_ack_time)
35923592
{
3593-
if (*last_oow_ack_time) {
3594-
s32 elapsed = (s32)(tcp_jiffies32 - *last_oow_ack_time);
3593+
/* Paired with the WRITE_ONCE() in this function. */
3594+
u32 val = READ_ONCE(*last_oow_ack_time);
3595+
3596+
if (val) {
3597+
s32 elapsed = (s32)(tcp_jiffies32 - val);
35953598

35963599
if (0 <= elapsed &&
35973600
elapsed < READ_ONCE(net->ipv4.sysctl_tcp_invalid_ratelimit)) {
@@ -3600,7 +3603,10 @@ static bool __tcp_oow_rate_limited(struct net *net, int mib_idx,
36003603
}
36013604
}
36023605

3603-
*last_oow_ack_time = tcp_jiffies32;
3606+
/* Paired with the prior READ_ONCE() and with itself,
3607+
* as we might be lockless.
3608+
*/
3609+
WRITE_ONCE(*last_oow_ack_time, tcp_jiffies32);
36043610

36053611
return false; /* not rate-limited: go ahead, send dupack now! */
36063612
}

0 commit comments

Comments
 (0)