Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>

authored by

Eiichi Tsukata and committed by
David S. Miller
c7cd82b9 bb7bbb6e

+2
+2
net/vmw_vsock/af_vsock.c
··· 1322 1322 * non-blocking call. 1323 1323 */ 1324 1324 err = -EALREADY; 1325 + if (flags & O_NONBLOCK) 1326 + goto out; 1325 1327 break; 1326 1328 default: 1327 1329 if ((sk->sk_state == TCP_LISTEN) ||