From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK6rj-0007Wi-1i for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:04:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aK6rh-0003HT-PB for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:04:42 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:33387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK6rh-0003H9-J7 for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:04:41 -0500 Received: by mail-wm0-x22f.google.com with SMTP id f206so28856652wmf.0 for ; Fri, 15 Jan 2016 08:04:41 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 15 Jan 2016 17:04:19 +0100 Message-Id: <1452873871-138914-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1452873871-138914-1-git-send-email-pbonzini@redhat.com> References: <1452873871-138914-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL] i386: avoid null pointer dereference List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Prasad J Pandit From: Prasad J Pandit When I/O port write operation is called from hmp interface, 'current_cpu' remains null, as it is not called from cpu_exec() loop. This leads to a null pointer dereference in vapic_write routine. Add check to avoid it. Reported-by: Ling Liu Signed-off-by: Prasad J Pandit Message-Id: Signed-off-by: Paolo Bonzini --- hw/i386/kvmvapic.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c index c6d34b2..f0922da 100644 --- a/hw/i386/kvmvapic.c +++ b/hw/i386/kvmvapic.c @@ -634,13 +634,18 @@ static int vapic_prepare(VAPICROMState *s) static void vapic_write(void *opaque, hwaddr addr, uint64_t data, unsigned int size) { - CPUState *cs = current_cpu; - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - hwaddr rom_paddr; VAPICROMState *s = opaque; + X86CPU *cpu; + CPUX86State *env; + hwaddr rom_paddr; - cpu_synchronize_state(cs); + if (!current_cpu) { + return; + } + + cpu_synchronize_state(current_cpu); + cpu = X86_CPU(current_cpu); + env = &cpu->env; /* * The VAPIC supports two PIO-based hypercalls, both via port 0x7E. -- 1.8.3.1