From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.145.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796165750; b=MpfC81gx0qbAMg29xxqZuTQOfVLQ4rSDUDnGYnc8U5OfSEtrPkjf9QtkD63vTwt+QJLT GVkjzAq8Dv0yyyCbDeTNdnV3+qUeMM1jniDwUso9gf8vPBijqdHXQlPTtPAdift+CqqPl WEifOJK3j4+Ux0Vg193FQxaSFzllgYu9+D/bbXzkS6n/Bz8CeIaEDKGbPb7Q8lQhofMH0 l2iuzn0/ZUdMIUqev5URG+DqxPL3iPlZG9utE58xaVKl+q8ZREgHDFib0bnSN31E+uYPH UIQ3qt5w3X2+MF2uYCxlhHimt+BhDTTDu0HZuiMzMUEMDC/IlvcW6VrtPg+BiY5DbFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796165750; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Date:From:To: CC:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: X-Originating-IP:X-Authority-Analysis:X-Proofpoint-Spam-Info: X-Proofpoint-GUID:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version; bh=eLFUIkZOoAOX8spgIthwo2dwpthagvnIuvIaKLE5ZcY=; b=yKvTHyRinhx1r7yZh1PF4esYaxtdHu45FbGU/r8Zr/IJsEZT7LMnlflVOoB9QzqKzCN+ m8FH0H9y//D5aQgFCj8u8unWSShVtRHenqjkpGRM7/UvOBbWFa72aDRNbvyUCIuxzRvh/ pvcVxrxe9pnhNH+GwaB1QM8CUrDGXQ2HLi9iptgTHamCYvWTfJnfG+hrTiS3RSxx1jvuW K6wblYuGM8zPMAxg+VqmSyMnUX6ePk7eVVjQmrikMcH3GLgao1bUYFikCQ+xg2Q5XcKHY hxAVagFUbhR0x2AUv1c8J3yH8bvIgShMtpm3eVP381SaFUlfqPWVwtmIVnunz7W8/4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=F9pkYPgM; arc=none smtp.remote-ip=67.231.145.42 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 F28EF606A31A; Tue, 1 Dec 2026 22:55:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F28EF606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=F9pkYPgM Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1J0kNn1710351; Tue, 1 Dec 2026 14:55:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= pps82601-s2048-2026-q3; bh=eLFUIkZOoAOX8spgIthwo2dwpthagvnIuvIaK LE5ZcY=; b=F9pkYPgMVTIVuALqC1ly4gtgUJ9wXRDkdZfO8g3esZXOaTkDnkEpn sRE4iajUqMXtPqb8WPDgayKkmRq+omwM2OMf9gxTvIhkfGS7N2R78d7DgU0M2Ik6 FRTeXs4x1pbMFEl5fTnaujdPoilZvqNm4kOeSJ+2YnwS3WllpDAH2RgL0sTFk5Ni JKlJaAgoGxY7GjZ1iFEXvwXUc3UUZw7p4Dv81aL6fYKbgt639pAGTywkefrjG4BF 1stftxYbnMoiZetxQWph2ointQWc8FpgRNPQTVEiZdMCjVB4AN7g0DpdwT8aF2/5 i7LXsYW7vloddFUOinmFH07lVKSOef4gQ== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4j9qxfpcaw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 01 Dec 2026 14:55:31 -0800 (PST) Received: from localhost (2620:10d:c0a8:1b::2d) by mail.thefacebook.com (2620:10d:c0a9:6f::237c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.56; Tue, 1 Dec 2026 22:55:30 +0000 Date: Tue, 1 Dec 2026 14:55:28 -0800 From: Bobby Eshleman To: CC: , , , , , , , , , , , , , , Subject: Re: [PATCH net v3] vsock: only undo SS_CONNECTING when connect() fails Message-ID: References: <20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com> <179616345017.3146.10416611062732420707@kernel.org> 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 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <179616345017.3146.10416611062732420707@kernel.org> X-Authority-Analysis: v=2.4 cv=M/HYuCws c=1 sm=1 tr=0 ts=6b0f5063 cx=c_pps a=MfjaFnPeirRr97d5FC5oHw==:117 a=MfjaFnPeirRr97d5FC5oHw==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=crHB47gyY4rKiduisYu9:22 a=VwQbUJbxAAAA:8 a=CMsG76WHQAODDutjcncA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA5MSBTYWx0ZWRfX13byQkEopeXz wPxU8snyjKCX9MuUrz8DvjBC3dkG3mJeXynvqHCsOhAnXia2hJvfTh9kx3ynEQytQx58PuAGdOo 4g5hVXyl5ZtLYgdaw2y4rKrkIiJgDZ0= X-Proofpoint-GUID: 2tP0Pww5cPjMMW3t-BdWHVTEu1OopFsv X-Proofpoint-ORIG-GUID: 2tP0Pww5cPjMMW3t-BdWHVTEu1OopFsv X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA5MSBTYWx0ZWRfX0AV8UXmprTFE ipAKbGEEENzQ+6B/i11MFXMfzr9De52gx5BU04gjybgUtFgejjCi4xOpPH1HauvsEcUH9QgEOq6 XQGjSYVjmhjwCoMMxkZphmxu6olOgNic3NDq+da1BNZVNC85IJ1hq2Rz/OLM1zxfjUtdXRq2h0F z24oBnB/kO7Y27iF06QucC2IwpF7cSlB2eDYTYSHjJZ8qkBjec6ecJZukOHL6SSMYCvmG3GPiez ptCjUli/2izE6JWOTrlzCfqeE0ewwuEYdeTH8ktI60qhYPF5Hg+viEJvgt6YjIQESiNrp+czXKp JDHWqOFIg2SdlSe7pSh0TyPon3F5bsq4uiWii8YJqFcHHjsquSTkvngin0V0NAuvGxTNMoxT4ZO 32SS2K7FAH9prQXgkjfY23deMBkPHJJD9vNyhFtD5x8IVjD1tuwL6ISU3/X6W8Xu2CyyY4bTMxY gg0w0A7u7sI0bv5MXJQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_04,2026-12-01_01,2025-10-01_01 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