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