All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH net] virtio/vsock: fix leak due to missing skb owner
  2023-03-28  7:58   ` Stefano Garzarella
  (?)
@ 2023-03-18 11:38   ` Bobby Eshleman
  -1 siblings, 0 replies; 4+ messages in thread
From: Bobby Eshleman @ 2023-03-18 11:38 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: Bobby Eshleman, Stefan Hajnoczi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, kvm, virtualization, netdev,
	linux-kernel, Cong Wang

On Tue, Mar 28, 2023 at 09:58:00AM +0200, Stefano Garzarella wrote:
> On Mon, Mar 27, 2023 at 10:01:05PM +0000, Bobby Eshleman wrote:
> > This patch sets the owner for the skb when being sent from a socket and
> > so solves the leak caused when virtio_transport_purge_skbs() finds
> > skb->sk is always NULL and therefore never matches it with the current
> > socket. Setting the owner upon allocation fixes this.
> > 
> > Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
> > Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
> > Reported-by: Cong Wang <xiyou.wangcong@gmail.com>
> > Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/
> > ---
> > net/vmw_vsock/virtio_transport_common.c | 3 +++
> > 1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> > index 957cdc01c8e8..2a2f0c1a9fbd 100644
> > --- a/net/vmw_vsock/virtio_transport_common.c
> > +++ b/net/vmw_vsock/virtio_transport_common.c
> > @@ -94,6 +94,9 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
> > 					 info->op,
> > 					 info->flags);
> > 
> > +	if (info->vsk)
> > +		skb_set_owner_w(skb, sk_vsock(info->vsk));
> > +
> 
> Should we do the same also in virtio_transport_recv_pkt()?
> 
> The skb in that cases is allocated in drivers/vhost/vsock.c and
> net/vmw_vsock/virtio_transport.c using directly
> virtio_vsock_alloc_skb(), because we don't know in advance which socket
> it belongs to.
> 
> Then in virtio_transport_recv_pkt() we look for the socket and queue it
> up. This should also solve the problem in vsock_loopback.c where we move
> skb from one socket to another.
> 

That's a great point, skb_set_owner_r() in recv_pkt() will do all of the
right accounting when called by vsock_loopback_work.

I'll add that in a v2.

Thanks,
Bobby

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net] virtio/vsock: fix leak due to missing skb owner
@ 2023-03-27 22:01 Bobby Eshleman
  2023-03-28  7:58   ` Stefano Garzarella
  0 siblings, 1 reply; 4+ messages in thread
From: Bobby Eshleman @ 2023-03-27 22:01 UTC (permalink / raw)
  To: Stefan Hajnoczi, Stefano Garzarella, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Bobby Eshleman
  Cc: kvm, virtualization, netdev, linux-kernel, Cong Wang

This patch sets the owner for the skb when being sent from a socket and
so solves the leak caused when virtio_transport_purge_skbs() finds
skb->sk is always NULL and therefore never matches it with the current
socket. Setting the owner upon allocation fixes this.

Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
Reported-by: Cong Wang <xiyou.wangcong@gmail.com>
Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/
---
 net/vmw_vsock/virtio_transport_common.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 957cdc01c8e8..2a2f0c1a9fbd 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -94,6 +94,9 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
 					 info->op,
 					 info->flags);
 
+	if (info->vsk)
+		skb_set_owner_w(skb, sk_vsock(info->vsk));
+
 	return skb;
 
 out:

---
base-commit: e5b42483ccce50d5b957f474fd332afd4ef0c27b
change-id: 20230327-vsock-fix-leak-b1cef1582aa8

Best regards,
-- 
Bobby Eshleman <bobby.eshleman@bytedance.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] virtio/vsock: fix leak due to missing skb owner
  2023-03-27 22:01 [PATCH net] virtio/vsock: fix leak due to missing skb owner Bobby Eshleman
@ 2023-03-28  7:58   ` Stefano Garzarella
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2023-03-28  7:58 UTC (permalink / raw)
  To: Bobby Eshleman
  Cc: Stefan Hajnoczi, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kvm, virtualization, netdev, linux-kernel,
	Cong Wang

On Mon, Mar 27, 2023 at 10:01:05PM +0000, Bobby Eshleman wrote:
>This patch sets the owner for the skb when being sent from a socket and
>so solves the leak caused when virtio_transport_purge_skbs() finds
>skb->sk is always NULL and therefore never matches it with the current
>socket. Setting the owner upon allocation fixes this.
>
>Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
>Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
>Reported-by: Cong Wang <xiyou.wangcong@gmail.com>
>Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/
>---
> net/vmw_vsock/virtio_transport_common.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index 957cdc01c8e8..2a2f0c1a9fbd 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -94,6 +94,9 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
> 					 info->op,
> 					 info->flags);
>
>+	if (info->vsk)
>+		skb_set_owner_w(skb, sk_vsock(info->vsk));
>+

Should we do the same also in virtio_transport_recv_pkt()?

The skb in that cases is allocated in drivers/vhost/vsock.c and
net/vmw_vsock/virtio_transport.c using directly
virtio_vsock_alloc_skb(), because we don't know in advance which socket
it belongs to.

Then in virtio_transport_recv_pkt() we look for the socket and queue it
up. This should also solve the problem in vsock_loopback.c where we move
skb from one socket to another.

Thanks,
Stefano


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] virtio/vsock: fix leak due to missing skb owner
@ 2023-03-28  7:58   ` Stefano Garzarella
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2023-03-28  7:58 UTC (permalink / raw)
  To: Bobby Eshleman
  Cc: kvm, netdev, linux-kernel, virtualization, Eric Dumazet,
	Stefan Hajnoczi, Cong Wang, Jakub Kicinski, Paolo Abeni,
	David S. Miller

On Mon, Mar 27, 2023 at 10:01:05PM +0000, Bobby Eshleman wrote:
>This patch sets the owner for the skb when being sent from a socket and
>so solves the leak caused when virtio_transport_purge_skbs() finds
>skb->sk is always NULL and therefore never matches it with the current
>socket. Setting the owner upon allocation fixes this.
>
>Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
>Signed-off-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
>Reported-by: Cong Wang <xiyou.wangcong@gmail.com>
>Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/
>---
> net/vmw_vsock/virtio_transport_common.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index 957cdc01c8e8..2a2f0c1a9fbd 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -94,6 +94,9 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
> 					 info->op,
> 					 info->flags);
>
>+	if (info->vsk)
>+		skb_set_owner_w(skb, sk_vsock(info->vsk));
>+

Should we do the same also in virtio_transport_recv_pkt()?

The skb in that cases is allocated in drivers/vhost/vsock.c and
net/vmw_vsock/virtio_transport.c using directly
virtio_vsock_alloc_skb(), because we don't know in advance which socket
it belongs to.

Then in virtio_transport_recv_pkt() we look for the socket and queue it
up. This should also solve the problem in vsock_loopback.c where we move
skb from one socket to another.

Thanks,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-28 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27 22:01 [PATCH net] virtio/vsock: fix leak due to missing skb owner Bobby Eshleman
2023-03-28  7:58 ` Stefano Garzarella
2023-03-28  7:58   ` Stefano Garzarella
2023-03-18 11:38   ` Bobby Eshleman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.