Skip to contentSkip to conversation

hw/i386/pc: fix possible segment fault for port92_write

PATCH Superseded liguang 3 participants 5 messages Mar 22, 2013 – Mar 26, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH 1/1 hw/i386/pc: fix possible segment fault for port92_write

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/i386/pc.c +2 -1
index ed7d9ba..a0e8ee0 100644
@@ -440,7 +440,8 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out)
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);
     if (val & 1) {
         qemu_system_reset_request();
     }
Signature · 1 line
1.7.2.5
#1 lore raw

Il 22/03/2013 10:12, liguang ha scritto:

Quoted 18 lines

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/i386/pc.c +0 -0
index ed7d9ba..a0e8ee0 100644

hw/i386/pc.c static void port92_write(void *opaque, hwaddr addr, uint64_t val, · line 447

Quoted 9 lines
hw/i386/pc.c +2 -1
@@ -440,7 +440,8 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out)
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);
     if (val & 1) {
         qemu_system_reset_request();
     }

Unfortunately, this is a very common problem. The correct fix is to change port92 to use the GPIO mechanism instead.

Paolo

author
#2 lore raw
Quoted 19 lines · 在 2013-03-22五的 12:07 +0100,Paolo Bonzini写道:

Il 22/03/2013 10:12, liguang ha scritto:

Quoted 18 lines

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/i386/pc.c +0 -0
index ed7d9ba..a0e8ee0 100644
@@ -440,7 +440,8 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
Quoted 13 lines

hw/i386/pc.c static void port92_write(void *opaque, hwaddr addr, uint64_t val, · line 447

Quoted 9 lines
hw/i386/pc.c +2 -1
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out)
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);
     if (val & 1) {
         qemu_system_reset_request();
     }

Unfortunately, this is a very common problem. The correct fix is to change port92 to use the GPIO mechanism instead.

Sorry, Paolo,
I'm not so familiar with 'GPIO mechanism',
can you specify more?

Thanks!

#3 lore raw
In reply to liguang

Am 22.03.2013 10:12, schrieb liguang:

Quoted 17 lines

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/i386/pc.c +0 -0
index ed7d9ba..a0e8ee0 100644

hw/i386/pc.c static void port92_write(void *opaque, hwaddr addr, uint64_t val, · line 444

Quoted 6 lines
hw/i386/pc.c +2 -1
@@ -440,7 +440,8 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out)
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);

Missing braces.

But I think it would be better to proceed with my QOM'ification [1] and return an Error on realize here since these IRQs don't change while realized and qdev init doesn't allow to return a textual error.

Andreas

[1] https://github.com/afaerber/qemu-cpu/commits/realize-isa

Quoted 4 lines
hw/i386/pc.c +0 -0
     if (val & 1) {
         qemu_system_reset_request();
     }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#4 lore raw
Quoted 19 lines · 在 2013-03-22五的 12:20 +0100,Andreas Färber写道:

Am 22.03.2013 10:12, schrieb liguang:

Quoted 18 lines

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/i386/pc.c +0 -0
index ed7d9ba..a0e8ee0 100644
@@ -440,7 +440,8 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
Quoted 7 lines

hw/i386/pc.c static void port92_write(void *opaque, hwaddr addr, uint64_t val, · line 444

Quoted 5 lines
hw/i386/pc.c +2 -1
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out)
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);

Missing braces.

Yes, Thanks!

Quoted 15 lines

But I think it would be better to proceed with my QOM'ification [1] and return an Error on realize here since these IRQs don't change while realized and qdev init doesn't allow to return a textual error.

Andreas

[1] https://github.com/afaerber/qemu-cpu/commits/realize-isa

Quoted 4 lines
hw/i386/pc.c +0 -0
     if (val & 1) {
         qemu_system_reset_request();
     }