From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.153.30 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796085647; b=JpFKWRQuHF2O6hFQ47dnpe6e5laMgqmP9Jl103D77/PU0xO1y/zCePS/Z3WpMQK3mW4v +UZhmfqNVYPlxj5YPSK2OYj5OlC1XglJFf4uqAfbO/IjofTwEfUR5lL7dZQUmpbf0Ih+N TN121ZZmNsnLdcKBX++xeNtcA88zlkW9Eoj0GbG/ZwT0b+GJbVR2s9viScIf+JzTe26pE QphXtgB5X7aQhqlU4YW046SEmzvuYJ0aAEAAIZ6H8j26yfu3Ufy/V96iWT0espM+UtWS7 qE5juW4YbRgt7Uv6QFaJV9XE0pHEAxby+6EngC04IPT8AFv0Kd4pZ65ZGfvRGUiogcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796085647; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Date:From:To: CC:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Originating-IP:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Virus-Version; bh=FaSrp9iVC0bXiM7YjhWitE4CeujQ1hpoHERhAA4E8BU=; b=P7iOPIokIpaKWddNeW3JvRoYHgXWqne404W6xJa7B7mQrNFmzMe/xyY8wqOHP3aDAJGP P1JPGt8tsG/n/R1eawnrSoT03M5Z412lCh7/D7ewp/I4jo1vwXnvUovV3lr2TixoPQ8Dc /3pW5sODAY8B/WdhatUWDI/WPRW1Qm+HgU2noA9PCSCrUuHEsLJPCFCBRg/oO4mhUSfCQ BUjs3kHsbdCSz1yJgjyfPfbXJW99XRTxYbiHFY0ibQ0MCqkh4dDOrB/X/RbnPRhJPohU4 HNoeJWYmmPesmmyg4eHCekacZ6+WPusCF2qdVZhxBzSuP7L4ctbtuZMTKF2kx3LbanA== 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=LBuqq5IG; arc=none smtp.remote-ip=67.231.153.30 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (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 CAC9C606A31A; Tue, 1 Dec 2026 00:40:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CAC9C606A31A 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=LBuqq5IG Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKVb5A1362807; Mon, 30 Nov 2026 16:40:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=pps82601-s2048-2026-q3; bh=FaSrp9iVC0b XiM7YjhWitE4CeujQ1hpoHERhAA4E8BU=; b=LBuqq5IGuTsTre6ppURYjvWE2aV 5HC0OJi2BIiTRHnuaWXnrNga1O1dLYfGxUig/ZwyX+CBS7QMTyZiXxunFECmrclH zASb7K1+eXO2Ac1kdN4dm8k9gWPjaRKEk6rfJMfPjOg4tQSwYCwu00jiAd9mlqAo iecpbeVEstxlLiHakT9QNDuhq5O0vXZAhm7B5nz40qR0DwE6DmQK0J4xhToqP2Pp HK8bQvdW3IMWKOLQqRwxLEoKieY85SJkw+qZSz/V6sBItKI5yshpOGb1qsK7MiG/ SwGFv+fK4sHKXxc/1ftEbM+SCj4UVCcF4AEwcqOYUPch7iSir3glY6WlfXg== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4j7wnbpda2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 30 Nov 2026 16:40:34 -0800 (PST) Received: from localhost (2620:10d:c085:208::7cb7) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) 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 00:40:33 +0000 Date: Mon, 30 Nov 2026 16:40:32 -0800 From: Bobby Eshleman To: Stefano Garzarella CC: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , George Zhang , Andy King , Dmitry Torokhov , , , , Kyle Zeng , Michal Luczaj Subject: Re: [PATCH net v2] vsock: only undo SS_CONNECTING when connect() fails Message-ID: References: <20261117-vsock-connect-close-v2-1-db5388323770@meta.com> X-Mailing-List: linux-kernel@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="us-ascii" Content-Disposition: inline In-Reply-To: X-Proofpoint-GUID: uPJFxtjKd-vTSOLGsN1mc1HW_I3mSmwa X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAwMSBTYWx0ZWRfX5CiK6tAgrXf6 SZjB42xXOiuV7z8mr/g/HilVwlx/eNRfp+eqm2+DMtJnzIxdX1K2gV4PhWavnTFMCa/apzP3pUn iKjhCTz/5TvlNiMRVg4Y1JyqDpBq2ov/noIXn+PTOusydvNRKNfsyoF5tf91Yxev7BtvfkUbYDQ V+UQLH4VELh/5pdiYfl48wM/Xwep05co5EwMfeeeAohqZsqRWitofzlYKMSlKoGIL9/1AC7DIiJ QA88dM3Wwi+l6l/pCs2DazgC/N/DvyeY11AsB7HQNAj2+GEs2Iu3vDf0rSwwZBkotXkms6c29OX i0xmpazMSMdvtwO8H7vT0LS4uEdPiwsyk0a3FmA7kxOGbxf5aaF1PCw7WHUdKkHhwFMwBTwotxX hUbxs6TMDhy072JPXmjmPjQw6ic4SjtS9LD1Hi8QEUVGSb9Kc/DhAXRKNtpDb/aQbXpKASEMi8A IhlRoixEBD2EihrEeXg== X-Proofpoint-ORIG-GUID: uPJFxtjKd-vTSOLGsN1mc1HW_I3mSmwa X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAwMSBTYWx0ZWRfX9gpiWtbq+2Tl B8uCF+ACnIzEIdsaaG1mS0hAvjtVnuhMJ9RNvdLs8VNg8CYiBmw2OzqxmJeUfc1/vQELace0hEn cx8IpRtEGQJpOTqwxnN9hHV2qcB36MY= X-Authority-Analysis: v=2.4 cv=ct0OAF4i c=1 sm=1 tr=0 ts=6b0e1782 cx=c_pps a=CB4LiSf2rd0gKozIdrpkBw==:117 a=CB4LiSf2rd0gKozIdrpkBw==:17 a=kj9zAlcOel0A:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=wpfVPzegXHpEFt3DAXn9:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8 a=LG5T7v2SAAAA:8 a=MuRgy9yfNUNJtl-xkKQA:9 a=CjuIK1q_8ugA:10 a=gKebqoRLp9LExxC7YDUY:22 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-11-30_05,2026-11-30_01,2025-10-01_01 On Thu, Nov 26, 2026 at 10:25:41AM +0100, Stefano Garzarella wrote: > On Tue, Nov 17, 2026 at 05:34:09PM -0800, Bobby Eshleman wrote: > > 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. > > > > Only move the socket back to SS_UNCONNECTED if it is still > > SS_CONNECTING. A socket that got connected stays SS_CONNECTED, and > > another connect() fails with -EISCONN. > > > > Likewise, only move sk_state to TCP_CLOSE if it is still TCP_SYN_SENT. > > Otherwise a second thread blocked in connect() on the same socket can > > time out after the first one failed and called listen(), and overwrite > > TCP_LISTEN. > > > > Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") > > Reported-by: Kyle Zeng > > Link: > > https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/ > > Suggested-by: Michal Luczaj > > Signed-off-by: Bobby Eshleman > > --- > > Changes in v2: > > - Only reset sk_state if it is still TCP_SYN_SENT, so a concurrent > > connect() caller that times out late doesn't overwrite TCP_LISTEN > > (Sashiko). > > - Drop Michal's Reviewed-by since the code changed. > > - Link to v1: https://lore.kernel.org/r/20261116-vsock-connect-close-v1-1-43fb125973dd@meta.com > > --- > > net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++------ > > 1 file changed, 16 insertions(+), 6 deletions(-) > > > > diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c > > index 1d7d53542724..ce958b48295b 100644 > > --- a/net/vmw_vsock/af_vsock.c > > +++ b/net/vmw_vsock/af_vsock.c > > @@ -1704,6 +1704,19 @@ static void vsock_connect_timeout(struct work_struct *work) > > sock_put(sk); > > } > > > > +/* Avoid breaking the socket when another thread has changed its state while > > + * we were asleep. > > + */ > > Should we make this comment a bit more clear to explain why we are doing > this? > > Something like this (IIUC, please check and correct it) > > /* 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. > */ > > The rest LGTM! > > Thanks, > Stefano Your wording is accurate, I'll just use it as is! Best, Bobby