* [PATCH net] vhost/vsock: Fix socket state constant
@ 2026-11-12 10:34 Michal Luczaj
2026-11-12 10:36 ` netdev-bot+sinfo
2026-11-16 10:35 ` netdev-bot+sashiko
0 siblings, 2 replies; 5+ messages in thread
From: Michal Luczaj @ 2026-11-12 10:34 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
David S. Miller
Cc: kvm, virtualization, netdev, linux-kernel, Michal Luczaj
Refactor under Fixes missed one: SS_UNCONNECTED (1) -> TCP_CLOSE (7).
Until now, sk->sk_state = 1 stood for TCP_ESTABLISHED.
Fixes: 3b4477d2dcf2 ("VSOCK: use TCP state constants for sk_state")
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
Salvaging a single already-reviewed patch from a series[1] that was
superseded.
[1]: https://lore.kernel.org/all/20260922-vsock-connect-reset-closing-v3-0-78907b8200d4@rbox.co/
---
drivers/vhost/vsock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 88a310390eb0..fd224f7681d9 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -789,7 +789,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
sock_set_flag(sk, SOCK_DONE);
vsk->peer_shutdown = SHUTDOWN_MASK;
- sk->sk_state = SS_UNCONNECTED;
+ sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET;
sk_error_report(sk);
}
---
base-commit: 145480b28ca82e9fae789427cc4569e596515a32
change-id: 20261112-transport-reset-state-fix-42363b46d2a7
Best regards,
--
Michal Luczaj <mhal@rbox.co>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] vhost/vsock: Fix socket state constant
2026-11-12 10:34 [PATCH net] vhost/vsock: Fix socket state constant Michal Luczaj
@ 2026-11-12 10:36 ` netdev-bot+sinfo
2026-11-12 10:52 ` Michal Luczaj
2026-11-16 10:35 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-12 10:36 UTC (permalink / raw)
To: Michal Luczaj
Cc: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
David S. Miller, kvm, virtualization, netdev, linux-kernel
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. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
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] 5+ messages in thread
* Re: [PATCH net] vhost/vsock: Fix socket state constant
2026-11-12 10:36 ` netdev-bot+sinfo
@ 2026-11-12 10:52 ` Michal Luczaj
2026-11-13 8:44 ` Michal Luczaj
0 siblings, 1 reply; 5+ messages in thread
From: Michal Luczaj @ 2026-11-12 10:52 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
David S. Miller, kvm, virtualization, netdev, linux-kernel
On 11/12/26 11:36, netdev-bot+sinfo@kernel.org wrote:
> - How the issue was discovered, e.g. hit in production, hit during
> development, syzbot report, manual code inspection, LLM or static
> analysis tool scan.
Discovered by reading the code and not getting it.
> - 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.
Not triggered at runtime. It's a correctness fix, I didn't try to work out
what could/would actually go wrong.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] vhost/vsock: Fix socket state constant
2026-11-12 10:52 ` Michal Luczaj
@ 2026-11-13 8:44 ` Michal Luczaj
0 siblings, 0 replies; 5+ messages in thread
From: Michal Luczaj @ 2026-11-13 8:44 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
David S. Miller, kvm, virtualization, netdev, linux-kernel
>> - 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.
>
> Not triggered at runtime. It's a correctness fix, I didn't try to work out
> what could/would actually go wrong.
I don't see any way this could really affect the kernel. Will re-post to
net-next along with some other cleanups. Sorry for the noise.
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] vhost/vsock: Fix socket state constant
2026-11-12 10:34 [PATCH net] vhost/vsock: Fix socket state constant Michal Luczaj
2026-11-12 10:36 ` netdev-bot+sinfo
@ 2026-11-16 10:35 ` netdev-bot+sashiko
1 sibling, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 10:35 UTC (permalink / raw)
To: mhal
Cc: stefanha, sgarzare, bobbyeshleman, mst, jasowangio, eperezma,
davem, kvm, virtualization, netdev, linux-kernel, kuba
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 0
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).
- [High] Writing TCP_CLOSE plus sk_err = ECONNRESET in
vhost_vsock_reset_orphans() (drivers/vhost/vsock.c:792-793) brings…
- [Medium] vhost_vsock_reset_orphans() now moves every orphaned connected
socket to TCP_CLOSE unconditionally, after setting SOCK_DONE, even…
--
vhost/vsock: Fix socket state constant
This patch replaces SS_UNCONNECTED with TCP_CLOSE in
vhost_vsock_reset_orphans(). SS_UNCONNECTED has the value 1, which is the
same as TCP_ESTABLISHED. So far, orphaned sockets have been left in the
established state after the vhost device was released.
> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 88a310390eb0a..fd224f7681d92 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -789,7 +789,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
>
> sock_set_flag(sk, SOCK_DONE);
> vsk->peer_shutdown = SHUTDOWN_MASK;
> - sk->sk_state = SS_UNCONNECTED;
> + sk->sk_state = TCP_CLOSE;
[Severity: High]
Can this let connect() reset a socket that is still linked in
vsock_connected_table? Commit 4f6ac74fa594 ("vsock: treat TCP_CLOSING as
once-established") fixed that problem for the other close paths.
vhost_vsock_reset_orphans() runs without lock_sock(). Suppose it runs
after virtio_transport_recv_connecting() has handled a RESPONSE, but
before the waiter in vsock_connect() gets the socket lock back:
vhost TX worker
virtio_transport_recv_connecting()
sk->sk_state = TCP_ESTABLISHED;
sk->sk_socket->state = SS_CONNECTED;
vsock_insert_connected(vsk);
vhost_vsock_dev_release()
vhost_vsock_reset_orphans()
sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET;
The waiter then fails the TCP_ESTABLISHED/TCP_CLOSING check and ends up
here:
net/vmw_vsock/af_vsock.c:vsock_connect() {
...
err = sock_error(sk);
if (err) {
sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED;
}
...
}
connect() returns -ECONNRESET, but the socket is still in the connected
table. With the old value (1 == TCP_ESTABLISHED), connect() returned 0 and
the socket stayed SS_CONNECTED.
After that, ordinary API calls seem to be enough to insert the socket a
second time:
1. A second connect(): sock->state is SS_UNCONNECTED, so it does not get
-EISCONN. vsock_assign_transport() returns early because the transport
is the same. That skips both vsock_remove_sock() and
sock_reset_flag(sk, SOCK_DONE).
2. shutdown() while the socket is SS_CONNECTING: vsock_shutdown() calls
sock_reset_flag(sk, SOCK_DONE). Without that flag,
virtio_transport_recv_pkt() no longer drops the incoming RESPONSE.
3. A RESPONSE from a guest with that CID reaches
virtio_transport_recv_connecting() in TCP_SYN_SENT. It calls
vsock_insert_connected() a second time.
__vsock_insert_connected() then does an unconditional sock_hold() and
list_add() on a node that is already linked, which corrupts the bucket.
Any later walk of that bucket under vsock_table_lock can then loop forever,
for example in vsock_find_connected_socket() or
vsock_for_each_connected_socket(). With CONFIG_DEBUG_LIST it hits the
list_add double add BUG instead. One socket reference is also leaked.
Only the first step depends on timing, a race with VM teardown. The rest
is normal use of the socket API.
> + sk->sk_state = TCP_CLOSE;
[Severity: Medium]
Does this drop data that is still queued in the socket's rx_queue?
vhost_vsock_reset_orphans() now sets SOCK_DONE and then moves the socket
to TCP_CLOSE unconditionally. __vsock_connectible_recvmsg() then returns
early without dequeuing anything:
net/vmw_vsock/af_vsock.c:__vsock_connectible_recvmsg() {
...
if (!transport || sk->sk_state != TCP_ESTABLISHED) {
...
if (sock_flag(sk, SOCK_DONE))
err = 0;
else
err = -ENOTCONN;
goto out;
}
...
}
So recv() returns 0 (EOF), and sk_err is not reported there.
The other close paths only leave the readable state when no data is
pending:
net/vmw_vsock/virtio_transport_common.c:virtio_transport_do_close() {
...
if (vsock_stream_has_data(vsk) <= 0)
sk->sk_state = TCP_CLOSING;
...
}
hvs_do_close_lock_held() in hyperv_transport.c has the same check.
vmci_transport_handle_detach() skips the check only on the host side,
where queue-pair data can't be read once the VM detaches. With vhost, the
data is still in host-kernel skbs and can be read.
One way to hit this:
1. The guest writes data and sends SHUTDOWN.
virtio_transport_recv_connected() keeps the socket TCP_ESTABLISHED
because data is pending.
2. The VM exits, or the VMM closes the vhost fd.
vhost_vsock_dev_release() calls vhost_vsock_reset_orphans().
3. The host application's next recv() returns 0, and the end of the
stream is lost.
With the old value the socket stayed TCP_ESTABLISHED, so the application
could read the remaining data before seeing EOF.
On the guest side, virtio_vsock_reset_sock() also sets TCP_CLOSE
unconditionally on a transport reset, so this may be the intended reset
behaviour. It is still different from the RST path, which keeps queued
data readable.
Should vhost_vsock_reset_orphans() check vsock_stream_has_data() the way
the other transports do?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-transport-reset-state-fix-v1-1-5698375f52a9%40rbox.co
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 10:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 10:34 [PATCH net] vhost/vsock: Fix socket state constant Michal Luczaj
2026-11-12 10:36 ` netdev-bot+sinfo
2026-11-12 10:52 ` Michal Luczaj
2026-11-13 8:44 ` Michal Luczaj
2026-11-16 10:35 ` 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