]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tcp: annotate data-race around challenge_timestamp
authorEric Dumazet <edumazet@google.com>
Tue, 30 Aug 2022 18:56:55 +0000 (11:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 10:04:50 +0000 (12:04 +0200)
[ Upstream commit cfb642efb8478a64499231cc1d79b80e29cfe766 ]

challenge_timestamp can be read an written by concurrent threads.

This was expected, but we need to annotate the race to avoid potential issues.

Following patch moves challenge_timestamp and challenge_count
to per-netns storage to provide better isolation.

Fixes: a2e9ee9d0bec ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/tcp_input.c

index f4e00ff909da312d13d8d66910c102e6aa2c559f..ff10edc85d64805a00471a3a4fa8346292058c46 100644 (file)
@@ -3484,11 +3484,11 @@ static void tcp_send_challenge_ack(struct sock *sk, const struct sk_buff *skb)
 
        /* Then check host-wide RFC 5961 rate limit. */
        now = jiffies / HZ;
-       if (now != challenge_timestamp) {
+       if (now != READ_ONCE(challenge_timestamp)) {
                u32 ack_limit = READ_ONCE(net->ipv4.sysctl_tcp_challenge_ack_limit);
                u32 half = (ack_limit + 1) >> 1;
 
-               challenge_timestamp = now;
+               WRITE_ONCE(challenge_timestamp, now);
                WRITE_ONCE(challenge_count, half + prandom_u32_max(ack_limit));
        }
        count = READ_ONCE(challenge_count);