Article View: linux.kernel.netdev
Article #25485Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 22:17
Date: Tue, 01 Dec 2026 22:17
209 lines
16016 bytes
16016 bytes
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
Technical Details
Message-ID:
<179616345017.3146.10416611062732420707@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375377-linux-kernel-netdev=dewy.ruReferences:
<20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375377-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Date: Tue, 01 Dec 2026 22:17:30 +0000 Organization: Usenet Network Message-ID: <179616345017.3146.10416611062732420707@kernel.org> References: <20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1830489"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:0Coonw3EvUzg9SOBiHHNAMIulao= sha256:0IJRgljz3jfedpPhsjv26R+uJhlwVagj1rvnJCY5C84= sha1:6xiYLZx8+iqgJNF6Apnkh7yyA9s= sha256:zDAHEAEdaCHI5i30LReWkvm9LsSXRt1krqtdAXnuSeA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id ECAE11174B9; Wed, 2 Dec 2026 01:17:52 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K85dOydk1cIU; Wed, 2 Dec 2026 01:17:49 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375377-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id BFE3411749B; Wed, 2 Dec 2026 01:17:40 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id C269F28C13; Tue, 1 Dec 2026 22:17:38 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796163457; b=ntEqb4pFTvhIqN9r6NUE4vUfqnhLXcV85B/ZV87GYUv88YxPtFCer+W+dCFzhZg8GH9t ajzH5pJnmvymbVkf804/sCR/gzZuNsJKOMD7aQMPU+T26E65PGEotZB37IrYAO7aOPJsf 7e0zvmxgR3Frbj+juJ3ia6f+R6NzlngJTTdJAT9wERbtyzgmE+SfE28wHQxOb/MN/AN9H jnj2ufIyt58Ji54V/hvtud1M7zblnu1danqultioTCT57sRjec9ewfLYmME5PMgYGmwWm ybJ9DwWwLPWcUJ3KajPBImB3namK2qiOLOA9Yiy5Qyyyo5nma1QudSfIr9SYL4rUanA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796163457; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=uPrBFYOsAyZXiYICReBEI3B0ymijnwliXL2HWE8W/iQ=; b=C8ZclJgk1wXpkaCpFlezOl2E6qX91SvTqqkGuFDjJaPC/PXUymcNetBOEnN88Zf0e945 GMnYM5I5qbyksPYAD5CkmbWTZ79Ykeh5dGNA7BZrIiSi906WNVdYt8YH87Fbm4GabvRhj LFifhpiA5qUgTIrV/Q621s4dSZqxShtMz/CE4ziJcPRQdw/CT4jNpx+KbfioG77mnA+OZ kAqb5p1bAg/2/8VIkk5WCsjwfahfrXwq4aCnsl+hiLHljsoS2rTuxFyKsNvLaP/lAlJFi LaFLTCuUzQH1lonHELb5y8nw3T7BU9/IoCaFTkSU8IUxhVxawu51LYkGt6wTpGlYchQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UVfOJbIs; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A79B4606A329; Tue, 1 Dec 2026 22:17:37 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UVfOJbIs X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796163451; b=F2WXbR3lMdX+q1vNbsxWa4x8bd57vr8L6OOQiyCK0EnoBC97QJjzbhT5RSd0OdjnrBFp cG99cQ47/ur6+6VIa1FB1vXaDR8GdnETXDo+cAI1dfRzQID8r/TpzQFlVd02GmiKv9CAH nBXsMbEC0UCtTQu8dZfuzF9Ghvva/ZPjC3qOz3lIwyUPO5oMk1MaSat5QPsbExYh39dX8 y+xjPVRCdaT8OlCweFCvdvHbBMuXs/GS3DROTjuCrWpS9Md8pfyoRDcpU0U4uVVQfFRiY 4aDQttnJ7/JX84lr9d0QVKsC0Sdm9O8kH5ik7BilcUckQRpQdCrVPJc/dh9v6cAZIeg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796163451; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=uPrBFYOsAyZXiYICReBEI3B0ymijnwliXL2HWE8W/iQ=; b=HuwnbUg9+kKXoJYclPcer1Ez3pm42+lF8g045alaS0SOJr5sQ3T812eV9J8EwootbYte GiIUq1dPleDsz8FkndYQ6/izjIXSaJrNLHNCCMRThai2iGXnk02swQsCtiBUT+8rwJpF7 KUOtbzdLCsmijrJF6HpIrqWppq2NtuRFMu8ZrrzEyduAyUxbJlth4BjHwlgP2DeKIaFJ9 /ARkccS0Ymcfp4SKJDfh5QJG2ztdXW+yY3yi0P9mN35dJUO+BartdrI+3bymkDHLfva27 317XWPOaoZyQy6HFlRnfeZXnCPxm2z659V1I30EzP/HaYvkVS7swAw89bZRzaJy4Xaw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UVfOJbIs; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6263606A31A; Tue, 1 Dec 2026 22:17:31 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F49C1F000C1; Tue, 1 Dec 2026 22:17:30 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796163451; bh=uPrBFYOsAyZXiYICReBEI3B0ymijnwliXL2HWE8W/iQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=UVfOJbIsH5lZ10jva3ipQW1ZxavVHlDrDLKN+h59DLGZCKNEjOIiQC801JzsqLKZs 2034dIVUTXlBmqcPQMDEclvu9h2A/MtqdaClwRpxVom2lUId28kloVK4vq2bm5rvsy 9N8LyzMjLnQESbueBW4w+Qt7AZRCsnf5/GVc//exg45bsFS92ClrYMUMs85Rjje9In GqWfe/2wlDAGa6bRNKOaD4hAUNl9YpXn4qs2Sue+DAw8yGPbzDSqDngtqsJS9QG9Ub h+dcb8QBM7VYciNdGvmg5mAIx36smE1ikyhMVPsh7WlMMHqEa1fAZjtRZasWRbPbmK AuDex4J3urqWA== X-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 X-In-Reply-To: <20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 15830