diff mbox series

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

Message ID 20211109001502.9152-1-eiichi.tsukata@nutanix.com (mailing list archive)
State Accepted
Commit c7cd82b90599fa10915f41e3dd9098a77d0aa7b6
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] vsock: prevent unnecessary refcnt inc for nonblocking connect | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 3 blamed authors not CCed: acking@vmware.com georgezhang@vmware.com dtor@vmware.com; 3 maintainers not CCed: acking@vmware.com georgezhang@vmware.com dtor@vmware.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eiichi Tsukata Nov. 9, 2021, 12:15 a.m. UTC
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>
---
 net/vmw_vsock/af_vsock.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 10, 2021, 2:40 p.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

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!
diff mbox series

Patch

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