]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tcp: fix races in tcp_abort()
authorEric Dumazet <edumazet@google.com>
Tue, 28 May 2024 12:52:52 +0000 (12:52 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 3 Aug 2024 06:59:35 +0000 (08:59 +0200)
[ Upstream commit 5ce4645c23cf5f048eb8e9ce49e514bababdee85 ]

tcp_abort() has the same issue than the one fixed in the prior patch
in tcp_write_err().

In order to get consistent results from tcp_poll(), we must call
sk_error_report() after tcp_done().

We can use tcp_done_with_error() to centralize this logic.

Fixes: c1e64e298b8c ("net: diag: Support destroying TCP sockets.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Link: https://lore.kernel.org/r/20240528125253.1966136-4-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/tcp.c

index cc36ff797484bddac7b70c79c2eb57172b92691d..ec6911034138f3d9f5e8c8ff72ebb73106f336e2 100644 (file)
@@ -4583,14 +4583,10 @@ int tcp_abort(struct sock *sk, int err)
        bh_lock_sock(sk);
 
        if (!sock_flag(sk, SOCK_DEAD)) {
-               WRITE_ONCE(sk->sk_err, err);
-               /* This barrier is coupled with smp_rmb() in tcp_poll() */
-               smp_wmb();
-               sk_error_report(sk);
                if (tcp_need_reset(sk->sk_state))
                        tcp_send_active_reset(sk, GFP_ATOMIC,
                                              SK_RST_REASON_NOT_SPECIFIED);
-               tcp_done(sk);
+               tcp_done_with_error(sk, err);
        }
 
        bh_unlock_sock(sk);