Skip to contentSkip to conversation

hostmem: fix crash when querying empty host-nodes property via QMP

PATCH Applied Igor Mammedov 4 participants 4 messages Feb 14, 2019 – Feb 28, 2019 Arm STM32

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hostmem: fix crash when querying empty host-nodes property via QMP

QEMU will crashes with
qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of not set hostmem's "host-nodes"
property, HostMemoryBackend::host_nodes bitmap doesn't have
any bits set in it, which leads to find_first_bit() returning
MAX_NODES and consequently to an early return from
host_memory_backend_get_host_nodes() without calling visitor.

Fix it by calling visitor even if "host-nodes" property wasn't set before exiting from property getter to return valid empty list.

---
v2:
* fixup commit message to put emphasis on property instead local variable host_nodes and make explanation more hopefully more clear. (Markus Armbruster <[email protected]>)

---
 backends/hostmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
backends/hostmem.c +2 -1
index 87b19d2111..04baf479a1 100644
@@ -88,7 +88,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
 
     value = find_first_bit(backend->host_nodes, MAX_NODES);
     if (value == MAX_NODES) {
-        return;
+        goto ret;
     }
 
     *node = g_malloc0(sizeof(**node));
@@ -106,6 +106,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
         node = &(*node)->next;
     } while (true);
 
+ret:
     visit_type_uint16List(v, name, &host_nodes, errp);
 }
 
Signature · 1 line
2.18.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Igor Mammedov

QEMU will crashes with
qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of not set hostmem's "host-nodes"
property, HostMemoryBackend::host_nodes bitmap doesn't have
any bits set in it, which leads to find_first_bit() returning
MAX_NODES and consequently to an early return from
host_memory_backend_get_host_nodes() without calling visitor.

Fix it by calling visitor even if "host-nodes" property wasn't set before exiting from property getter to return valid empty list.

Quoted 9 lines

---
v2:
* fixup commit message to put emphasis on property instead local variable host_nodes and make explanation more hopefully more clear. (Markus Armbruster <[email protected]>)

---
 backends/hostmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 22 lines
backends/hostmem.c +2 -1
index 87b19d2111..04baf479a1 100644
@@ -88,7 +88,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
 
     value = find_first_bit(backend->host_nodes, MAX_NODES);
     if (value == MAX_NODES) {
-        return;
+        goto ret;
     }
 
     *node = g_malloc0(sizeof(**node));
@@ -106,6 +106,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
         node = &(*node)->next;
     } while (true);
 
+ret:
     visit_type_uint16List(v, name, &host_nodes, errp);
 }
 
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v2 1/1
#2 lore raw
In reply to Igor Mammedov
Quoted 13 lines · Igor Mammedov

QEMU will crashes with
qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of not set hostmem's "host-nodes"
property, HostMemoryBackend::host_nodes bitmap doesn't have
any bits set in it, which leads to find_first_bit() returning
MAX_NODES and consequently to an early return from
host_memory_backend_get_host_nodes() without calling visitor.

Fix it by calling visitor even if "host-nodes" property wasn't set before exiting from property getter to return valid empty list.

Quoted 8 lines

---
v2:
* fixup commit message to put emphasis on property instead local variable host_nodes and make explanation more hopefully more clear. (Markus Armbruster <[email protected]>)

---
 backends/hostmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#3 lore raw
In reply to Igor Mammedov
Quoted 8 lines · Igor Mammedov

QEMU will crashes with
qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of not set hostmem's "host-nodes"
property, HostMemoryBackend::host_nodes bitmap doesn't have
any bits set in it, which leads to find_first_bit() returning
MAX_NODES and consequently to an early return from
host_memory_backend_get_host_nodes() without calling visitor.

Quoted 5 lines

Fix it by calling visitor even if "host-nodes" property wasn't set before exiting from property getter to return valid empty list.

Queued on machine-next, thanks!

Signature · 1 line
Eduardo