* [PATCH net] vsock: only undo SS_CONNECTING when connect() fails
@ 2026-11-17 1:57 Bobby Eshleman
2026-11-17 2:01 ` Bobby Eshleman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bobby Eshleman @ 2026-11-17 1:57 UTC (permalink / raw)
To: Stefano Garzarella, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, George Zhang, Andy King,
Dmitry Torokhov
Cc: virtualization, netdev, linux-kernel, Kyle Zeng, Michal Luczaj,
Bobby Eshleman
vsock_connect() sleeps with the socket unlocked. Meanwhile the transport
can complete the handshake, setting sock->state to SS_CONNECTED, and then
reset the connection, e.g. in vhost_vsock_reset_orphans(),
virtio_vsock_reset_sock() or vmci_transport_handle_detach(). When
connect() gets the lock back, it finds sk_err set and moves the socket
back to SS_UNCONNECTED. Userspace can then connect() the socket again,
and a connect() to a CID on another transport makes
vsock_assign_transport() release the transport the socket was connected
on.
Only move the socket back to SS_UNCONNECTED if it is still
SS_CONNECTING. A socket that got connected stays SS_CONNECTED, and
another connect() fails with -EISCONN.
Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Reported-by: Kyle Zeng <kylebot@openai.com>
Link: https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/
Suggested-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
---
net/vmw_vsock/af_vsock.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 1d7d53542724..6395c6a7b0b1 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1704,6 +1704,16 @@ static void vsock_connect_timeout(struct work_struct *work)
sock_put(sk);
}
+/* Avoid breaking the socket when another thread has changed its sock->state
+ * while we were asleep.
+ */
+static void vsock_connect_close(struct socket *sock)
+{
+ sock->sk->sk_state = TCP_CLOSE;
+ if (sock->state == SS_CONNECTING)
+ sock->state = SS_UNCONNECTED;
+}
+
static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
int addr_len, int flags)
{
@@ -1862,8 +1872,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
* sk_state == TCP_SYN_SENT, which hereby we break.
* In such case VIRTIO_VSOCK_OP_RST will follow.
*/
- sk->sk_state = TCP_CLOSE;
- sock->state = SS_UNCONNECTED;
+ vsock_connect_close(sock);
/* Try to cancel VIRTIO_VSOCK_OP_REQUEST skb sent out by
* transport->connect().
@@ -1877,10 +1886,8 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
}
err = sock_error(sk);
- if (err) {
- sk->sk_state = TCP_CLOSE;
- sock->state = SS_UNCONNECTED;
- }
+ if (err)
+ vsock_connect_close(sock);
out_wait:
finish_wait(sk_sleep(sk), &wait);
---
base-commit: 533ec433efdc11196f438da90d683053a57257ff
change-id: 20261116-vsock-connect-close-1beb7cb51e7a
Best regards,
--
Bobby Eshleman <bobbyeshleman@meta.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] vsock: only undo SS_CONNECTING when connect() fails
2026-11-17 1:57 [PATCH net] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
@ 2026-11-17 2:01 ` Bobby Eshleman
2026-11-17 2:02 ` netdev-bot+sinfo
2026-11-18 1:58 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Bobby Eshleman @ 2026-11-17 2:01 UTC (permalink / raw)
To: Stefano Garzarella, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, George Zhang, Andy King,
Dmitry Torokhov
Cc: virtualization, netdev, linux-kernel, Kyle Zeng, Michal Luczaj
On Mon, Nov 16, 2026 at 05:57:53PM -0800, Bobby Eshleman wrote:
> vsock_connect() sleeps with the socket unlocked. Meanwhile the transport
> can complete the handshake, setting sock->state to SS_CONNECTED, and then
> reset the connection, e.g. in vhost_vsock_reset_orphans(),
> virtio_vsock_reset_sock() or vmci_transport_handle_detach(). When
> connect() gets the lock back, it finds sk_err set and moves the socket
> back to SS_UNCONNECTED. Userspace can then connect() the socket again,
> and a connect() to a CID on another transport makes
> vsock_assign_transport() release the transport the socket was connected
> on.
>
> Only move the socket back to SS_UNCONNECTED if it is still
> SS_CONNECTING. A socket that got connected stays SS_CONNECTED, and
> another connect() fails with -EISCONN.
>
> Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
> Reported-by: Kyle Zeng <kylebot@openai.com>
> Link: https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/
> Suggested-by: Michal Luczaj <mhal@rbox.co>
> Reviewed-by: Michal Luczaj <mhal@rbox.co>
> Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
> ---
> net/vmw_vsock/af_vsock.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724..6395c6a7b0b1 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -1704,6 +1704,16 @@ static void vsock_connect_timeout(struct work_struct *work)
> sock_put(sk);
> }
>
> +/* Avoid breaking the socket when another thread has changed its sock->state
> + * while we were asleep.
> + */
> +static void vsock_connect_close(struct socket *sock)
> +{
> + sock->sk->sk_state = TCP_CLOSE;
> + if (sock->state == SS_CONNECTING)
> + sock->state = SS_UNCONNECTED;
> +}
> +
Actually there is an issue in the guest netns series that I think would
be fixed by moving TCP_CLOSE within the conditional block here. Will
respin tomorrow.
pw-bot: cr
Best,
Bobby
> static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> int addr_len, int flags)
> {
> @@ -1862,8 +1872,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> * sk_state == TCP_SYN_SENT, which hereby we break.
> * In such case VIRTIO_VSOCK_OP_RST will follow.
> */
> - sk->sk_state = TCP_CLOSE;
> - sock->state = SS_UNCONNECTED;
> + vsock_connect_close(sock);
>
> /* Try to cancel VIRTIO_VSOCK_OP_REQUEST skb sent out by
> * transport->connect().
> @@ -1877,10 +1886,8 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> }
>
> err = sock_error(sk);
> - if (err) {
> - sk->sk_state = TCP_CLOSE;
> - sock->state = SS_UNCONNECTED;
> - }
> + if (err)
> + vsock_connect_close(sock);
>
> out_wait:
> finish_wait(sk_sleep(sk), &wait);
>
> ---
> base-commit: 533ec433efdc11196f438da90d683053a57257ff
> change-id: 20261116-vsock-connect-close-1beb7cb51e7a
>
> Best regards,
> --
> Bobby Eshleman <bobbyeshleman@meta.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] vsock: only undo SS_CONNECTING when connect() fails
2026-11-17 1:57 [PATCH net] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-11-17 2:01 ` Bobby Eshleman
@ 2026-11-17 2:02 ` netdev-bot+sinfo
2026-11-18 1:58 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-17 2:02 UTC (permalink / raw)
To: Bobby Eshleman
Cc: Stefano Garzarella, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, George Zhang, Andy King,
Dmitry Torokhov, virtualization, netdev, linux-kernel, Kyle Zeng,
Michal Luczaj
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] vsock: only undo SS_CONNECTING when connect() fails
2026-11-17 1:57 [PATCH net] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-11-17 2:01 ` Bobby Eshleman
2026-11-17 2:02 ` netdev-bot+sinfo
@ 2026-11-18 1:58 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-18 1:58 UTC (permalink / raw)
To: Bobby Eshleman; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vsock: incomplete handling of post-handshake reset in
vsock_connect()
--
commit bfeaeec883913ff39b46b5892948bd62e612d57c
Author: Bobby Eshleman <bobbyeshleman@meta.com>
vsock: only undo SS_CONNECTING when connect() fails
This commit introduces vsock_connect_close() so that vsock_connect() only
resets sock->state to SS_UNCONNECTED if the socket is still in
SS_CONNECTING.
Link: https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724f..6395c6a7b0b1e 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -1704,6 +1704,16 @@ static void vsock_connect_timeout(struct work_struct *work)
> sock_put(sk);
> }
>
> +/* Avoid breaking the socket when another thread has changed its sock->state
> + * while we were asleep.
> + */
> +static void vsock_connect_close(struct socket *sock)
> +{
> + sock->sk->sk_state = TCP_CLOSE;
> + if (sock->state == SS_CONNECTING)
> + sock->state = SS_UNCONNECTED;
> +}
> +
> static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> int addr_len, int flags)
> {
> @@ -1862,8 +1872,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> * sk_state == TCP_SYN_SENT, which hereby we break.
> * In such case VIRTIO_VSOCK_OP_RST will follow.
> */
> - sk->sk_state = TCP_CLOSE;
> - sock->state = SS_UNCONNECTED;
> + vsock_connect_close(sock);
>
> /* Try to cancel VIRTIO_VSOCK_OP_REQUEST skb sent out by
> * transport->connect().
> @@ -1877,10 +1886,8 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> }
>
> err = sock_error(sk);
> - if (err) {
> - sk->sk_state = TCP_CLOSE;
> - sock->state = SS_UNCONNECTED;
> - }
> + if (err)
> + vsock_connect_close(sock);
>
> out_wait:
> finish_wait(sk_sleep(sk), &wait);
[Severity: Medium]
Can vsock_connect() hang until connect_timeout or corrupt vvs->bytes_unsent
when a socket completes its handshake and is then reset to TCP_CLOSE while
vsock_connect() is sleeping?
CPU0 CPU1
vsock_connect()
release_sock(sk)
schedule_timeout(timeout)
/* handshake completes */
sock->state = SS_CONNECTED
sk->sk_state = TCP_ESTABLISHED
vmci_transport_handle_detach()
sk->sk_state = TCP_CLOSE
lock_sock(sk)
if (sk->sk_state == TCP_ESTABLISHED ||
sk->sk_state == TCP_CLOSING) <-- false
if (signal_pending(current) ||
timeout == 0) <-- false
/* loops back to schedule_timeout() */
When vmci_transport_handle_detach() runs after the socket has already
entered TCP_ESTABLISHED, it sets sk->sk_state = TCP_CLOSE without setting
sk->sk_err:
net/vmw_vsock/vmci_transport.c:vmci_transport_handle_detach() {
...
if (vsk->local_addr.svm_cid == VMADDR_CID_HOST ||
vsock_stream_has_data(vsk) <= 0) {
if (sk->sk_state == TCP_SYN_SENT) {
...
sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET;
sk_error_report(sk);
return;
}
sk->sk_state = TCP_CLOSE;
}
...
}
Because the wait loop only checks for TCP_ESTABLISHED, TCP_CLOSING, and
sk->sk_err, vsock_connect() stays in the loop and sleeps on the closed
socket until connect_timeout expires.
Also, if a signal or timeout coincides with a post-handshake reset to
TCP_CLOSE (via vmci_transport_handle_detach() or
virtio_vsock_reset_sock()), vsock_connect() enters the signal/timeout path
and calls vsock_transport_cancel_pkt(vsk) on a socket in SS_CONNECTED. If
another thread sent data after the handshake completed,
virtio_transport_purge_skbs() frees queued VIRTIO_VSOCK_OP_RW packets
without decrementing vvs->bytes_unsent, breaking SIOCOUTQ and
vsock_linger() accounting.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-vsock-connect-close-v1-1-43fb125973dd@meta.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 1:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 1:57 [PATCH net] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-11-17 2:01 ` Bobby Eshleman
2026-11-17 2:02 ` netdev-bot+sinfo
2026-11-18 1:58 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.