From patchwork Mon Dec 17 02:43:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10732675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44D5F14E5 for ; Mon, 17 Dec 2018 02:43:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 372A729C8F for ; Mon, 17 Dec 2018 02:43:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2946E29CC9; Mon, 17 Dec 2018 02:43:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D32229C8F for ; Mon, 17 Dec 2018 02:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbeLQCn3 (ORCPT ); Sun, 16 Dec 2018 21:43:29 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42587 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbeLQCn2 (ORCPT ); Sun, 16 Dec 2018 21:43:28 -0500 Received: by mail-pg1-f196.google.com with SMTP id d72so5353390pga.9; Sun, 16 Dec 2018 18:43:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=M8+ummLCtRqGGD8qCTL9INcTH4UiAYtPFKbsoKJo8KU=; b=s1JLes0TitLirAJe510U8q5Fb3cIFdcrLMnqYcF82S19osHkxxD9rOgJnmP+kJMDHS kYh2UU73qP4nP8JH3tLwKsPsB6O10y9u/JtE7fQ1amvuZlCOU0VC4olleRIXgnLBvefm yTnVjq4Nu/vbcAezT1s5yt+xD717nybyh8WU59fUY7pk1DFddBneKYeYnAmKE44d0SM0 QauInP14/d267wcVmhOfW3Ei1t5ovWXNp6k6/pC/WbFIIdcbNTNeVrXUtdZMVU0yuAkQ K4MDBZtCUrFwB7zFVj2scWuW/nZqjV0raqy1l9RKl2AEpajSEP63gatteC9qWpomEov7 BQEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=M8+ummLCtRqGGD8qCTL9INcTH4UiAYtPFKbsoKJo8KU=; b=EhLb/Bm6/0im71LxvIrJbl/SIhOr1dA778mSEdtJOzeqolQcSY/c626xR0YRjOiAyP ZeFzakDfBULQn1WCXg+vdkvbSEOmYnxmlLQlOh9+MVNzM4ccfg/07z9TSSbKeZWJrkl+ OLH0TtFF77Qg/5aY7gaZmwItQ+PXGVB3LhzzgSeN2C6UWygylbTYfijl4lYVJ+1WTiAx gqCHhfKlrfZ6T9+7+F/xaMTlKp4jQfPJbxTAIVssPLZ9reNETiOyxHvkyRrNhaS6gX8N uUjpmIAAk11tklTK4pj2afKFVyK0qClzzu42DLQ8rZMkxnulIYr/LviGO4QP8MIsYNOP Lq4Q== X-Gm-Message-State: AA+aEWYsr+kHYr+sHJOwTRKaekZZqfU1YrTrVh8Z5uUic37+r7BbBsHP 4vKwwRxpE2r9l3Ir122M5t8zUYa0 X-Google-Smtp-Source: AFSGD/Xo+u9J9RmVMGCm7CW8KKLtreC6u8eTGNaQVC9kBYRIbUHpCWYu78VPenqCrAWUiFokr5BGdQ== X-Received: by 2002:a62:55c4:: with SMTP id j187mr7164226pfb.129.1545014607625; Sun, 16 Dec 2018 18:43:27 -0800 (PST) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id k191sm13088466pgd.9.2018.12.16.18.43.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 16 Dec 2018 18:43:27 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Subject: [PATCH] KVM: X86: Fix NULL deref in vcpu_scan_ioapic Date: Mon, 17 Dec 2018 10:43:23 +0800 Message-Id: <1545014603-4109-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li Reported by syzkaller: CPU: 1 PID: 5962 Comm: syz-executor118 Not tainted 4.20.0-rc6+ #374 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:kvm_apic_hw_enabled arch/x86/kvm/lapic.h:169 [inline] RIP: 0010:vcpu_scan_ioapic arch/x86/kvm/x86.c:7449 [inline] RIP: 0010:vcpu_enter_guest arch/x86/kvm/x86.c:7602 [inline] RIP: 0010:vcpu_run arch/x86/kvm/x86.c:7874 [inline] RIP: 0010:kvm_arch_vcpu_ioctl_run+0x5296/0x7320 arch/x86/kvm/x86.c:8074 Call Trace: kvm_vcpu_ioctl+0x5c8/0x1150 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2596 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:509 [inline] do_vfs_ioctl+0x1de/0x1790 fs/ioctl.c:696 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:713 __do_sys_ioctl fs/ioctl.c:720 [inline] __se_sys_ioctl fs/ioctl.c:718 [inline] __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe The reason is that the testcase writes hyperv synic HV_X64_MSR_SINT14 msr and triggers scan ioapic logic to load synic vectors into EOI exit bitmap. However, irqchip is not initialized by this simple testcase, ioapic/apic objects should not be accessed. This patch fixes it by also considering whether or not apic is present. Reported-by: syzbot+39810e6c400efadfef71@syzkaller.appspotmail.com Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4f786fc..c7c1197 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7510,7 +7510,7 @@ void kvm_make_scan_ioapic_request(struct kvm *kvm) static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu) { - if (!kvm_apic_hw_enabled(vcpu->arch.apic)) + if (!kvm_apic_present(vcpu)) return; bitmap_zero(vcpu->arch.ioapic_handled_vectors, 256);