Skip to content

Commit 3d0bc44

Browse files
Norbert Slusarekkuba-moo
authored andcommitted
net/vmw_vsock: improve locking in vsock_connect_timeout()
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>
1 parent 5d1cbcc commit 3d0bc44

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

net/vmw_vsock/af_vsock.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,6 @@ static void vsock_connect_timeout(struct work_struct *work)
12431243
{
12441244
struct sock *sk;
12451245
struct vsock_sock *vsk;
1246-
int cancel = 0;
12471246

12481247
vsk = container_of(work, struct vsock_sock, connect_work.work);
12491248
sk = sk_vsock(vsk);
@@ -1254,11 +1253,9 @@ static void vsock_connect_timeout(struct work_struct *work)
12541253
sk->sk_state = TCP_CLOSE;
12551254
sk->sk_err = ETIMEDOUT;
12561255
sk->sk_error_report(sk);
1257-
cancel = 1;
1256+
vsock_transport_cancel_pkt(vsk);
12581257
}
12591258
release_sock(sk);
1260-
if (cancel)
1261-
vsock_transport_cancel_pkt(vsk);
12621259

12631260
sock_put(sk);
12641261
}

0 commit comments

Comments
 (0)