Skip to content

Commit

Permalink
vsock: Set socket state back to SS_UNCONNECTED in vsock_connect_timeo…
Browse files Browse the repository at this point in the history
…ut()

Imagine two non-blocking vsock_connect() requests on the same socket.
The first request schedules @connect_work, and after it times out,
vsock_connect_timeout() sets *sock* state back to TCP_CLOSE, but keeps
*socket* state as SS_CONNECTING.

Later, the second request returns -EALREADY, meaning the socket "already
has a pending connection in progress", even though the first request has
already timed out.

As suggested by Stefano, fix it by setting *socket* state back to
SS_UNCONNECTED, so that the second request will return -ETIMEDOUT.

Suggested-by: Stefano Garzarella <[email protected]>
Fixes: d021c34 ("VSOCK: Introduce VM Sockets")
Reviewed-by: Stefano Garzarella <[email protected]>
Signed-off-by: Peilin Ye <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
peilin-ye authored and davem330 committed Aug 10, 2022
1 parent 7e97cfe commit a3e7b29
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/vmw_vsock/af_vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ static void vsock_connect_timeout(struct work_struct *work)
if (sk->sk_state == TCP_SYN_SENT &&
(sk->sk_shutdown != SHUTDOWN_MASK)) {
sk->sk_state = TCP_CLOSE;
sk->sk_socket->state = SS_UNCONNECTED;
sk->sk_err = ETIMEDOUT;
sk_error_report(sk);
vsock_transport_cancel_pkt(vsk);
Expand Down

0 comments on commit a3e7b29

Please sign in to comment.