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 D16FCC4332F for ; Wed, 24 Nov 2021 13:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347835AbhKXNPy (ORCPT ); Wed, 24 Nov 2021 08:15:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:52052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347934AbhKXNMP (ORCPT ); Wed, 24 Nov 2021 08:12:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4C12261407; Wed, 24 Nov 2021 12:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637757747; bh=J3HqR3bGwk+zv7mfS73dHaPWxcMzdyWtvMt1La+h8dM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0nSbBBQH2sV0/jBt8xmg2jp+st/eMDP5cea2b4F53bj/kfE/sSP7fUOYkRaILYpQI MjXqxGa6G5I6UbZc7j1sYQmRClCW/uEVxEwJk44AjgrGdKfyLaAiKXk00iAr398Szg GHoqMxkL2KgxyXJ5nG66KgpffIz2GURNNpgCJZLo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , Eiichi Tsukata , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 230/323] vsock: prevent unnecessary refcnt inc for nonblocking connect Date: Wed, 24 Nov 2021 12:57:00 +0100 Message-Id: <20211124115726.686414340@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115718.822024889@linuxfoundation.org> References: <20211124115718.822024889@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eiichi Tsukata [ Upstream commit c7cd82b90599fa10915f41e3dd9098a77d0aa7b6 ] Currently vosck_connect() increments sock refcount for nonblocking socket each time it's called, which can lead to memory leak if it's called multiple times because connect timeout function decrements sock refcount only once. Fixes it by making vsock_connect() return -EALREADY immediately when sock state is already SS_CONNECTING. Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Reviewed-by: Stefano Garzarella Signed-off-by: Eiichi Tsukata Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/af_vsock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 2d31fce5c2185..37329e11dc3cc 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1159,6 +1159,8 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, * non-blocking call. */ err = -EALREADY; + if (flags & O_NONBLOCK) + goto out; break; default: if ((sk->sk_state == TCP_LISTEN) || -- 2.33.0