f7153f0
From: Prasad J Pandit <address@hidden>
f7153f0
f7153f0
When I/O port write operation is called from hmp interface,
f7153f0
'current_cpu' remains null, as it is not called from cpu_exec()
f7153f0
loop. This leads to a null pointer dereference in vapic_write
f7153f0
routine. Add check to avoid it.
f7153f0
f7153f0
Reported-by: Ling Liu <address@hidden>
f7153f0
Signed-off-by: Prasad J Pandit <address@hidden>
f7153f0
Message-Id: <address@hidden>
f7153f0
Signed-off-by: Paolo Bonzini <address@hidden>
f7153f0
---
f7153f0
 hw/i386/kvmvapic.c | 15 ++++++++++-----
f7153f0
 1 file changed, 10 insertions(+), 5 deletions(-)
f7153f0
f7153f0
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
f7153f0
index c6d34b2..f0922da 100644
f7153f0
--- a/tools/qemu-xen/hw/i386/kvmvapic.c
f7153f0
+++ b/tools/qemu-xen/hw/i386/kvmvapic.c
f7153f0
@@ -634,13 +634,18 @@ static int vapic_prepare(VAPICROMState *s)
f7153f0
 static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
f7153f0
                         unsigned int size)
f7153f0
 {
f7153f0
-    CPUState *cs = current_cpu;
f7153f0
-    X86CPU *cpu = X86_CPU(cs);
f7153f0
-    CPUX86State *env = &cpu->env;
f7153f0
-    hwaddr rom_paddr;
f7153f0
     VAPICROMState *s = opaque;
f7153f0
+    X86CPU *cpu;
f7153f0
+    CPUX86State *env;
f7153f0
+    hwaddr rom_paddr;
f7153f0
 
f7153f0
-    cpu_synchronize_state(cs);
f7153f0
+    if (!current_cpu) {
f7153f0
+        return;
f7153f0
+    }
f7153f0
+
f7153f0
+    cpu_synchronize_state(current_cpu);
f7153f0
+    cpu = X86_CPU(current_cpu);
f7153f0
+    env = &cpu->env;
f7153f0
 
f7153f0
     /*
f7153f0
      * The VAPIC supports two PIO-based hypercalls, both via port 0x7E.
f7153f0
-- 
f7153f0
1.8.3.1