From nobody Fri Sep 5 20:12:17 2025 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 B8B3EC32772 for ; Tue, 23 Aug 2022 11:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358758AbiHWLx5 (ORCPT ); Tue, 23 Aug 2022 07:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358731AbiHWLuo (ORCPT ); Tue, 23 Aug 2022 07:50:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E03B6D2EAB; Tue, 23 Aug 2022 02:31:48 -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 ams.source.kernel.org (Postfix) with ESMTPS id 16B44B8105C; Tue, 23 Aug 2022 09:31:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51F4FC433D6; Tue, 23 Aug 2022 09:31:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661247105; bh=tgwi/tP+hcVfUhfNfNmv7WL2po1ZQx4WqR5FMscIIQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxqHU8Fcow4VV0zd4n6PGJ4HMmSdS9oCNVybyJUvu/lxZVlS7n0eR/qdKLqyx9e4j 3hB4m3B0zFzQDVorSrOMrIGgI+tpMN3EQlRFEy5YWmUzGT+LEo866BQY9s9ID7vrZc ibXxtekL6RT2E06E0rDNy91RTTq4fVVJzgWwrDvM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , Peilin Ye , "David S. Miller" Subject: [PATCH 5.4 319/389] vsock: Set socket state back to SS_UNCONNECTED in vsock_connect_timeout() Date: Tue, 23 Aug 2022 10:26:37 +0200 Message-Id: <20220823080128.865043509@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peilin Ye commit a3e7b29e30854ed67be0d17687e744ad0c769c4b upstream. Imagine two non-blocking vsock_connect() requests on the same socket. The first request schedules @connect_work, and after it times out, vsock_connect_timeout() sets *sock* state back to TCP_CLOSE, but keeps *socket* state as SS_CONNECTING. Later, the second request returns -EALREADY, meaning the socket "already has a pending connection in progress", even though the first request has already timed out. As suggested by Stefano, fix it by setting *socket* state back to SS_UNCONNECTED, so that the second request will return -ETIMEDOUT. Suggested-by: Stefano Garzarella Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Reviewed-by: Stefano Garzarella Signed-off-by: Peilin Ye Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/af_vsock.c | 1 + 1 file changed, 1 insertion(+) --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1110,6 +1110,7 @@ static void vsock_connect_timeout(struct if (sk->sk_state =3D=3D TCP_SYN_SENT && (sk->sk_shutdown !=3D SHUTDOWN_MASK)) { sk->sk_state =3D TCP_CLOSE; + sk->sk_socket->state =3D SS_UNCONNECTED; sk->sk_err =3D ETIMEDOUT; sk->sk_error_report(sk); vsock_transport_cancel_pkt(vsk);