* [PATCH v4 0/2] fix two virtio queues memleak
@ 2020-03-28 0:57 Pan Nengyuan
2020-03-28 0:57 ` [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize() Pan Nengyuan
2020-03-28 0:57 ` [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize Pan Nengyuan
0 siblings, 2 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-03-28 0:57 UTC (permalink / raw)
To: qemu-devel; +Cc: euler.robot, Pan Nengyuan, zhang.zhanghailiang, mst
This series fix two vqs leak:
1. Do delete vqs on the error path in virtio_blk_device_realize().
2. Do delete vqs in virtio_iommu_device_unrealize() to fix another leaks.
v2->v1:
- Fix incorrect free in virtio_blk_device_realize, it will cause a uaf.
v3->v2:
- Also clean 's->as_by_busptr' hash table in virtio_iommu_device_unrealize.(Suggested by Stefano Garzarella)
v4->v3:
- update patch2/2 subject message and move g_hash_table_destroy() at the beggining of unrealize().
Pan Nengyuan (2):
virtio-blk: delete vqs on the error path in realize()
virtio-iommu: avoid memleak in the unrealize
hw/block/virtio-blk.c | 3 +++
hw/virtio/virtio-iommu.c | 3 +++
2 files changed, 6 insertions(+)
--
2.18.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize()
2020-03-28 0:57 [PATCH v4 0/2] fix two virtio queues memleak Pan Nengyuan
@ 2020-03-28 0:57 ` Pan Nengyuan
2020-03-30 8:59 ` Stefan Hajnoczi
2020-03-30 10:58 ` Pankaj Gupta
2020-03-28 0:57 ` [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize Pan Nengyuan
1 sibling, 2 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-03-28 0:57 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, zhang.zhanghailiang, qemu-block, mst, Pan Nengyuan,
Max Reitz, Stefan Hajnoczi, euler.robot
virtio_vqs forgot to free on the error path in realize(). Fix that.
The asan stack:
Direct leak of 14336 byte(s) in 1 object(s) allocated from:
#0 0x7f58b93fd970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
#1 0x7f58b858249d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
#2 0x5562cc627f49 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:2413
#3 0x5562cc4b524a in virtio_blk_device_realize /mnt/sdb/qemu/hw/block/virtio-blk.c:1202
#4 0x5562cc613050 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virtio.c:3615
#5 0x5562ccb7a568 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:891
#6 0x5562cd39cd45 in property_set_bool /mnt/sdb/qemu/qom/object.c:2238
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
v2->v1:
- Fix incorrect free in v1, it will cause a uaf.
---
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
Cc: qemu-block@nongnu.org
---
hw/block/virtio-blk.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 142863a3b2..97ba8a2187 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1204,6 +1204,9 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err);
if (err != NULL) {
error_propagate(errp, err);
+ for (i = 0; i < conf->num_queues; i++) {
+ virtio_del_queue(vdev, i);
+ }
virtio_cleanup(vdev);
return;
}
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize
2020-03-28 0:57 [PATCH v4 0/2] fix two virtio queues memleak Pan Nengyuan
2020-03-28 0:57 ` [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize() Pan Nengyuan
@ 2020-03-28 0:57 ` Pan Nengyuan
2020-03-30 7:24 ` Stefano Garzarella
1 sibling, 1 reply; 6+ messages in thread
From: Pan Nengyuan @ 2020-03-28 0:57 UTC (permalink / raw)
To: qemu-devel
Cc: zhang.zhanghailiang, mst, Pan Nengyuan, Eric Auger,
Stefan Hajnoczi, euler.robot
req_vq/event_vq forgot to free in unrealize. Fix that.
And also do clean 's->as_by_busptr' hash table in unrealize to fix another leak.
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Acked-by: Eric Auger <eric.auger@redhat.com>
---
Cc: Eric Auger <eric.auger@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
---
v3->v1/v2:
- Also clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
v4->v3:
- update subject msg and move g_hash_table_destroy to the beginning of unrealize.
---
hw/virtio/virtio-iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 4cee8083bc..22ba8848c2 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -693,9 +693,12 @@ static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
+ g_hash_table_destroy(s->as_by_busptr);
g_tree_destroy(s->domains);
g_tree_destroy(s->endpoints);
+ virtio_delete_queue(s->req_vq);
+ virtio_delete_queue(s->event_vq);
virtio_cleanup(vdev);
}
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize
2020-03-28 0:57 ` [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize Pan Nengyuan
@ 2020-03-30 7:24 ` Stefano Garzarella
0 siblings, 0 replies; 6+ messages in thread
From: Stefano Garzarella @ 2020-03-30 7:24 UTC (permalink / raw)
To: Pan Nengyuan
Cc: zhang.zhanghailiang, mst, qemu-devel, Eric Auger,
Stefan Hajnoczi, euler.robot
On Sat, Mar 28, 2020 at 08:57:05AM +0800, Pan Nengyuan wrote:
> req_vq/event_vq forgot to free in unrealize. Fix that.
> And also do clean 's->as_by_busptr' hash table in unrealize to fix another leak.
>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Acked-by: Eric Auger <eric.auger@redhat.com>
> ---
> Cc: Eric Auger <eric.auger@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> v3->v1/v2:
> - Also clean 's->as_by_busptr' hash table in unrealize.(Suggested by Stefano Garzarella)
> v4->v3:
> - update subject msg and move g_hash_table_destroy to the beginning of unrealize.
> ---
> hw/virtio/virtio-iommu.c | 3 +++
> 1 file changed, 3 insertions(+)
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Thanks,
Stefano
>
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 4cee8083bc..22ba8848c2 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -693,9 +693,12 @@ static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp)
> VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
>
> + g_hash_table_destroy(s->as_by_busptr);
> g_tree_destroy(s->domains);
> g_tree_destroy(s->endpoints);
>
> + virtio_delete_queue(s->req_vq);
> + virtio_delete_queue(s->event_vq);
> virtio_cleanup(vdev);
> }
>
> --
> 2.18.2
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize()
2020-03-28 0:57 ` [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize() Pan Nengyuan
@ 2020-03-30 8:59 ` Stefan Hajnoczi
2020-03-30 10:58 ` Pankaj Gupta
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2020-03-30 8:59 UTC (permalink / raw)
To: Pan Nengyuan
Cc: Kevin Wolf, zhang.zhanghailiang, qemu-block, mst, qemu-devel,
Max Reitz, euler.robot
[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]
On Sat, Mar 28, 2020 at 08:57:04AM +0800, Pan Nengyuan wrote:
> virtio_vqs forgot to free on the error path in realize(). Fix that.
>
> The asan stack:
> Direct leak of 14336 byte(s) in 1 object(s) allocated from:
> #0 0x7f58b93fd970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
> #1 0x7f58b858249d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
> #2 0x5562cc627f49 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:2413
> #3 0x5562cc4b524a in virtio_blk_device_realize /mnt/sdb/qemu/hw/block/virtio-blk.c:1202
> #4 0x5562cc613050 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virtio.c:3615
> #5 0x5562ccb7a568 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:891
> #6 0x5562cd39cd45 in property_set_bool /mnt/sdb/qemu/qom/object.c:2238
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> v2->v1:
> - Fix incorrect free in v1, it will cause a uaf.
> ---
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Max Reitz <mreitz@redhat.com>
> Cc: qemu-block@nongnu.org
> ---
> hw/block/virtio-blk.c | 3 +++
> 1 file changed, 3 insertions(+)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize()
2020-03-28 0:57 ` [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize() Pan Nengyuan
2020-03-30 8:59 ` Stefan Hajnoczi
@ 2020-03-30 10:58 ` Pankaj Gupta
1 sibling, 0 replies; 6+ messages in thread
From: Pankaj Gupta @ 2020-03-30 10:58 UTC (permalink / raw)
To: Pan Nengyuan
Cc: Kevin Wolf, zhang.zhanghailiang, qemu-block, Michael S . Tsirkin,
qemu-devel, Max Reitz, Stefan Hajnoczi, euler.robot
Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-30 10:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 0:57 [PATCH v4 0/2] fix two virtio queues memleak Pan Nengyuan
2020-03-28 0:57 ` [PATCH v4 1/2] virtio-blk: delete vqs on the error path in realize() Pan Nengyuan
2020-03-30 8:59 ` Stefan Hajnoczi
2020-03-30 10:58 ` Pankaj Gupta
2020-03-28 0:57 ` [PATCH v4 2/2] virtio-iommu: avoid memleak in the unrealize Pan Nengyuan
2020-03-30 7:24 ` Stefano Garzarella
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).