From: Norbert Slusarek <nslusa...@gmx.net>

commit 3d0bc44d39bca615b72637e340317b7899b7f911 upstream.

A possible locking issue in vsock_connect_timeout() was recognized by
Eric Dumazet which might cause a null pointer dereference in
vsock_transport_cancel_pkt(). This patch assures that
vsock_transport_cancel_pkt() will be called within the lock, so a race
condition won't occur which could result in vsk->transport to be set to NULL.

Fixes: 380feae0def7 ("vsock: cancel packets when failing to connect")
Reported-by: Eric Dumazet <eric.duma...@gmail.com>
Signed-off-by: Norbert Slusarek <nslusa...@gmx.net>
Reviewed-by: Stefano Garzarella <sgarz...@redhat.com>
Link: 
https://lore.kernel.org/r/trinity-f8e0937a-cf0e-4d80-a76e-d9a958ba3ef1-1612535522360@3c-app-gmx-bap12
Signed-off-by: Jakub Kicinski <k...@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 net/vmw_vsock/af_vsock.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1121,7 +1121,6 @@ static void vsock_connect_timeout(struct
 {
        struct sock *sk;
        struct vsock_sock *vsk;
-       int cancel = 0;
 
        vsk = container_of(work, struct vsock_sock, connect_work.work);
        sk = sk_vsock(vsk);
@@ -1132,11 +1131,9 @@ static void vsock_connect_timeout(struct
                sk->sk_state = SS_UNCONNECTED;
                sk->sk_err = ETIMEDOUT;
                sk->sk_error_report(sk);
-               cancel = 1;
+               vsock_transport_cancel_pkt(vsk);
        }
        release_sock(sk);
-       if (cancel)
-               vsock_transport_cancel_pkt(vsk);
 
        sock_put(sk);
 }


Reply via email to