From: Michal Luczaj <mhal@rbox.co>
To: netdev-bot+sashiko@kernel.org, bobbyeshleman@meta.com
Cc: sgarzare@redhat.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
skhan@linuxfoundation.org, stefanha@redhat.com, mst@redhat.com,
jasowangio@gmail.com, xuanzhuo@linux.alibaba.com,
eperezma@redhat.com, shuah@kernel.org, rdunlap@infradead.org,
donald.hunter@gmail.com, edumazet@kernel.org,
georgezhang@vmware.com, acking@vmware.com, dtor@vmware.com,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
sargun@sargun.me, jlinbox@meta.com, bobbyeshleman@gmail.com
Subject: Re: [PATCH net-next v6 1/8] vsock: only undo SS_CONNECTING when connect() fails
Date: Mon, 16 Nov 2026 00:11:50 +0100 [thread overview]
Message-ID: <35c21a88-9e0b-4238-8926-b97cef74e1c9@rbox.co> (raw)
In-Reply-To: <179471528724.2199510.7407342828719727367@kernel.org>
On 11/15/26 05:01, netdev-bot+sashiko@kernel.org wrote:
> [Severity: Low]
> Do vhost_vsock_reset_orphans() and vmci_transport_handle_detach() really
> reach connect() through the sk_err path described here?
The other (also fixed) path is signal/timeout, unrelated to sk_err.
> vhost_vsock_reset_orphans() in drivers/vhost/vsock.c writes:
>
> sk->sk_state = SS_UNCONNECTED;
> sk->sk_err = ECONNRESET;
>
> SS_UNCONNECTED is 1, which is the same value as TCP_ESTABLISHED. When
> vsock_connect() takes the lock again, this check runs first:
The sk_state assignment is wrong and it's getting fixed:
https://lore.kernel.org/netdev/20261112-transport-reset-state-fix-v1-1-5698375f52a9@rbox.co/
> [Severity: Low]
> Should the changelog also describe the same-transport case? This patch
> seems to close that one too.
It generally closes the issue of unexpected socket state transition.
> [Severity: Medium]
> Does the rest of vsock_connect() need to recognize SS_CONNECTED now?
>
> With this patch the failure paths can run on a socket whose
> sock->state is SS_CONNECTED. The wait loop and the signal/timeout
> branch still only treat TCP_ESTABLISHED and TCP_CLOSING as success:
>
> while (sk->sk_state != TCP_ESTABLISHED &&
> sk->sk_state != TCP_CLOSING && sk->sk_err == 0) {
>
> Suppose the handshake completes while connect() sleeps, and the
> socket is then moved to TCP_CLOSE with sk_err == 0. The loop keeps
> sleeping. vmci_transport_handle_detach() does that for an established
> socket, since it only sets sk_err in TCP_SYN_SENT. With virtio,
> virtio_vsock_reset_sock() sets ECONNRESET, but another thread can
> clear it with getsockopt(SO_ERROR) before connect() takes the lock
> again. connect() then waits for the whole connect_timeout, or until a
> signal arrives, and ends up in this branch.
>
> Here vsock_connect_close() now leaves the socket SS_CONNECTED, yet
> vsock_transport_cancel_pkt() is still called right after it. For
> virtio this reaches virtio_transport_purge_skbs(), which drops every
> skb queued for this vsk, not only the OP_REQUEST mentioned in the
> comment.
>
> If a concurrent sendmsg() queued OP_RW skbs while the socket was
> TCP_ESTABLISHED, virtio_transport_get_credit() already added them to
> vvs->bytes_unsent. Purging them without
> virtio_transport_consume_skb_sent() seems to leave bytes_unsent
> non-zero for good. SIOCOUTQ then reports stale data, and
> vsock_linger() waits out the full SO_LINGER time on close().
>
> The caller also gets -ETIMEDOUT or -EINTR for a socket that now
> reports SS_CONNECTED. If the error is -ERESTARTSYS, the restarted
> connect() fails with -EISCONN.
>
> The long wait and the vsock_transport_cancel_pkt() call predate this
> patch. But this patch is what decides that such a socket stays
> SS_CONNECTED, so the rest of vsock_connect() should probably agree
> with it. Should the loop also stop when sock->state is no longer
> SS_CONNECTING? And should an already connected socket skip
> vsock_transport_cancel_pkt() and return sock_error() (or 0) instead?
This patch is about keeping a bricked socket - safely bricked.
> [Severity: Low]
> Can this leave a socket that never connected stuck in SS_DISCONNECTING?
>
> Consider a blocking connect() racing with shutdown():
>
> Thread A Thread B
> vsock_connect()
> sock->state = SS_CONNECTING
> release_sock(sk)
> schedule_timeout()
> vsock_shutdown()
> sock->state = SS_DISCONNECTING;
> lock_sock(sk)
> timeout, signal or sk_err
> vsock_connect_close()
> sk_state = TCP_CLOSE
> sock->state stays SS_DISCONNECTING
>
> After this, every later connect() fails here:
>
> case SS_DISCONNECTING:
> err = -EINVAL;
> goto out;
IOW, after shutdown() races connect(), socket cannot be used to re-connect
(or become a listener). I'm not sure if that's an issue.
next prev parent reply other threads:[~2026-11-15 23:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 3:14 [PATCH net-next v6 0/8] vsock: assign the guest vsock device to a network namespace Bobby Eshleman
2026-11-14 3:14 ` [PATCH net-next v6 1/8] vsock: only undo SS_CONNECTING when connect() fails Bobby Eshleman
2026-11-15 4:01 ` netdev-bot+sashiko
2026-11-15 23:11 ` Michal Luczaj [this message]
2026-11-15 23:10 ` Michal Luczaj
2026-11-14 3:14 ` [PATCH net-next v6 2/8] vsock: constify the transport in vsock_for_each_connected_socket() Bobby Eshleman
2026-11-14 3:14 ` [PATCH net-next v6 3/8] vsock: rename the vsock pernet operations Bobby Eshleman
2026-11-14 3:14 ` [PATCH net-next v6 4/8] vsock: pass the netns to ->has_remote_cid() Bobby Eshleman
2026-11-14 3:14 ` [PATCH net-next v6 5/8] vsock: add a netlink command to assign the g2h device to a netns Bobby Eshleman
2026-11-15 4:01 ` netdev-bot+sashiko
2026-11-15 22:31 ` Bobby Eshleman
2026-11-14 3:14 ` [PATCH net-next v6 6/8] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-11-15 4:01 ` netdev-bot+sashiko
2026-11-14 3:14 ` [PATCH net-next v6 7/8] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-11-15 4:01 ` netdev-bot+sashiko
2026-11-14 3:14 ` [PATCH net-next v6 8/8] selftests/vsock: test the netns assign privilege checks Bobby Eshleman
2026-11-15 4:01 ` netdev-bot+sashiko
2026-11-14 3:22 ` [PATCH net-next v6 0/8] vsock: assign the guest vsock device to a network namespace netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=35c21a88-9e0b-4238-8926-b97cef74e1c9@rbox.co \
--to=mhal@rbox.co \
--cc=acking@vmware.com \
--cc=bobbyeshleman@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dtor@vmware.com \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=georgezhang@vmware.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=jlinbox@meta.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=sargun@sargun.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®