Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1217017pxx; Tue, 27 Oct 2020 10:58:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVwJ6Lqhr26FBfj1vfmXc7bL9pwilf+tvmy8QlbM6REf1j9id72XMNYQXPwkaxr7X3T84Z X-Received: by 2002:a50:fb18:: with SMTP id d24mr3595271edq.43.1603821491969; Tue, 27 Oct 2020 10:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603821491; cv=none; d=google.com; s=arc-20160816; b=vIQtWXNKjRncFIoJN8mcJlffXMGDeuqvArYZwS0n4UnsQqeG5+G1w/vZloIBk4ZT0T QbvzlHzviqxLo86aYAb74h6F1rlJAzPV6KMBYA2/hA0rPuQoQ1tUFwrH73/X5pTltxRl is6iABxJlZrw5rpwggy+0Xiz/TlATwl4LAr7v3/L7ArSCyfDd/deyTxomtpkM4MN2WMp YCQYnTJNDoiZ/44QTff15gegiPU9H/v4JruxBOcO8gVSfUYN7FizWGSk8lTJ4DXCCjXZ EYzPfvYxbxvS2NcO1aP/egWUBrwBtrLcgfQ2AJZ2/ON6lQhkAwd2WfzV0f5kEHp9zDl7 k2Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZJRAXVX9NWRx7wPCnVGFoaB0tozNCAsUnLHxyzh+CzU=; b=kYQQdQHJwFvL6JWmvWxhir5aNLdPL19xdPjdzm/82CxyHlMp/hcHbSDzmMcgJGrb+z lSKLo7inN2c2smfumpsXmwMPn88j/E9wybqB8B5AFuG/HXczsmnxNfXgQxNEYn6+KQp/ 7LVKo5BMpjRFrmoDbfAe0sZk6CbZSat78vQAb/e0O/BeQHwmIbOGNSlaQAxBKFUBMh3D /vdPuAQn3KObBUng/FPznA8xxDz7kzVONPyeh4FwobQoCu3zxaTixzBy0bsqtmfK60MI V99Haw09zzz+Y0vo/jLqJqvssOeKQ/E4AAOLMXDLY/8d2PvCXvoQiYTExci4EzuTN4ox 5w9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2Z/l2HSe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v25si1555955ejf.560.2020.10.27.10.57.48; Tue, 27 Oct 2020 10:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2Z/l2HSe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1819170AbgJ0R1r (ORCPT + 99 others); Tue, 27 Oct 2020 13:27:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:53298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775460AbgJ0Owu (ORCPT ); Tue, 27 Oct 2020 10:52:50 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2366A207DE; Tue, 27 Oct 2020 14:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810369; bh=G6sjFPSpnFl9sVmbWuuppn0Mwm534ZnHpRzoh1YpcxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Z/l2HSeOjOjJShaSnsoCyP1Y1qew6iEc5azaiP8hmZAw2iM+JX4PHVy2+imzmN4t Z+cu8pcbnIgq3OWZwLe6zyhvqC/mwF/yaxBE7FuctAzmbBi7VY9NUTEIleHvzK6F8R qeS1YGrmD+GePWVRB8xBJUJFGC5ebcMVL0iiy8fQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suravee Suthikulpanit , Paolo Bonzini Subject: [PATCH 5.8 074/633] KVM: SVM: Initialize prev_ga_tag before use Date: Tue, 27 Oct 2020 14:46:57 +0100 Message-Id: <20201027135526.165745210@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit commit f6426ab9c957e97418ac5b0466538792767b1738 upstream. The function amd_ir_set_vcpu_affinity makes use of the parameter struct amd_iommu_pi_data.prev_ga_tag to determine if it should delete struct amd_iommu_pi_data from a list when not running in AVIC mode. However, prev_ga_tag is initialized only when AVIC is enabled. The non-zero uninitialized value can cause unintended code path, which ends up making use of the struct vcpu_svm.ir_list and ir_list_lock without being initialized (since they are intended only for the AVIC case). This triggers NULL pointer dereference bug in the function vm_ir_list_del with the following call trace: svm_update_pi_irte+0x3c2/0x550 [kvm_amd] ? proc_create_single_data+0x41/0x50 kvm_arch_irq_bypass_add_producer+0x40/0x60 [kvm] __connect+0x5f/0xb0 [irqbypass] irq_bypass_register_producer+0xf8/0x120 [irqbypass] vfio_msi_set_vector_signal+0x1de/0x2d0 [vfio_pci] vfio_msi_set_block+0x77/0xe0 [vfio_pci] vfio_pci_set_msi_trigger+0x25c/0x2f0 [vfio_pci] vfio_pci_set_irqs_ioctl+0x88/0xb0 [vfio_pci] vfio_pci_ioctl+0x2ea/0xed0 [vfio_pci] ? alloc_file_pseudo+0xa5/0x100 vfio_device_fops_unl_ioctl+0x26/0x30 [vfio] ? vfio_device_fops_unl_ioctl+0x26/0x30 [vfio] __x64_sys_ioctl+0x96/0xd0 do_syscall_64+0x37/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Therefore, initialize prev_ga_tag to zero before use. This should be safe because ga_tag value 0 is invalid (see function avic_vm_init). Fixes: dfa20099e26e ("KVM: SVM: Refactor AVIC vcpu initialization into avic_init_vcpu()") Signed-off-by: Suravee Suthikulpanit Message-Id: <20201003232707.4662-1-suravee.suthikulpanit@amd.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/avic.c | 1 + 1 file changed, 1 insertion(+) --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -868,6 +868,7 @@ int svm_update_pi_irte(struct kvm *kvm, * - Tell IOMMU to use legacy mode for this interrupt. * - Retrieve ga_tag of prior interrupt remapping data. */ + pi.prev_ga_tag = 0; pi.is_guest_mode = false; ret = irq_set_vcpu_affinity(host_irq, &pi);