From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C124426A0AF; Tue, 8 Apr 2025 12:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115217; cv=none; b=BI1STmvLf9kjIST+vPlT4Jz8/cj7W1uAz0XQ1c+OUvVizR/6oUNhDhLwrIVg2JnPwVF9cEPASOL9THsL9Ghcjf5kTVLBa6aHkTKgdImBRbj/zLAKuc67TR9f4HSeoEXuThG9zvUx4UKzlgMLR0KVBDGzk9ctyTG+A3ZXQOtwQPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115217; c=relaxed/simple; bh=ruGCkA/C2pKT+5S2GpiFVK4CP7VyLZVPKFnH+w9xtF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ntvXB8TDX/EX/LdMhieUjBY5FJEyEzyN+JhvDAojR9cA8VQToX9j2ADKsxtc85V7oTDb+SwJg2Sfrtdo2V6AA5GU6pgp8MzYXrbRNVvavxCdRKuFLvOQ0qlxBHAvUQexS1oa1WlXwL5tY/XxnOZP1M6qWHi76txh960PZFneIhU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lP9ZgVNw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lP9ZgVNw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E06FBC4CEEC; Tue, 8 Apr 2025 12:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744115217; bh=ruGCkA/C2pKT+5S2GpiFVK4CP7VyLZVPKFnH+w9xtF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lP9ZgVNwk2ExHni6QVjmv/tCr4B0wWMvkfg3xJyMFdQ2JkH10rTTMgCGFvtYFDCXq vE30LlA6ESrF1ukHi63ZuEnaiAbHXaK4G3x4ZB/F2WCNPpExKMhRnwm/aWX+kIzO6/ A63NyD1Eqwd48mqlYftuPFui1XS/K+jVb8DNCYbc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Luigi Leonardi , Stefano Garzarella , Paolo Abeni , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.13 394/499] vsock: avoid timeout during connect() if the socket is closing Date: Tue, 8 Apr 2025 12:50:06 +0200 Message-ID: <20250408104901.055440632@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104851.256868745@linuxfoundation.org> References: <20250408104851.256868745@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stefano Garzarella [ Upstream commit fccd2b711d9628c7ce0111d5e4938652101ee30a ] When a peer attempts to establish a connection, vsock_connect() contains a loop that waits for the state to be TCP_ESTABLISHED. However, the other peer can be fast enough to accept the connection and close it immediately, thus moving the state to TCP_CLOSING. When this happens, the peer in the vsock_connect() is properly woken up, but since the state is not TCP_ESTABLISHED, it goes back to sleep until the timeout expires, returning -ETIMEDOUT. If the socket state is TCP_CLOSING, waiting for the timeout is pointless. vsock_connect() can return immediately without errors or delay since the connection actually happened. The socket will be in a closing state, but this is not an issue, and subsequent calls will fail as expected. We discovered this issue while developing a test that accepts and immediately closes connections to stress the transport switch between two connect() calls, where the first one was interrupted by a signal (see Closes link). Reported-by: Luigi Leonardi Closes: https://lore.kernel.org/virtualization/bq6hxrolno2vmtqwcvb5bljfpb7mvwb3kohrvaed6auz5vxrfv@ijmd2f3grobn/ Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Signed-off-by: Stefano Garzarella Acked-by: Paolo Abeni Tested-by: Luigi Leonardi Reviewed-by: Luigi Leonardi Link: https://patch.msgid.link/20250328141528.420719-1-sgarzare@redhat.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/vmw_vsock/af_vsock.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 7e3db87ae4333..fc6afbc8d6806 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1551,7 +1551,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, timeout = vsk->connect_timeout; prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); - while (sk->sk_state != TCP_ESTABLISHED && sk->sk_err == 0) { + /* If the socket is already closing or it is in an error state, there + * is no point in waiting. + */ + while (sk->sk_state != TCP_ESTABLISHED && + sk->sk_state != TCP_CLOSING && sk->sk_err == 0) { if (flags & O_NONBLOCK) { /* If we're not going to block, we schedule a timeout * function to generate a timeout on the connection -- 2.39.5