* [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails
@ 2026-12-01 0:52 Bobby Eshleman
2026-12-01 0:58 ` netdev-bot+sinfo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bobby Eshleman @ 2026-12-01 0:52 UTC (permalink / raw)
To: Stefano Garzarella, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, George Zhang, Andy King,
Dmitry Torokhov, Willem de Bruijn
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.
Likewise, only move sk_state to TCP_CLOSE if it is still TCP_SYN_SENT.
Otherwise a second thread blocked in connect() on the same socket can
time out after the first one failed and called listen(), and overwrite
TCP_LISTEN.
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>
---
Changes in v3:
- Explain why vsock_connect_close() undoes only the state that connect()
set (Stefano)
- Pick up Michal's RoB
- Link to v2: https://lore.kernel.org/r/20261117-vsock-connect-close-v2-1-db5388323770@meta.com
Changes in v2:
- Only reset sk_state if it is still TCP_SYN_SENT, so a concurrent
connect() caller that times out late doesn't overwrite TCP_LISTEN
(Sashiko).
- Drop Michal's Reviewed-by since the code changed.
- Link to v1: https://lore.kernel.org/r/20261116-vsock-connect-close-v1-1-43fb125973dd@meta.com
---
net/vmw_vsock/af_vsock.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 1d7d53542724..782bcb2eb956 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1704,6 +1704,21 @@ static void vsock_connect_timeout(struct work_struct *work)
sock_put(sk);
}
+/* Undo only the state this connect() attempt set. While we slept, the
+ * transport may have connected and then reset the socket (it is still in
+ * vsock_connected_table, so it must not go back to SS_UNCONNECTED), or
+ * another thread may have turned it into a listener.
+ */
+static void vsock_connect_close(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+
+ if (sk->sk_state == TCP_SYN_SENT)
+ 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 +1877,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 +1891,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: 76fca30e8d34eb151fcf4f363b51c21b7e8c4709
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 v3] vsock: only undo SS_CONNECTING when connect() fails
2026-12-01 0:52 [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
@ 2026-12-01 0:58 ` netdev-bot+sinfo
2026-12-01 8:20 ` Stefano Garzarella
2026-12-01 22:17 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 0:58 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, Willem de Bruijn, 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:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- 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 v3] vsock: only undo SS_CONNECTING when connect() fails
2026-12-01 0:52 [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-12-01 0:58 ` netdev-bot+sinfo
@ 2026-12-01 8:20 ` Stefano Garzarella
2026-12-01 22:17 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2026-12-01 8:20 UTC (permalink / raw)
To: Bobby Eshleman
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, George Zhang, Andy King, Dmitry Torokhov,
Willem de Bruijn, virtualization, netdev, linux-kernel, Kyle Zeng,
Michal Luczaj
On Mon, Nov 30, 2026 at 04:52: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.
>
> Likewise, only move sk_state to TCP_CLOSE if it is still TCP_SYN_SENT.
> Otherwise a second thread blocked in connect() on the same socket can
> time out after the first one failed and called listen(), and overwrite
> TCP_LISTEN.
>
> 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>
> ---
> Changes in v3:
> - Explain why vsock_connect_close() undoes only the state that connect()
> set (Stefano)
> - Pick up Michal's RoB
> - Link to v2: https://lore.kernel.org/r/20261117-vsock-connect-close-v2-1-db5388323770@meta.com
>
> Changes in v2:
> - Only reset sk_state if it is still TCP_SYN_SENT, so a concurrent
> connect() caller that times out late doesn't overwrite TCP_LISTEN
> (Sashiko).
> - Drop Michal's Reviewed-by since the code changed.
> - Link to v1: https://lore.kernel.org/r/20261116-vsock-connect-close-v1-1-43fb125973dd@meta.com
> ---
> net/vmw_vsock/af_vsock.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails
2026-12-01 0:52 [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-12-01 0:58 ` netdev-bot+sinfo
2026-12-01 8:20 ` Stefano Garzarella
@ 2026-12-01 22:17 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 22:17 UTC (permalink / raw)
To: bobbyeshleman
Cc: sgarzare, davem, edumazet, kuba, pabeni, horms, georgezhang,
acking, dtor, willemb, virtualization, netdev, linux-kernel,
kylebot, mhal
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] vsock_connect_close() cannot tell which connect() attempt set
TCP_SYN_SENT/SS_CONNECTING, so the new comment's claim ("Undo only the…
- [Low] The commit message does not describe the worst consequence of the
bug it fixes.
- [Low] The patch makes the blocking and non-blocking connect() failure
paths treat SS_DISCONNECTING differently.
--
vsock: only undo SS_CONNECTING when connect() fails
This patch adds vsock_connect_close(), which rolls back sk_state only
if it is still TCP_SYN_SENT and sock->state only if it is still
SS_CONNECTING. The blocking connect() error paths now use it. A socket
that got connected and was then reset by the transport therefore stays
SS_CONNECTED, and a late waiter can no longer overwrite TCP_LISTEN.
Link: https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/
> 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.
[Severity: Low]
Could the commit message also describe the same-transport reconnect
case? Before this patch it seems to be the worse outcome.
When the transport does not change, vsock_assign_transport() returns
early. release() is not called and the socket is not removed from
vsock_connected_table:
net/vmw_vsock/af_vsock.c:vsock_assign_transport() {
...
if (vsk->transport && vsk->transport == new_transport) {
ret = 0;
goto err;
}
...
}
virtio_vsock_reset_sock() also leaves the socket in the table and does
not set SOCK_DONE. The RESPONSE to the new REQUEST then reaches
virtio_transport_recv_connecting(), which inserts it again without a
check:
sk->sk_state = TCP_ESTABLISHED;
sk->sk_socket->state = SS_CONNECTED;
vsock_insert_connected(vsk);
__vsock_insert_connected() then runs this on an entry that is already
linked, possibly in a different bucket if remote_addr changed:
sock_hold(&vsk->sk);
list_add(&vsk->connected_table, list);
That gives list corruption in vsock_connected_table and an extra socket
reference. The new code comment says the socket "is still in
vsock_connected_table", but the changelog only mentions the
transport-release case.
The code change does block this path, since connect() now returns
-EISCONN. Would it help stable and security triage to mention the list
corruption and refcount imbalance here?
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724f..782bcb2eb956c 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -1704,6 +1704,21 @@ static void vsock_connect_timeout(struct work_struct *work)
> sock_put(sk);
> }
>
> +/* Undo only the state this connect() attempt set. While we slept, the
> + * transport may have connected and then reset the socket (it is still in
> + * vsock_connected_table, so it must not go back to SS_UNCONNECTED), or
> + * another thread may have turned it into a listener.
> + */
> +static void vsock_connect_close(struct socket *sock)
> +{
> + struct sock *sk = sock->sk;
> +
> + if (sk->sk_state == TCP_SYN_SENT)
> + sk->sk_state = TCP_CLOSE;
> + if (sock->state == SS_CONNECTING)
> + sock->state = SS_UNCONNECTED;
[Severity: Low]
Is it intended that a socket shut down during a blocking connect() now
stays in SS_DISCONNECTING?
vsock_shutdown() moves any socket that is not SS_UNCONNECTED to
SS_DISCONNECTING, including one in SS_CONNECTING. It leaves sk_state at
TCP_SYN_SENT:
net/vmw_vsock/af_vsock.c:vsock_shutdown() {
...
} else {
sock->state = SS_DISCONNECTING;
err = 0;
}
...
}
Suppose a blocking connect() then times out, gets a signal or sees
sk_err. vsock_connect_close() sets TCP_CLOSE but leaves SS_DISCONNECTING.
Later connect() calls hit case SS_DISCONNECTING and return -EINVAL, and
vsock_listen() returns -EINVAL because sock->state != SS_UNCONNECTED.
Before this patch the socket went back to SS_UNCONNECTED.
The non-blocking path was not converted. vsock_connect_timeout() still
resets the state unconditionally:
if (sk->sk_state == TCP_SYN_SENT &&
(sk->sk_shutdown != SHUTDOWN_MASK)) {
sk->sk_state = TCP_CLOSE;
sk->sk_socket->state = SS_UNCONNECTED;
After shutdown(SHUT_RD) or shutdown(SHUT_WR), that path still moves
SS_DISCONNECTING to SS_UNCONNECTED, so the socket can be connected
again.
So the same sequence of events now leaves a different end state
depending on O_NONBLOCK. Should vsock_connect_timeout() follow the same
rule, and should the commit message mention the change?
> +}
> +
> static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> int addr_len, int flags)
> {
> @@ -1862,8 +1877,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().
[Severity: Medium]
Can a stale waiter still roll back a newer connect() attempt here? The
new comment says "Undo only the state this connect() attempt set". The
checks only compare state values, though, and a newer attempt sets
exactly the same values.
A second blocking caller enters through the SS_CONNECTING branch
(-EALREADY) without setting any state, but it still runs this rollback
on timeout or signal:
Thread A Thread B
connect()
SS_CONNECTING, sleeps
connect()
-EALREADY path, sleeps
first attempt fails (RST)
sock_error() consumes sk_err
vsock_connect_close()
-> SS_UNCONNECTED
returns
wakes, sk_err == 0, sleeps again
connect() again
sk_state = TCP_SYN_SENT
transport->connect()
sock->state = SS_CONNECTING
old timeout expires or signal
vsock_connect_close()
-> TCP_CLOSE, SS_UNCONNECTED
vsock_transport_cancel_pkt()
-> purges A's REQUEST
Thread A then waits with TCP_CLOSE and sk_err == 0 until its own
timeout, and gets a spurious -ETIMEDOUT. A RESPONSE already in flight
gets an RST, because virtio_transport_recv_pkt() falls into its default
case. A third connect() can be aborted the same way by thread A's late
timeout.
This does not seem able to recreate the connected-table or
transport-release problem, because SS_CONNECTED is left alone. The v2
change still only closes the TCP_LISTEN variant of the stale-waiter
race.
Would a per-attempt generation counter checked in vsock_connect_close()
work here? Another option is to skip the rollback for waiters that came
in through the SS_CONNECTING/-EALREADY path.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-vsock-connect-close-v3-1-7a9abc4e3474%40meta.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 22:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 0:52 [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-12-01 0:58 ` netdev-bot+sinfo
2026-12-01 8:20 ` Stefano Garzarella
2026-12-01 22:17 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox