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 A5E0CC433FE for ; Wed, 24 Nov 2021 12:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244896AbhKXM1W (ORCPT ); Wed, 24 Nov 2021 07:27:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244451AbhKXMXe (ORCPT ); Wed, 24 Nov 2021 07:23:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BE3F96109D; Wed, 24 Nov 2021 12:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637756047; bh=tFGTaT77JZFxI/VUzBar6Lpl+pYtrphfByvjZPpwnog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jdx+D7hwq8oFGhPNLoHqIA4JqRWkHdyPgKeM10gQfnNAylVumBwGyDVH5FDd6BTUa MJBVSvWbAfcT2piP6+iDrwxO+xRYn02wMwenlmZwHOEeOhezKrbZWXLqs+RcgDQiPa Z/VzmZ04TFP5r1jH9oW2uMziNwJ/5I3uUDIjg8/w= 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.9 151/207] vsock: prevent unnecessary refcnt inc for nonblocking connect Date: Wed, 24 Nov 2021 12:57:02 +0100 Message-Id: <20211124115708.901588208@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115703.941380739@linuxfoundation.org> References: <20211124115703.941380739@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 2fecdfe49bae3..95470d628d34b 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1173,6 +1173,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 == VSOCK_SS_LISTEN) || -- 2.33.0