[Qemu-devel] [PATCH] hostmem: fix crash when querying empty host-nodes property via QMP

Igor Mammedov posted 1 patch 5 years, 2 months ago
Test docker-mingw@fedora passed
Test asan passed
Test checkpatch passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1549377087-205549-1-git-send-email-imammedo@redhat.com
Maintainers: Igor Mammedov <imammedo@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>
There is a newer version of this series
backends/hostmem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH] hostmem: fix crash when querying empty host-nodes property via QMP
Posted by Igor Mammedov 5 years, 2 months ago
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 empty hostmem.host-nodes property.

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

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 backends/hostmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 0c8ef17..fe14be5 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -86,7 +86,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));
@@ -104,6 +104,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);
 }
 
-- 
2.7.4


Re: [Qemu-devel] [PATCH] hostmem: fix crash when querying empty host-nodes property via QMP
Posted by Markus Armbruster 5 years, 2 months ago
Igor Mammedov <imammedo@redhat.com> writes:

> 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 empty hostmem.host-nodes property.
>
> Fix it by calling visitor even if host-nodes wasn't set
> before exiting from property getter to return empty list.

host-nodes or host_nodes?

If local variable host_nodes: that one's always set.  The case you fix
has it set to NULL.

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  backends/hostmem.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 0c8ef17..fe14be5 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -86,7 +86,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));
> @@ -104,6 +104,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);
>  }

Yes, an empty list needs to be visited just like a non-empty list.

Patch looks good.

Re: [Qemu-devel] [PATCH] hostmem: fix crash when querying empty host-nodes property via QMP
Posted by Igor Mammedov 5 years, 2 months ago
On Wed, 13 Feb 2019 14:30:55 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Igor Mammedov <imammedo@redhat.com> writes:
> 
> > 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 empty hostmem.host-nodes property.
> >
> > Fix it by calling visitor even if host-nodes wasn't set
> > before exiting from property getter to return empty list.  
> 
> host-nodes or host_nodes?
> 
> If local variable host_nodes: that one's always set.  The case you fix
> has it set to NULL.

it's about property host-nodes:

  value = find_first_bit(backend->host_nodes, MAX_NODES);                      
  if (value == MAX_NODES) {                                                    
    goto ret;                                                                
  }

when no bits set, it exits without visiting being returned list.

I'll send v2 with commit message giving more explanation to make
it clearer.

> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  backends/hostmem.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/backends/hostmem.c b/backends/hostmem.c
> > index 0c8ef17..fe14be5 100644
> > --- a/backends/hostmem.c
> > +++ b/backends/hostmem.c
> > @@ -86,7 +86,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));
> > @@ -104,6 +104,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);
> >  }  
> 
> Yes, an empty list needs to be visited just like a non-empty list.
> 
> Patch looks good.
> 


Re: [Qemu-devel] [PATCH] hostmem: fix crash when querying empty host-nodes property via QMP
Posted by Igor Mammedov 5 years, 2 months ago
On Tue,  5 Feb 2019 15:31:27 +0100
Igor Mammedov <imammedo@redhat.com> wrote:

> 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 empty hostmem.host-nodes property.
> 
> Fix it by calling visitor even if host-nodes wasn't set
> before exiting from property getter to return empty list.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  backends/hostmem.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 0c8ef17..fe14be5 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -86,7 +86,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));
> @@ -104,6 +104,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);
>  }
>  

Markus/Michael,

does this patch make sense from QAPI point of view?