Skip to content

Commit

Permalink
net/vmw_vsock: improve locking in vsock_connect_timeout()
Browse files Browse the repository at this point in the history
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: 380feae ("vsock: cancel packets when failing to connect")
Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/trinity-f8e0937a-cf0e-4d80-a76e-d9a958ba3ef1-1612535522360@3c-app-gmx-bap12
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Norbert Slusarek authored and Jakub Kicinski committed Feb 6, 2021
1 parent 5d1cbcc commit 3d0bc44
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions net/vmw_vsock/af_vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,6 @@ static void vsock_connect_timeout(struct work_struct *work)
{
struct sock *sk;
struct vsock_sock *vsk;
int cancel = 0;

vsk = container_of(work, struct vsock_sock, connect_work.work);
sk = sk_vsock(vsk);
Expand All @@ -1254,11 +1253,9 @@ static void vsock_connect_timeout(struct work_struct *work)
sk->sk_state = TCP_CLOSE;
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);
}
Expand Down

0 comments on commit 3d0bc44

Please sign in to comment.