From nobody Sun Feb 8 19:54:56 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DF35258ECB for ; Thu, 15 Jan 2026 01:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768439649; cv=none; b=PYgDF0l2TLJki1PtFP0NvRc4uZTPF75Z3YftkRTGYfn5VHTIsFIqZRRe0c/aesgti2bCOrt0bGrXtQSUagoNA8iiF4B0intsJp/CisQoiEWZv5sroKXMdNEDVPX+JC9xNwKY+k4yYFFpH53FsuJt57mS/M9bgbpebys0vxb4lvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768439649; c=relaxed/simple; bh=FhTOmmi6gnSSLVnyBr/gDx4uaArPGwCmaY2IJPjijuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PExkakUPUvYK0QVOQebkuvFh++hu6mEEtSl5TMhK9UQIxGBL7m67ppcQPgXBg0b6fflXCDxav8SrTUYmW0iCUrUMfvs0zZzORsycC4DT7jR2J1oCXdvCx7UHpFMUNhw93syZm56kuJQz/dnpKdv5aFfueVYEaXB8ac4Y7W3Zbos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FtgnqG4P; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FtgnqG4P" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768439638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QrdFcAsC8FiX1Peqg4gjJ2+Ki+Tm5p09T6ZYsAHHLkU=; b=FtgnqG4PjkcBNQ7yhBSvavt2zRWIuveyzqyN1ELxbTsxzNf7TW2lvkk/kxDzn7nQGr34sX +ELLYC1+Mn+c5SnG3bA1px00lM2B02aLyxOVeh+WoK9me9hy4akZViEAQmjQ5XBGgPKiav Pv9zYM5DMsSi5GuJJZL+Qm8lGseemio= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , stable@vger.kernel.org Subject: [PATCH v4 17/26] KVM: nSVM: Add missing consistency check for hCR0.PG and NP_ENABLE Date: Thu, 15 Jan 2026 01:13:03 +0000 Message-ID: <20260115011312.3675857-18-yosry.ahmed@linux.dev> In-Reply-To: <20260115011312.3675857-1-yosry.ahmed@linux.dev> References: <20260115011312.3675857-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT From the APM Volume #2, 15.25.3 (24593=E2=80=94Rev. 3.42=E2=80=94March 2024= ): If VMRUN is executed with hCR0.PG cleared to zero and NP_ENABLE set to 1 , VMRUN terminates with #VMEXIT(VMEXIT_INVALID). Add the consistency check by plumbing L1's CR0 to nested_vmcb_check_controls(). Fixes: 4b16184c1cca ("KVM: SVM: Initialize Nested Nested MMU context on VMR= UN") Cc: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index eb4a633a668d..72db46b5126d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -343,7 +343,8 @@ static bool nested_svm_check_bitmap_pa(struct kvm_vcpu = *vcpu, u64 pa, u32 size) } =20 static bool nested_vmcb_check_controls(struct kvm_vcpu *vcpu, - struct vmcb_ctrl_area_cached *control) + struct vmcb_ctrl_area_cached *control, + unsigned long l1_cr0) { if (CC(!vmcb12_is_intercept(control, INTERCEPT_VMRUN))) return false; @@ -354,6 +355,8 @@ static bool nested_vmcb_check_controls(struct kvm_vcpu = *vcpu, if (nested_npt_enabled(to_svm(vcpu))) { if (CC(!kvm_vcpu_is_legal_gpa(vcpu, control->nested_cr3))) return false; + if (CC(!(l1_cr0 & X86_CR0_PG))) + return false; } =20 if (CC(!nested_svm_check_bitmap_pa(vcpu, control->msrpm_base_pa, @@ -951,7 +954,8 @@ int enter_svm_guest_mode(struct kvm_vcpu *vcpu, u64 vmc= b12_gpa, enter_guest_mode(vcpu); =20 if (!nested_vmcb_check_save(vcpu, &svm->nested.save) || - !nested_vmcb_check_controls(vcpu, &svm->nested.ctl)) + !nested_vmcb_check_controls(vcpu, &svm->nested.ctl, + svm->vmcb01.ptr->save.cr0)) return -EINVAL; =20 if (nested_npt_enabled(svm)) @@ -1882,7 +1886,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, =20 ret =3D -EINVAL; __nested_copy_vmcb_control_to_cache(vcpu, &ctl_cached, ctl); - if (!nested_vmcb_check_controls(vcpu, &ctl_cached)) + /* 'save' contains L1 state saved from before VMRUN */ + if (!nested_vmcb_check_controls(vcpu, &ctl_cached, save->cr0)) goto out_free; =20 /* --=20 2.52.0.457.g6b5491de43-goog