summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEiichi Tsukata <eiichi.tsukata@nutanix.com>2021-11-09 00:15:02 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-11-26 11:36:16 +0100
commit0608664fb50441224458e944efec167869b3f8a1 (patch)
tree4dfb5fed23b90a17a3b8364e16d39a6e54526bec
parent5b4bf87e96f2eb319bd6830935becea4a94e17ec (diff)
downloadlinux-stable-0608664fb50441224458e944efec167869b3f8a1.tar.gz
linux-stable-0608664fb50441224458e944efec167869b3f8a1.tar.bz2
linux-stable-0608664fb50441224458e944efec167869b3f8a1.zip
vsock: prevent unnecessary refcnt inc for nonblocking connect
[ 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 <sgarzare@redhat.com> Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/vmw_vsock/af_vsock.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 2d31fce5c218..37329e11dc3c 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) ||