]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tcp: annotate data races around tp->mtu_info
authorEric Dumazet <edumazet@google.com>
Fri, 2 Jul 2021 20:09:03 +0000 (13:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Jul 2021 09:13:45 +0000 (11:13 +0200)
commit 561022acb1ce62e50f7a8258687a21b84282a4cb upstream.

While tp->mtu_info is read while socket is owned, the write
sides happen from err handlers (tcp_v[46]_mtu_reduced)
which only own the socket spinlock.

Fixes: 563d34d05786 ("tcp: dont drop MTU reduction indications")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index ac6135555e24a9b9244d1cd27e3d5619f8252490..71236aa7388d72155a229e0919ce1a9ff4cddaec 100644 (file)
@@ -348,7 +348,7 @@ void tcp_v4_mtu_reduced(struct sock *sk)
 
        if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
                return;
-       mtu = tcp_sk(sk)->mtu_info;
+       mtu = READ_ONCE(tcp_sk(sk)->mtu_info);
        dst = inet_csk_update_pmtu(sk, mtu);
        if (!dst)
                return;
@@ -516,7 +516,7 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
                        if (sk->sk_state == TCP_LISTEN)
                                goto out;
 
-                       tp->mtu_info = info;
+                       WRITE_ONCE(tp->mtu_info, info);
                        if (!sock_owned_by_user(sk)) {
                                tcp_v4_mtu_reduced(sk);
                        } else {
index 2e7a28f327a865e19ee6ebdfddbe951cf00615c5..5121012cc7413401823b80130327c6100908c916 100644 (file)
@@ -340,7 +340,7 @@ static void tcp_v6_mtu_reduced(struct sock *sk)
        if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
                return;
 
-       dst = inet6_csk_update_pmtu(sk, tcp_sk(sk)->mtu_info);
+       dst = inet6_csk_update_pmtu(sk, READ_ONCE(tcp_sk(sk)->mtu_info));
        if (!dst)
                return;
 
@@ -429,7 +429,7 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                if (!ip6_sk_accept_pmtu(sk))
                        goto out;
 
-               tp->mtu_info = ntohl(info);
+               WRITE_ONCE(tp->mtu_info, ntohl(info));
                if (!sock_owned_by_user(sk))
                        tcp_v6_mtu_reduced(sk);
                else if (!test_and_set_bit(TCP_MTU_REDUCED_DEFERRED,