qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
@ 2019-06-10 13:50 Igor Mammedov
  2019-06-10 13:57 ` Paolo Bonzini
  2019-06-21  0:29 ` Paolo Bonzini
  0 siblings, 2 replies; 5+ messages in thread
From: Igor Mammedov @ 2019-06-10 13:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mst, ehabkost, armbru, rth

QEMU will crash when device-memory-region-size property is read if ms->device_memory
wasn't initialized yet.

Crash can be reproduced with:
 $QEMU -preconfig -qmp unix:qmp_socket,server,nowait &
 ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size

Instead of crashing return 0 if ms->device_memory hasn't been initialized.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  add reproducer to commit message
   (Markus Armbruster <armbru@redhat.com>)

 hw/i386/pc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index edc240b..1b7ead9 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -2459,7 +2459,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
                                          Error **errp)
 {
     MachineState *ms = MACHINE(obj);
-    int64_t value = memory_region_size(&ms->device_memory->mr);
+    int64_t value = 0;
+
+    if (ms->device_memory) {
+        memory_region_size(&ms->device_memory->mr);
+    }
 
     visit_type_int(v, name, &value, errp);
 }
-- 
2.7.4



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

* Re: [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
  2019-06-10 13:50 [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() Igor Mammedov
@ 2019-06-10 13:57 ` Paolo Bonzini
  2019-06-21  0:29 ` Paolo Bonzini
  1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2019-06-10 13:57 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: armbru, mst, ehabkost, rth

On 10/06/19 15:50, Igor Mammedov wrote:
> QEMU will crash when device-memory-region-size property is read if ms->device_memory
> wasn't initialized yet.
> 
> Crash can be reproduced with:
>  $QEMU -preconfig -qmp unix:qmp_socket,server,nowait &
>  ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size
> 
> Instead of crashing return 0 if ms->device_memory hasn't been initialized.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v2:
>   add reproducer to commit message
>    (Markus Armbruster <armbru@redhat.com>)
> 
>  hw/i386/pc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index edc240b..1b7ead9 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -2459,7 +2459,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
>                                           Error **errp)
>  {
>      MachineState *ms = MACHINE(obj);
> -    int64_t value = memory_region_size(&ms->device_memory->mr);
> +    int64_t value = 0;
> +
> +    if (ms->device_memory) {
> +        memory_region_size(&ms->device_memory->mr);
> +    }
>  
>      visit_type_int(v, name, &value, errp);
>  }
> 

Queued, thanks.

Paolo


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

* Re: [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
  2019-06-10 13:50 [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() Igor Mammedov
  2019-06-10 13:57 ` Paolo Bonzini
@ 2019-06-21  0:29 ` Paolo Bonzini
  2019-06-21  1:46   ` Eduardo Habkost
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2019-06-21  0:29 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: armbru, rth, ehabkost, mst

On 10/06/19 15:50, Igor Mammedov wrote:
> QEMU will crash when device-memory-region-size property is read if ms->device_memory
> wasn't initialized yet.
> 
> Crash can be reproduced with:
>  $QEMU -preconfig -qmp unix:qmp_socket,server,nowait &
>  ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size
> 
> Instead of crashing return 0 if ms->device_memory hasn't been initialized.

This patch breaks bios-tables-test /x86_64/acpi/piix64/cpuhp:

acpi-test: Warning! SRAT binary file mismatch. Actual [aml:/tmp/aml-RIFK3Z], Expected [aml:tests/data/acpi/pc/SRAT.memhp].
acpi-test: Warning! SRAT mismatch. Actual [asl:/tmp/asl-TLFK3Z.dsl, aml:/tmp/aml-RIFK3Z], Expected [asl:/tmp/asl-JL5J3Z.dsl, aml:tests/data/acpi/pc/SRAT.memhp].
**
ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)
ERROR - Bail out! ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)

So I'm removing it from the pull request.

Paolo

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v2:
>   add reproducer to commit message
>    (Markus Armbruster <armbru@redhat.com>)
> 
>  hw/i386/pc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index edc240b..1b7ead9 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -2459,7 +2459,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
>                                           Error **errp)
>  {
>      MachineState *ms = MACHINE(obj);
> -    int64_t value = memory_region_size(&ms->device_memory->mr);
> +    int64_t value = 0;
> +
> +    if (ms->device_memory) {
> +        memory_region_size(&ms->device_memory->mr);
> +    }
>  
>      visit_type_int(v, name, &value, errp);
>  }
> 



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

* Re: [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
  2019-06-21  0:29 ` Paolo Bonzini
@ 2019-06-21  1:46   ` Eduardo Habkost
  2019-06-24  9:01     ` Igor Mammedov
  0 siblings, 1 reply; 5+ messages in thread
From: Eduardo Habkost @ 2019-06-21  1:46 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Igor Mammedov, rth, qemu-devel, armbru, mst

On Fri, Jun 21, 2019 at 02:29:29AM +0200, Paolo Bonzini wrote:
> On 10/06/19 15:50, Igor Mammedov wrote:
> > QEMU will crash when device-memory-region-size property is read if ms->device_memory
> > wasn't initialized yet.
> > 
> > Crash can be reproduced with:
> >  $QEMU -preconfig -qmp unix:qmp_socket,server,nowait &
> >  ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size
> > 
> > Instead of crashing return 0 if ms->device_memory hasn't been initialized.
> 
> This patch breaks bios-tables-test /x86_64/acpi/piix64/cpuhp:
> 
> acpi-test: Warning! SRAT binary file mismatch. Actual [aml:/tmp/aml-RIFK3Z], Expected [aml:tests/data/acpi/pc/SRAT.memhp].
> acpi-test: Warning! SRAT mismatch. Actual [asl:/tmp/asl-TLFK3Z.dsl, aml:/tmp/aml-RIFK3Z], Expected [asl:/tmp/asl-JL5J3Z.dsl, aml:tests/data/acpi/pc/SRAT.memhp].
> **
> ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)
> ERROR - Bail out! ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)
> 
> So I'm removing it from the pull request.

The patch makes all memory regions return 0 as its size.


> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > v2:
> >   add reproducer to commit message
> >    (Markus Armbruster <armbru@redhat.com>)
> > 
> >  hw/i386/pc.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index edc240b..1b7ead9 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -2459,7 +2459,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
> >                                           Error **errp)
> >  {
> >      MachineState *ms = MACHINE(obj);
> > -    int64_t value = memory_region_size(&ms->device_memory->mr);
> > +    int64_t value = 0;
> > +
> > +    if (ms->device_memory) {
> > +        memory_region_size(&ms->device_memory->mr);

This was supposed to be:

        value = memory_region_size(&ms->device_memory->mr);

> > +    }
> >  
> >      visit_type_int(v, name, &value, errp);
> >  }
> > 
> 

