* [PATCH net] vsock: prevent unnecessary refcnt inc for nonblocking connect
@ 2021-11-07 12:03 Eiichi Tsukata
2021-11-08 8:30 ` Stefano Garzarella
0 siblings, 1 reply; 3+ messages in thread
From: Eiichi Tsukata @ 2021-11-07 12:03 UTC (permalink / raw)
To: sgarzare, davem, kuba, virtualization, netdev, linux-kernel
Cc: Eiichi Tsukata
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(+)
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) ||
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] vsock: prevent unnecessary refcnt inc for nonblocking connect
2021-11-07 12:03 [PATCH net] vsock: prevent unnecessary refcnt inc for nonblocking connect Eiichi Tsukata
@ 2021-11-08 8:30 ` Stefano Garzarella
2021-11-09 0:13 ` Eiichi Tsukata
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Garzarella @ 2021-11-08 8:30 UTC (permalink / raw)
To: Eiichi Tsukata; +Cc: davem, kuba, virtualization, netdev, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] vsock: prevent unnecessary refcnt inc for nonblocking connect
2021-11-08 8:30 ` Stefano Garzarella
@ 2021-11-09 0:13 ` Eiichi Tsukata
0 siblings, 0 replies; 3+ messages in thread
From: Eiichi Tsukata @ 2021-11-09 0:13 UTC (permalink / raw)
To: Stefano Garzarella
Cc: David S. Miller, kuba@kernel.org,
virtualization@lists.linux-foundation.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-09 0:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-07 12:03 [PATCH net] vsock: prevent unnecessary refcnt inc for nonblocking connect Eiichi Tsukata
2021-11-08 8:30 ` Stefano Garzarella
2021-11-09 0:13 ` Eiichi Tsukata
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox