From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63A9FC433EF for ; Fri, 25 Mar 2022 13:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354194AbiCYNXX (ORCPT ); Fri, 25 Mar 2022 09:23:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244397AbiCYNXT (ORCPT ); Fri, 25 Mar 2022 09:23:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2EE46D1118 for ; Fri, 25 Mar 2022 06:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648214505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=jHB6BR0YbApCBzRoAgSeCurDpGlWHsYv9gOGQx13pb0=; b=HCtojQUB79HM6YbTwbR9LXuhMfUxK94cVsRieafH0p+yr3K6gnRp5pu/YYp04MXtqRorX4 Hnl6XYSWPA/9qZNVRX529DkS9HllXLaS4XVzi+1ma2wpXlmwRp2tbq/daEbIslaj92ds6U ANh7DBdp0JrV9PHXOutdOVAKYnDnY+0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-pQDQAainO_GMcwUfculRtg-1; Fri, 25 Mar 2022 09:21:43 -0400 X-MC-Unique: pQDQAainO_GMcwUfculRtg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 772D3866DF1; Fri, 25 Mar 2022 13:21:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FA622166B16; Fri, 25 Mar 2022 13:21:41 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , linux-kernel@vger.kernel.org Subject: [PATCH 0/3] KVM: x86: Prefent NULL prointer dereference in kvm_irq_delivery_to_apic_fast() Date: Fri, 25 Mar 2022 14:21:37 +0100 Message-Id: <20220325132140.25650-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Syzkaller found the following crash: general protection fault, probably for non-canonical address 0xdffffc0000000013: 0000 [#1] PREEMPT SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000098-0x000000000000009f] CPU: 1 PID: 679 Comm: syz-executor210 Not tainted 5.17.0-rc8 #6 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1~cloud0 04/01/2014 RIP: 0010:kvm_irq_delivery_to_apic_fast+0x3dd/0x670 arch/x86/kvm/lapic.c:995 ... Call Trace: kvm_irq_delivery_to_apic+0xb8/0x860 arch/x86/kvm/irq_comm.c:54 synic_set_irq+0x169/0x340 arch/x86/kvm/hyperv.c:463 synic_deliver_msg arch/x86/kvm/hyperv.c:770 [inline] stimer_send_msg arch/x86/kvm/hyperv.c:793 [inline] stimer_expiration arch/x86/kvm/hyperv.c:817 [inline] kvm_hv_process_stimers+0xe85/0x1210 arch/x86/kvm/hyperv.c:849 vcpu_enter_guest+0x37cb/0x4070 arch/x86/kvm/x86.c:9947 vcpu_run arch/x86/kvm/x86.c:10261 [inline] ... The immediate issue is that kvm_irq_delivery_to_apic_fast() dereferences 'src' while in some cases it can be NULL. A sentinel against this is added in PATCH2 of the series, however, the condition should not happen in the first place. synic_set_irq() should not call kvm_irq_delivery_to_apic() with 'shorthand = APIC_DEST_SELF' and 'vcpu->arch.apic == NULL' and this is also 'fixed' by PATCH1. The root cause of the problem, however, is that VMM was allowed to enable Hyper-V synthetic timer when IRQ chip wasn't created. This is fixed by PATCH3. Vitaly Kuznetsov (3): KVM: x86: Check lapic_in_kernel() before attempting to set a SynIC irq KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast() KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated arch/x86/kvm/hyperv.c | 12 +++++++++--- arch/x86/kvm/lapic.c | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) -- 2.35.1