Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7415489rwr; Wed, 10 May 2023 08:01:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MSE/sbZE9dsUE+Ye23Cr6sIOra0apBYHFRLRZ3KPGl4RWmXado0pfYRyB180ieL3MYl9v X-Received: by 2002:a05:6830:39f1:b0:6ab:fde:96cb with SMTP id bt49-20020a05683039f100b006ab0fde96cbmr3242237otb.1.1683730888770; Wed, 10 May 2023 08:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683730888; cv=none; d=google.com; s=arc-20160816; b=d6X5qct90xHHDcoESVKMGVDOsgb3o+B8RCsYIhamN3SMLrX3LTQtH3MGibpxToS3rP jN2bbOY2VLLSgzH0QYQ3zUtLMMYL6DXxSX/kwd6+RlTimPcneEpUktpqUHwzKXiOOMY3 wpXLEaYBFSIvv/DeqNVf6izyg+YlLeD+EJCNvSrxukC+ej9VuRVdu6vQbXn7u3Nezq60 Ud+i2ozgSvn5/9AfoaGlvFzbX6cEGmHnwFumNokbxK1vRxFjexX8ht5d8ZdcIaLTMagc znlgB6V7jAni6qrnZc2zAJo9JEaIWHOpR3O/PpClpOO09DcW+Z2skzaXF8t7nKDarzXs DBEA== 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=ycscANJNAjSDfrRTgCa6xibl5zmnR9OZmHrsdFDvOgM=; b=WzTI89bUU45uHNGJpKTJxN30m/2KgpBKIJjh34am16TZkU9k+92G7e+PHe57wUzL1G wJ31nQMn+5krtOmUwXvCpASjlzzAk/L3BWoobXIPryO+8U6QSACSDGRHokaNapUAmPhU k21Tf1EVT1onGXt/+q2Owz1CmQmm/fZNPcp0YMlIGsn7AdW8+42c3L/Trkn4hXaYNoSK jizJhLn/12eGWzVxl2COmiDx0akSRIYkUzyJX9LBpWAiAkG0JcDdG9t5Zio/D7IfZbFY ZHi6pqwjyUBunq8d782mJoV1BE1dSnkgO5F8CJU/9G5+WrMI/eA7cCtG5+seyfgZBMHS m2GQ== 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 x63-20020a9d37c5000000b006ab1be5781asi2066509otb.185.2023.05.10.08.00.59; Wed, 10 May 2023 08:01:28 -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 S237598AbjEJOr5 (ORCPT + 99 others); Wed, 10 May 2023 10:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237592AbjEJOr4 (ORCPT ); Wed, 10 May 2023 10:47:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B678CE7E; Wed, 10 May 2023 07:47:53 -0700 (PDT) Received: from dggpemm100003.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QGchT74PCzsRGV; Wed, 10 May 2023 22:23:37 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm100003.china.huawei.com (7.185.36.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 10 May 2023 22:25:30 +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; Wed, 10 May 2023 22:25:30 +0800 From: Zhuang Shengen To: CC: , , , , , , Subject: [PATCH] vsock: bugfix port residue in server Date: Wed, 10 May 2023 22:25:02 +0800 Message-ID: <20230510142502.2293109-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: dggems706-chm.china.huawei.com (10.3.19.183) 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, User will release the port. 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. 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