tcp: Fix a data-race around sysctl_max_tw_buckets.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2149949
Upstream Status: linux.git
Conflicts: Missing upstream commit fbb8295248e1 ("tcp: allocate
           tcp_death_row outside of struct netns_ipv4"):
           tw_count hasn't been converted to a refcount in Centos
           Stream.

commit 6f605b57f3782114e330e108ce1903ede22ec675
Author: Kuniyuki Iwashima <kuniyu@amazon.com>
Date:   Mon Jul 11 17:15:21 2022 -0700

    tcp: Fix a data-race around sysctl_max_tw_buckets.

    While reading sysctl_max_tw_buckets, it can be changed concurrently.
    Thus, we need to add READ_ONCE() to its reader.

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Guillaume Nault <gnault@redhat.com>
This commit is contained in:
Guillaume Nault 2022-11-29 15:30:57 +01:00
parent 1a486afc33
commit 46cdf2120f
1 changed files with 2 additions and 1 deletions

View File

@ -158,7 +158,8 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
{
struct inet_timewait_sock *tw;
if (atomic_read(&dr->tw_count) >= dr->sysctl_max_tw_buckets)
if (atomic_read(&dr->tw_count) >=
READ_ONCE(dr->sysctl_max_tw_buckets))
return NULL;
tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_prot->twsk_slab,