From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UVfOJbIs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F49C1F000C1; Tue, 1 Dec 2026 22:17:30 +0000 (UTC) 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== Subject: Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails From: netdev-bot+sashiko@kernel.org To: bobbyeshleman@meta.com 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 Date: Tue, 01 Dec 2026 22:17:30 +0000 Message-ID: <179616345017.3146.10416611062732420707@kernel.org> In-Reply-To: <20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com> References: <20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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