diff mbox series

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

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

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
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 warning 9 maintainers not CCed: songliubraving@fb.com daniel@iogearbox.net john.fastabend@gmail.com yhs@fb.com kpsingh@kernel.org ast@kernel.org andrii@kernel.org kafai@fb.com bpf@vger.kernel.org
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 No Fixes tag
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. 7, 2021, 12:03 p.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.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
 net/vmw_vsock/af_vsock.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stefano Garzarella Nov. 8, 2021, 8:30 a.m. UTC | #1
On Sun, Nov 07, 2021 at 12:03:04PM +0000, Eiichi Tsukata 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.
>
>Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
>---
> net/vmw_vsock/af_vsock.c | 2 ++
> 1 file changed, 2 insertions(+)

Make sense to me, thanks for fixing this issue!
I think would be better to add the Fixes ref in the commit message:

Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")

With that:
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Thanks,
Stefano
Eiichi Tsukata Nov. 9, 2021, 12:13 a.m. UTC | #2
> On Nov 8, 2021, at 17:30, Stefano Garzarella <sgarzare@redhat.com> wrote:
> 
> On Sun, Nov 07, 2021 at 12:03:04PM +0000, Eiichi Tsukata 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.
>> 
>> Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
>> ---
>> net/vmw_vsock/af_vsock.c | 2 ++
>> 1 file changed, 2 insertions(+)
> 
> Make sense to me, thanks for fixing this issue!
> I think would be better to add the Fixes ref in the commit message:
> 
> Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
> 
> With that:
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> 
> Thanks,
> Stefano
> 

Thanks for comments! I’ll add Fixes and Reviewed-by tag then send v2.

Eiichi
diff mbox series

Patch

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 7d851eb3a683..ed0df839c38c 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) ||