vsock: prevent unnecessary refcnt inc for nonblocking connect

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: d021c34405 ("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>
This commit is contained in:
Eiichi Tsukata 2021-11-09 00:15:02 +00:00 committed by David S. Miller
parent bb7bbb6e36
commit c7cd82b905
1 changed files with 2 additions and 0 deletions

View File

@ -1322,6 +1322,8 @@ static int vsock_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) ||