-- 
Eduardo


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

* Re: [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
  2019-06-21  1:46   ` Eduardo Habkost
@ 2019-06-24  9:01     ` Igor Mammedov
  0 siblings, 0 replies; 5+ messages in thread
From: Igor Mammedov @ 2019-06-24  9:01 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, rth, qemu-devel, armbru, mst

On Thu, 20 Jun 2019 22:46:15 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Fri, Jun 21, 2019 at 02:29:29AM +0200, Paolo Bonzini wrote:
> > On 10/06/19 15:50, Igor Mammedov wrote:  
> > > QEMU will crash when device-memory-region-size property is read if ms->device_memory
> > > wasn't initialized yet.
> > > 
> > > Crash can be reproduced with:
> > >  $QEMU -preconfig -qmp unix:qmp_socket,server,nowait &
> > >  ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size
> > > 
> > > Instead of crashing return 0 if ms->device_memory hasn't been initialized.  
> > 
> > This patch breaks bios-tables-test /x86_64/acpi/piix64/cpuhp:
> > 
> > acpi-test: Warning! SRAT binary file mismatch. Actual [aml:/tmp/aml-RIFK3Z], Expected [aml:tests/data/acpi/pc/SRAT.memhp].
> > acpi-test: Warning! SRAT mismatch. Actual [asl:/tmp/asl-TLFK3Z.dsl, aml:/tmp/aml-RIFK3Z], Expected [asl:/tmp/asl-JL5J3Z.dsl, aml:tests/data/acpi/pc/SRAT.memhp].
> > **
> > ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)
> > ERROR - Bail out! ERROR:/home/pbonzini/work/upstream/qemu/tests/bios-tables-test.c:434:test_acpi_asl: assertion failed: (all_tables_match)
> > 
> > So I'm removing it from the pull request.  
> 
> The patch makes all memory regions return 0 as its size.
Indeed, sorry for not testing before posting patch.
I'll send properly tested v2.

> 
> 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > > v2:
> > >   add reproducer to commit message
> > >    (Markus Armbruster <armbru@redhat.com>)
> > > 
> > >  hw/i386/pc.c | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > > index edc240b..1b7ead9 100644
> > > --- a/hw/i386/pc.c
> > > +++ b/hw/i386/pc.c
> > > @@ -2459,7 +2459,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
> > >                                           Error **errp)
> > >  {
> > >      MachineState *ms = MACHINE(obj);
> > > -    int64_t value = memory_region_size(&ms->device_memory->mr);
> > > +    int64_t value = 0;
> > > +
> > > +    if (ms->device_memory) {
> > > +        memory_region_size(&ms->device_memory->mr);  
> 
> This was supposed to be:
> 
>         value = memory_region_size(&ms->device_memory->mr);
> 
> > > +    }
> > >  
> > >      visit_type_int(v, name, &value, errp);
> > >  }
> > >   
> >   
> 



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

end of thread, other threads:[~2019-06-24  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 13:50 [Qemu-devel] [PATCH] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() Igor Mammedov
2019-06-10 13:57 ` Paolo Bonzini
2019-06-21  0:29 ` Paolo Bonzini
2019-06-21  1:46   ` Eduardo Habkost
2019-06-24  9:01     ` Igor Mammedov

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).