Skip to content

Commit 6d4486e

Browse files
Zhuang Shengendavem330
authored andcommitted
vsock: avoid to close connected socket after the timeout
When client and server establish a connection through vsock, the client send a request to the server to initiate the connection, then start a timer to wait for the server's response. When the server's RESPONSE message arrives, the timer also times out and exits. The server's RESPONSE message is processed first, and the connection is established. However, the client's timer also times out, the original processing logic of the client is to directly set the state of this vsock to CLOSE and return ETIMEDOUT. It will not notify the server when the port is released, causing the server port remain. when client's vsock_connect timeout,it should check sk state is ESTABLISHED or not. if sk state is ESTABLISHED, it means the connection is established, the client should not set the sk state to CLOSE Note: I encountered this issue on kernel-4.18, which can be fixed by this patch. Then I checked the latest code in the community and found similar issue. Fixes: d021c34 ("VSOCK: Introduce VM Sockets") Signed-off-by: Zhuang Shengen <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 134120b commit 6d4486e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr,
14621462
vsock_transport_cancel_pkt(vsk);
14631463
vsock_remove_connected(vsk);
14641464
goto out_wait;
1465-
} else if (timeout == 0) {
1465+
} else if ((sk->sk_state != TCP_ESTABLISHED) && (timeout == 0)) {
14661466
err = -ETIMEDOUT;
14671467
sk->sk_state = TCP_CLOSE;
14681468
sock->state = SS_UNCONNECTED;

0 commit comments

Comments
 (0)