improve qom debugging and fix a dangling MemoryRegion in rutabaga
cover improve qom debugging and fix a dangling MemoryRegion in rutabaga
Hi, this series of patches fixes a dangling MemoryRegion in rutabaga and also brings the debugging changes I used to locate it.
Roman Kiryanov (2):
qom: improve use-after-free debugging
display: rutabaga: unparent MemoryRegions in unmap
hw/display/virtio-gpu-rutabaga.c | 1 + qom/object.c | 3 +++ 2 files changed, 4 insertions(+)
Signature · 1 line
2.54.0.rc2.544.gc7ae2d5bb8-goog
PATCH 1/2 qom: improve use-after-free debugging
This patch invalidates dead objects so their usage will lead to more predictable results (crashes or asserts).
--- qom/object.c | 3 +++ 1 file changed, 3 insertions(+)
qom/object.c +3 -0
@@ -613,6 +613,7 @@ static void object_property_del_all(Object *obj) }while (released);g_hash_table_unref (obj->properties); + obj->properties =NULL ; }static void object_property_del_child (Object *obj,Object *child)
@@ -670,6 +671,8 @@ static void object_finalize(void *data)g_assert (obj->ref ==0 );g_assert (obj->parent ==NULL ); +g_assert (obj->properties ==NULL ); + obj->class =NULL ;if (obj->free) { obj->free (obj); }
Signature · 1 line
2.54.0.rc2.544.gc7ae2d5bb8-goog
Re: [PATCH 1/2] qom: improve use-after-free debugging
Hi
Quoted 15 lines · Roman Kiryanov
This patch invalidates dead objects so their usage will lead to more predictable results (crashes or asserts).
Change-Id I1dc36dbc1030c2e41c937f08baa97b2e81d44c82Signed-off-by Roman Kiryanov <[email protected]>--- qom/object.c | 3 +++ 1 file changed, 3 insertions(+)qom/object.c +0
-0
qom/object.c static void object_property_del_all(Object *obj) · line 616
Quoted 4 lines
qom/object.c +1
-0@@ -613,6 +613,7 @@ static void object_property_del_all(Object *obj) }while (released);g_hash_table_unref (obj->properties); + obj->properties =NULL ;
That makes sense (I'd g_clear_pointer for a safer one-liner instead)
qom/object.c static void object_finalize(void *data) · line 675
Quoted 9 lines
qom/object.c +2
-0}static void object_property_del_child (Object *obj,Object *child)@@ -670,6 +671,8 @@ static void object_finalize(void *data)g_assert (obj->ref ==0 );g_assert (obj->parent ==NULL ); +g_assert (obj->properties ==NULL ); + obj->class =NULL ;
This one I am not sure is placed right. If the goal is to revert the object_initialize_with_type() effect, perhaps it should do more, in object_deinit() ?
Quoted 7 lines
qom/object.c +0
-1if (obj->free) { obj->free (obj); } --2.54.0.rc2.544.gc7ae2d5bb8-goog
Signature · 1 line
Marc-André Lureau
Re: [PATCH 1/2] qom: improve use-after-free debugging
Hi Marc, thank you for looking.
Quoted 3 lines · Marc-André Lureau
This one I am not sure is placed right. If the goal is to revert the
object_initialize_with_type()effect, perhaps it should do more, inobject_deinit()?
I agree, I will send an update.
PATCH 2/2 display: rutabaga: unparent MemoryRegions in unmap
In reply to Roman KiryanovThe virtio-gpu-rutabaga-device instance holds a hash table of child objects (Object::properties) and a memory region is added there every time memory_region_init_ram_ptr is called.
The unmap_blob call invalidates a MemoryRegion but does not remove it from the device, which makes pointers to the region dangling and eventually causes a crash when those pointers are dereferenced.
--- hw/display/virtio-gpu-rutabaga.c | 1 + 1 file changed, 1 insertion(+)
hw/display/virtio-gpu-rutabaga.c +1 -0
@@ -737,6 +737,7 @@ rutabaga_cmd_resource_unmap_blob(VirtIOGPU *g,MemoryRegion *mr = &(vr->memory_regions[slot].mr);memory_region_del_subregion (&vb->hostmem, mr); +object_unparent (OBJECT (mr)); vr->memory_regions[slot].resource_id =0 ; vr->memory_regions[slot].used =0 ;
Signature · 1 line
2.54.0.rc2.544.gc7ae2d5bb8-goog
v2 cover improve qom debugging and fix a dangling MemoryRegion in rutabaga
In reply to Roman KiryanovHi, this series of patches fixes a dangling MemoryRegion in rutabaga and also brings the debugging changes I used to locate it.
Changes in v2:
- Updated clearing of obj->properties using g_clear_pointer.
- Moved clearing of obj->class into object_deinit.
- obj->class is checked to be NULL before obj->free(obj).
Roman Kiryanov (2):
qom: improve use-after-free debugging
display: rutabaga: unparent MemoryRegions in unmap
hw/display/virtio-gpu-rutabaga.c | 1 + qom/object.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v2 1/2 qom: improve use-after-free debugging
This patch invalidates dead objects so their usage will lead to more predictable results (crashes or asserts).
---
Changes in v2:
- Updated clearing of obj->properties using g_clear_pointer.
- Moved clearing of obj->class into object_deinit.
- obj->class is checked to be NULL before obj->free(obj).
qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qom/object.c +5 -1
@@ -612,7 +612,7 @@ static void object_property_del_all(Object *obj) } }while (released); -g_hash_table_unref (obj->properties); +g_clear_pointer (&obj->properties, g_hash_table_unref); }static void object_property_del_child (Object *obj,Object *child)
@@ -658,6 +658,9 @@ static void object_deinit(Object *obj, TypeImpl *type)if (type_has_parent (type)) {object_deinit (obj,type_get_parent (type)); } + +g_assert (obj->properties ==NULL ); + obj->class =NULL ; }static void object_finalize (void *data)
@@ -670,6 +673,7 @@ static void object_finalize(void *data)g_assert (obj->ref ==0 );g_assert (obj->parent ==NULL ); +g_assert (obj->class ==NULL );if (obj->free) { obj->free (obj); }
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Re: [PATCH v2 1/2] qom: improve use-after-free debugging
Quoted 4 lines · Roman Kiryanov
This patch invalidates dead objects so their usage will lead to more predictable results (crashes or asserts).
Signed-off-by Roman Kiryanov <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Updated clearing ofobj->propertiesusingg_clear_pointer.
- Moved clearing ofobj->classintoobject_deinit.
-obj->classis checked to be NULL beforeobj->free(obj).qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
PATCH v2 2/2 display: rutabaga: unparent MemoryRegions in unmap
In reply to Roman KiryanovThe virtio-gpu-rutabaga-device instance holds a hash table of child objects (Object::properties) and a memory region is added there every time memory_region_init_ram_ptr is called.
The unmap_blob call invalidates a MemoryRegion but does not remove it from the device, which makes pointers to the region dangling and eventually causes a crash when those pointers are dereferenced.
--- hw/display/virtio-gpu-rutabaga.c | 1 + 1 file changed, 1 insertion(+)
hw/display/virtio-gpu-rutabaga.c +1 -0
@@ -737,6 +737,7 @@ rutabaga_cmd_resource_unmap_blob(VirtIOGPU *g,MemoryRegion *mr = &(vr->memory_regions[slot].mr);memory_region_del_subregion (&vb->hostmem, mr); +object_unparent (OBJECT (mr)); vr->memory_regions[slot].resource_id =0 ; vr->memory_regions[slot].used =0 ;
Signature · 1 line
2.54.0.545.g6539524ca2-goog