linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed
@ 2019-03-12  7:06 Yue Haibing
  2019-03-12  8:01 ` Jason Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Yue Haibing @ 2019-03-12  7:06 UTC (permalink / raw)
  To: mst, jasowang; +Cc: linux-kernel, virtualization, YueHaibing

From: YueHaibing <yuehaibing@huawei.com>

'desc' should be freed before leaving from err handing path.

Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/virtio/virtio_ring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index a0b07c3..9d95d9c 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -991,6 +991,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
 
 	if (unlikely(vq->vq.num_free < 1)) {
 		pr_debug("Can't add buf len 1 - avail = 0\n");
+		kfree(desc);
 		END_USE(vq);
 		return -ENOSPC;
 	}
-- 
2.7.0



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

* Re: [PATCH] virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed
  2019-03-12  7:06 [PATCH] virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed Yue Haibing
@ 2019-03-12  8:01 ` Jason Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Wang @ 2019-03-12  8:01 UTC (permalink / raw)
  To: Yue Haibing, mst; +Cc: linux-kernel, virtualization


On 2019/3/12 下午3:06, Yue Haibing wrote:
> From: YueHaibing <yuehaibing@huawei.com>
>
> 'desc' should be freed before leaving from err handing path.
>
> Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>   drivers/virtio/virtio_ring.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index a0b07c3..9d95d9c 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -991,6 +991,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
>   
>   	if (unlikely(vq->vq.num_free < 1)) {
>   		pr_debug("Can't add buf len 1 - avail = 0\n");
> +		kfree(desc);
>   		END_USE(vq);
>   		return -ENOSPC;
>   	}


Or you can move the check before the allocation.

Acked-by: Jason Wang <jasowang@redhat.com>

Please cc stable next time.

Thanks


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

end of thread, other threads:[~2019-03-12  8:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12  7:06 [PATCH] virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed Yue Haibing
2019-03-12  8:01 ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).