Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3779090pxt; Tue, 10 Aug 2021 11:07:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydh6tkaxwW7ts/wC/KQwnV3eDTNZvp3Aue2lryyBGWMwan2CDFlMdGELHJgBFyOllnwoNV X-Received: by 2002:a05:6402:4cf:: with SMTP id n15mr6473517edw.269.1628618838823; Tue, 10 Aug 2021 11:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628618838; cv=none; d=google.com; s=arc-20160816; b=eGS2HHWP9Vy4K3erHB1MySJ0TT9scXg6e01QBeK8X/yoXCAya6T1gHNmRUcBsH3f3J rEZclLltrPS3ab8mZfIVrnvX5aODqVkWmJ4zDgRSc8pTkBCGpsc+Ja8PQENHuO9Nb0+g EjBH+9ED0//KURkZMdJuN5l5y7FfpzaRbArAMzo0vOhqpV1iJt5+d6qfd90/I9flRVIp iJzaCZSleo2QuGy01C2olPkikiHTuk8e4IkmwV8iMjH0SmVIFbTkLncJvNKBRHWNWOJj MKVkkw7KS4gCHQ7o8EJYWODNnDxEOZhIOHZlOQw7iqwBLlwat75Ldf2vPv7FtegBP7WR EbBw== 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=IFxcyw+1EE7BPnUYRku//ibr99LpsdbqaN7pWpqYdxI=; b=G4yZV5JTaENxBT8NWIeISEVCz0LX/4QW970Kh1ipA1FzI+BLScTYAMMnwdv91RiOR/ BWvJVVCPzWKLAlA89tialSSs3pGSYEwfPeBDN3D+8/2U6gk1ZIOrSHqPMkNA7zWeEvEb PuNdxT6GombAMJeNdAcQLIrcM7kGeAKUGwtNG7J+Eiw7VvgMKd+7bEk+U/8EowRP/YME 8Nb0PdIlY4Nmt9Sq4BTw1Hze53OU60os9BS3kNTLY0QG3mJO/LAiAb5BvN5vX4NptykU /fldBSXAK3x9nrHxyXynWwG3lf3+Yi/8KesM56oxTa31+vZNhckEMC6xT0kHwjNalAGa ij5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qhHwChvp; 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=pass (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 o4si22633065edi.284.2021.08.10.11.06.54; Tue, 10 Aug 2021 11:07:18 -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=@linuxfoundation.org header.s=korg header.b=qhHwChvp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235419AbhHJSFe (ORCPT + 99 others); Tue, 10 Aug 2021 14:05:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:34364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236426AbhHJSBu (ORCPT ); Tue, 10 Aug 2021 14:01:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 029E7613AC; Tue, 10 Aug 2021 17:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617639; bh=FtSMuK5Q9Khr2WcBADPBZ2Ua96i+5A0LYRmsTDlqJ+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qhHwChvp1EcqB2JsVfUwdo45yQ9kvcTtPzpr+udZ/jyeMkvr5NMu6vg1juestDRpg uirkOJe3BRWRhGIOoLgE1gf1Ev7R432G83/bslCWrhUjG/cgndv8Iocb6v6FnmP6RP +UTUlvzu/g0V8gFz6C26WX2ZRYJa3hS/apuUGYHc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Brijesh Singh , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.13 148/175] KVM: SVM: Fix off-by-one indexing when nullifying last used SEV VMCB Date: Tue, 10 Aug 2021 19:30:56 +0200 Message-Id: <20210810173005.838432230@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810173000.928681411@linuxfoundation.org> References: <20210810173000.928681411@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: Sean Christopherson commit 179c6c27bf487273652efc99acd3ba512a23c137 upstream. Use the raw ASID, not ASID-1, when nullifying the last used VMCB when freeing an SEV ASID. The consumer, pre_sev_run(), indexes the array by the raw ASID, thus KVM could get a false negative when checking for a different VMCB if KVM manages to reallocate the same ASID+VMCB combo for a new VM. Note, this cannot cause a functional issue _in the current code_, as pre_sev_run() also checks which pCPU last did VMRUN for the vCPU, and last_vmentry_cpu is initialized to -1 during vCPU creation, i.e. is guaranteed to mismatch on the first VMRUN. However, prior to commit 8a14fe4f0c54 ("kvm: x86: Move last_cpu into kvm_vcpu_arch as last_vmentry_cpu"), SVM tracked pCPU on its own and zero-initialized the last_cpu variable. Thus it's theoretically possible that older versions of KVM could miss a TLB flush if the first VMRUN is on pCPU0 and the ASID and VMCB exactly match those of a prior VM. Fixes: 70cd94e60c73 ("KVM: SVM: VMRUN should use associated ASID when SEV is enabled") Cc: Tom Lendacky Cc: Brijesh Singh Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -188,7 +188,7 @@ static void sev_asid_free(struct kvm_sev for_each_possible_cpu(cpu) { sd = per_cpu(svm_data, cpu); - sd->sev_vmcbs[pos] = NULL; + sd->sev_vmcbs[sev->asid] = NULL; } mutex_unlock(&sev_bitmap_lock);