Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8697678rwr; Thu, 11 May 2023 05:12:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ATyHgZUYDuoj64qD9bA5uyifFouVCRbW8e+jCaEv7owk7NkLXlhlsVhdSzQaOaw2BReNp X-Received: by 2002:a17:902:ec8a:b0:1aa:f3c4:7582 with SMTP id x10-20020a170902ec8a00b001aaf3c47582mr29396683plg.31.1683807129975; Thu, 11 May 2023 05:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683807129; cv=none; d=google.com; s=arc-20160816; b=NNLJf6z0otAsjIjWBKBQIWav2PpD3sKPvObefaAZtpffJj+gQjZLPzy3hKezyTUzfv 2ySoJh5xBnVXoiKqobpe8kyPFX5ppsVBCFmT/5ozzIuSTLTYjmpMQlNE0JV7vCSx5Bdk ktTfS9YpUXK6hIE4gDy9Q5eYeygSta6BdK4kro7575TmHp9SkLnODYvmZ3MsXdQR3CMB JqkDywGYN005QaQB/+f4mcs1V3/ajlbwFfG5kgV1JZXhYCpilDpcM64Zoc2PKwrO109k xSrouFAQ/qsC0JuPcjxHMZZa0P+ijucy2Ps1bKypmUl140wCep49h6kGApXxg91FMW18 rZKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=pSVTPKFHYMep3AzzV5t5M4H8IVMYLNr+wiyS0T/0P78=; b=VDVw/rkTxTpPFsTR5yvJfznoOslxQd9MYU0OwN+MlhJd8eNIwrlKkCSv75lAPJRxLb 960MBzMTdBUkhL3MZO6knfL6gXNnFm4mI8XUxvGF/cMa5Y5lO/maGYDu4RZzhoZ6fyc6 2UZ+QRdiUIMZpLBMOXY8jqaWsQCtYp075mUpUab5HGfcA2D+42O4aqrobQU7SNILaxBd aUEWwua/cmnLDFu1VBiZ+qCdn4rxMPdeH4X3y7invNK+YcSPXIUSEZaMgJD+yRvuMJf0 RCVJNTIoDdvdiXosNrxTsiIkWMCudmwGSIvxS2PiVNoswp2kPkc5usNuLKcWguXPp2UF MHZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a170902b59400b001ac815f653asi6197070pls.348.2023.05.11.05.11.55; Thu, 11 May 2023 05:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237639AbjEKLfL (ORCPT + 99 others); Thu, 11 May 2023 07:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237825AbjEKLfD (ORCPT ); Thu, 11 May 2023 07:35:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D26627698; Thu, 11 May 2023 04:34:58 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QH8pW56fhzpSwF; Thu, 11 May 2023 19:30:43 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 19:34:56 +0800 Received: from huawei.com (10.175.104.170) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 19:34:56 +0800 From: Zhuang Shengen To: CC: , , , , , , , Subject: [PATCH net v2] vsock: avoid to close connected socket after the timeout Date: Thu, 11 May 2023 19:34:30 +0800 Message-ID: <20230511113430.646292-1-zhuangshengen@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 413407bb646c..efb8a0937a13 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1462,7 +1462,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.27.0