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