[PATCH net v2] vsock: prevent unnecessary refcnt inc for nonblocking connect

Subsystems: networking [general], the rest, vm sockets (af_vsock)

STALE1732d REVIEWED: 2 (2M)

1 review trailer (1 from subsystem maintainers).

2 messages, 2 authors, 2021-11-10 · open the first message on its own page

[PATCH net v2] vsock: prevent unnecessary refcnt inc for nonblocking connect

From: Eiichi Tsukata <hidden>
Date: 2021-11-09 00:15:26

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 <redacted>
---
 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 e2c0cfb334d2..fa8c1b623fa2 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -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) ||
-- 
2.33.1

Re: [PATCH net v2] vsock: prevent unnecessary refcnt inc for nonblocking connect

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-11-10 14:40:25

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller [off-list ref]:

On Tue,  9 Nov 2021 00:15:02 +0000 you wrote:
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.

[...]
Here is the summary with links:
  - [net,v2] vsock: prevent unnecessary refcnt inc for nonblocking connect
    https://git.kernel.org/netdev/net/c/c7cd82b90599

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help