Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp295849pxx; Wed, 28 Oct 2020 05:15:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtLHUCMEPtcFnzsbwW4ts4IKdZkFhLpwZ+oGwFTZAZcoxgfHx9iBZyF6FkH2vf7r++zLpb X-Received: by 2002:a05:6402:17ac:: with SMTP id j12mr3899954edy.31.1603887353675; Wed, 28 Oct 2020 05:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603887353; cv=none; d=google.com; s=arc-20160816; b=tTQR6sGVJZDQ29+iVvsTs2unxoG87RtrT9pIqarXK/4b9wVmCBX+SFuFQAumDz8+75 EbA0/o9dD1gqyaleuVb9XrUu7K2Mq0mCFNsf1UH7P040d+qC1nD4Um9Z6Lmz54HWEtpW QC2HU7+ZQJbNNpiM4dUh/7Qutik5Ak1H6v7jigcaZNhVAlaeTXkklifauHY2CE+mjW4R FqLD67j2crnJmn+Bknf8U3D80cna2701FXzucn84GvYFheGngpHIXcDsAz5+dxWNpMC/ kn1Tg8qzUJuMP251sdayLoyEDWhVBVwz5+453ukj/0wSP13o/Fxer//5Ogray01N1oC7 mEsQ== 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=HFEwtJau5oJEqO+qcEv/HVoq31pzkv2n/mNrhSx8tNk=; b=qvyK/nCenJdMH0Hj62uPGerWA/5UL8x1U0IpXF+lsh/pHtgo0btrv5+0s0Lz9j0vQ2 D4vZcKXOzLxtbjSZxeGvQi3wuB2YxfJu0NwqkZB2QpyVfw32VpemGBlX/dGIm0MfNLjR mTM3hzuLHuY/HPpe0HFFb+cTBxaJIHuVDoWyBJrggPfj+qTYfsdDkeaw6M3p+dHgeA5r b8+IINMUckhp862OcwA/AmgPxT8XDPF2QvxvW1C9R7N1nirgQA76jZIGRfTaCpk2dOq9 Kq0l++7NCUawmwEcSdGHhdRSNvztGtTCPDo0/GAP/2gWPj/r1ZoEVYiUqjTzb0qlx1LV FLXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A5KO8SfV; 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 z8si2802677eju.267.2020.10.28.05.15.30; Wed, 28 Oct 2020 05:15:53 -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=A5KO8SfV; 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 S1796322AbgJ0PRX (ORCPT + 99 others); Tue, 27 Oct 2020 11:17:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1794767AbgJ0PN0 (ORCPT ); Tue, 27 Oct 2020 11:13:26 -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 DDF8421D41; Tue, 27 Oct 2020 15:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811605; bh=gZ5hX7BiaGGoFJsUDs4rmUHdZt47slybaLRfnGmle74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A5KO8SfVDe636sGkOJ245DsBQrlMIq/9J3Ww9nrt//EV50HEeHJxcOGKVui8kdkJx u04i/VZTS5mEAsQT8YY83wfWHRw+IMjSiBaqFmGop/DVnfFVgCGCQ7s3Q/VigDBFA5 O+ePeQIPV/Ft2Bt6hcQblI4dtPnA5H0OhLwcTSC0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Bonzini , Alex Williamson , Vitaly Kuznetsov , Sasha Levin Subject: [PATCH 5.8 521/633] KVM: ioapic: break infinite recursion on lazy EOI Date: Tue, 27 Oct 2020 14:54:24 +0100 Message-Id: <20201027135547.206660307@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: Vitaly Kuznetsov [ Upstream commit 77377064c3a94911339f13ce113b3abf265e06da ] During shutdown the IOAPIC trigger mode is reset to edge triggered while the vfio-pci INTx is still registered with a resampler. This allows us to get into an infinite loop: ioapic_set_irq -> ioapic_lazy_update_eoi -> kvm_ioapic_update_eoi_one -> kvm_notify_acked_irq -> kvm_notify_acked_gsi -> (via irq_acked fn ptr) irqfd_resampler_ack -> kvm_set_irq -> (via set fn ptr) kvm_set_ioapic_irq -> kvm_ioapic_set_irq -> ioapic_set_irq Commit 8be8f932e3db ("kvm: ioapic: Restrict lazy EOI update to edge-triggered interrupts", 2020-05-04) acknowledges that this recursion loop exists and tries to avoid it at the call to ioapic_lazy_update_eoi, but at this point the scenario is already set, we have an edge interrupt with resampler on the same gsi. Fortunately, the only user of irq ack notifiers (in addition to resamplefd) is i8254 timer interrupt reinjection. These are edge-triggered, so in principle they would need the call to kvm_ioapic_update_eoi_one from ioapic_lazy_update_eoi, but they already disable AVIC(*), so they don't need the lazy EOI behavior. Therefore, remove the call to kvm_ioapic_update_eoi_one from ioapic_lazy_update_eoi. This fixes CVE-2020-27152. Note that this issue cannot happen with SR-IOV assigned devices because virtual functions do not have INTx, only MSI. Fixes: f458d039db7e ("kvm: ioapic: Lazy update IOAPIC EOI") Suggested-by: Paolo Bonzini Tested-by: Alex Williamson Signed-off-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/ioapic.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index d057376bd3d33..698969e18fe35 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -197,12 +197,9 @@ static void ioapic_lazy_update_eoi(struct kvm_ioapic *ioapic, int irq) /* * If no longer has pending EOI in LAPICs, update - * EOI for this vetor. + * EOI for this vector. */ rtc_irq_eoi(ioapic, vcpu, entry->fields.vector); - kvm_ioapic_update_eoi_one(vcpu, ioapic, - entry->fields.trig_mode, - irq); break; } } -- 2.25.1