From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 178ABC7EE2D for ; Mon, 22 May 2023 19:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234249AbjEVTTL (ORCPT ); Mon, 22 May 2023 15:19:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbjEVTTG (ORCPT ); Mon, 22 May 2023 15:19:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2605918B for ; Mon, 22 May 2023 12:18:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B75BB627F5 for ; Mon, 22 May 2023 19:18:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7464C433EF; Mon, 22 May 2023 19:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1684783136; bh=M9RLjLDGeDfjFAwgBMSFL6aqMfP9RBJrOcfIZrfgzBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s9aSgQX6W1MbfvFku+vQ/nV8ZN2ju4UzOsnJTo5sgoBmiK+t6bFMHpXCQV1427/DZ P0rmKtahWcPBHQ6sEASQop99G233d+lXHQBcifH+AYeJrXrhhM5uqYN3rHeYwjTi5l wfnIKQDXimTnKlaRSv4ZRFBi04ef/n79P21EzRXg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhuang Shengen , Stefano Garzarella , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 123/203] vsock: avoid to close connected socket after the timeout Date: Mon, 22 May 2023 20:09:07 +0100 Message-Id: <20230522190358.379540682@linuxfoundation.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230522190354.935300867@linuxfoundation.org> References: <20230522190354.935300867@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zhuang Shengen [ Upstream commit 6d4486efe9c69626cab423456169e250a5cd3af5 ] When client and server establish a connection through vsock, the client send a request to the server to initiate the connection, then start a timer to wait for the server's response. When the server's RESPONSE message arrives, the timer also times out and exits. The server's RESPONSE message is processed first, and the connection is established. However, the client's timer also times out, the original processing logic of the client is to directly set the state of this vsock to CLOSE and return ETIMEDOUT. It will not notify the server when the port is released, causing the server port remain. when client's vsock_connect timeout,it should check sk state is ESTABLISHED or not. if sk state is ESTABLISHED, it means the connection is established, the client should not set the sk state to CLOSE Note: I encountered this issue on kernel-4.18, which can be fixed by this patch. Then I checked the latest code in the community and found similar issue. Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Signed-off-by: Zhuang Shengen Reviewed-by: Stefano Garzarella Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/af_vsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index dc36a46ce0e75..9a65a2f195853 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1415,7 +1415,7 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, vsock_transport_cancel_pkt(vsk); vsock_remove_connected(vsk); goto out_wait; - } else if (timeout == 0) { + } else if ((sk->sk_state != TCP_ESTABLISHED) && (timeout == 0)) { err = -ETIMEDOUT; sk->sk_state = TCP_CLOSE; sock->state = SS_UNCONNECTED; -- 2.39.2