From: Bobby Eshleman <bobbyeshleman@meta.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <sgarzare@redhat.com>, <davem@davemloft.net>,
<edumazet@kernel.org>, <kuba@kernel.org>, <pabeni@redhat.com>,
<horms@kernel.org>, <georgezhang@vmware.com>, <acking@vmware.com>,
<dtor@vmware.com>, <willemb@google.com>,
<virtualization@lists.linux.dev>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <kylebot@openai.com>,
<mhal@rbox.co>
Subject: Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails
Date: Tue, 1 Dec 2026 14:55:28 -0800 [thread overview]
Message-ID: <aw9QYO/sBSTyZvoW@devvm29614.prn0.facebook.com> (raw)
In-Reply-To: <179616345017.3146.10416611062732420707@kernel.org>
On Tue, Dec 01, 2026 at 10:17:30PM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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 behavior exists before this patch, the only difference being that
prior to this patch the TCP_CLOSE/SS_UNCONNECTED writes are
unconditional. With this patch, they still happen because the new
conditions are met... but its not new.
Additionally, the outcome for Thread A's second connect's REQUEST
getting eaten is just that it times out again. IMHO this is fine.
I don't think the Low severity issues are worth respinning this either...
The non-blocking vs blocking issue is the same thing as we discussed
prior WRT vsock_connect_timeout(), i.e., there is work to be done but
not in this patch.
Best,
Bobby
prev parent reply other threads:[~2026-12-01 22:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 1:12 ` sashiko-bot
2026-12-01 8:20 ` Stefano Garzarella
2026-12-01 22:17 ` netdev-bot+sashiko
2026-12-01 22:55 ` Bobby Eshleman [this message]
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=aw9QYO/sBSTyZvoW@devvm29614.prn0.facebook.com \
--to=bobbyeshleman@meta.com \
--cc=acking@vmware.com \
--cc=davem@davemloft.net \
--cc=dtor@vmware.com \
--cc=edumazet@kernel.org \
--cc=georgezhang@vmware.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kylebot@openai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=willemb@google.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 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.