[PATCH v2] vsock: notify server to shutdown when client has pending signal

Subsystems: networking [general], the rest, vm sockets (af_vsock)

STALE1930d

3 messages, 3 authors, 2021-06-21 · open the first message on its own page

[PATCH v2] vsock: notify server to shutdown when client has pending signal

From: Longpeng(Mike) <hidden>
Date: 2021-06-21 06:26:42

The client's sk_state will be set to TCP_ESTABLISHED if the server
replay the client's connect request.

However, if the client has pending signal, its sk_state will be set
to TCP_CLOSE without notify the server, so the server will hold the
corrupt connection.

            client                        server

1. sk_state=TCP_SYN_SENT         |
2. call ->connect()              |
3. wait reply                    |
                                 | 4. sk_state=TCP_ESTABLISHED
                                 | 5. insert to connected list
                                 | 6. reply to the client
7. sk_state=TCP_ESTABLISHED      |
8. insert to connected list      |
9. *signal pending* <--------------------- the user kill client
10. sk_state=TCP_CLOSE           |
client is exiting...             |
11. call ->release()             |
     virtio_transport_close
      if (!(sk->sk_state == TCP_ESTABLISHED ||
	      sk->sk_state == TCP_CLOSING))
		return true; *return at here, the server cannot notice the connection is corrupt*

So the client should notify the peer in this case.

Cc: David S. Miller <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jorgen Hansen <redacted>
Cc: Norbert Slusarek <redacted>
Cc: Andra Paraschiv <redacted>
Cc: Colin Ian King <redacted>
Cc: David Brazdil <redacted>
Cc: Alexander Popov <redacted>
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lkml.org/lkml/2021/5/17/418
Signed-off-by: lixianming <redacted>
Signed-off-by: Longpeng(Mike) <redacted>
---
 net/vmw_vsock/af_vsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 92a72f0..ae11311 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1369,7 +1369,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
 
 		if (signal_pending(current)) {
 			err = sock_intr_errno(timeout);
-			sk->sk_state = TCP_CLOSE;
+			sk->sk_state = sk->sk_state == TCP_ESTABLISHED ? TCP_CLOSING : TCP_CLOSE;
 			sock->state = SS_UNCONNECTED;
 			vsock_transport_cancel_pkt(vsk);
 			goto out_wait;
-- 
1.8.3.1

Re: [PATCH v2] vsock: notify server to shutdown when client has pending signal

From: Stefano Garzarella <sgarzare@redhat.com>
Date: 2021-06-21 10:02:36

On Mon, Jun 21, 2021 at 02:26:01PM +0800, Longpeng(Mike) wrote:
quoted hunk
The client's sk_state will be set to TCP_ESTABLISHED if the server
replay the client's connect request.

However, if the client has pending signal, its sk_state will be set
to TCP_CLOSE without notify the server, so the server will hold the
corrupt connection.

           client                        server

1. sk_state=TCP_SYN_SENT         |
2. call ->connect()              |
3. wait reply                    |
                                | 4. sk_state=TCP_ESTABLISHED
                                | 5. insert to connected list
                                | 6. reply to the client
7. sk_state=TCP_ESTABLISHED      |
8. insert to connected list      |
9. *signal pending* <--------------------- the user kill client
10. sk_state=TCP_CLOSE           |
client is exiting...             |
11. call ->release()             |
    virtio_transport_close
     if (!(sk->sk_state == TCP_ESTABLISHED ||
      sk->sk_state == TCP_CLOSING))
	return true; *return at here, the server cannot notice the connection is corrupt*

So the client should notify the peer in this case.

Cc: David S. Miller <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jorgen Hansen <redacted>
Cc: Norbert Slusarek <redacted>
Cc: Andra Paraschiv <redacted>
Cc: Colin Ian King <redacted>
Cc: David Brazdil <redacted>
Cc: Alexander Popov <redacted>
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lkml.org/lkml/2021/5/17/418
Signed-off-by: lixianming <redacted>
Signed-off-by: Longpeng(Mike) <redacted>
---
net/vmw_vsock/af_vsock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 92a72f0..ae11311 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1369,7 +1369,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
		if (signal_pending(current)) {
			err = sock_intr_errno(timeout);
-			sk->sk_state = TCP_CLOSE;
+			sk->sk_state = sk->sk_state == TCP_ESTABLISHED ? TCP_CLOSING : TCP_CLOSE;
			sock->state = SS_UNCONNECTED;
			vsock_transport_cancel_pkt(vsk);
			goto out_wait;
-- 
1.8.3.1
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Re: [PATCH v2] vsock: notify server to shutdown when client has pending signal

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-06-21 21:50:09

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Mon, 21 Jun 2021 14:26:01 +0800 you wrote:
The client's sk_state will be set to TCP_ESTABLISHED if the server
replay the client's connect request.

However, if the client has pending signal, its sk_state will be set
to TCP_CLOSE without notify the server, so the server will hold the
corrupt connection.

[...]
Here is the summary with links:
  - [v2] vsock: notify server to shutdown when client has pending signal
    https://git.kernel.org/netdev/net/c/c7ff9cff7060

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help