Re: [PATCH v2 2/5] KVM: nVMX/nSVM: check unconditionally whether CR3 is valid

From: Yosry Ahmed

Date: Wed Nov 25 2026 - 16:35:31 EST


On Tue, Nov 17, 2026 at 1:09 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> From: Paolo Bonzini <pbonzini@xxxxxxxxxx>
>
> nested_vmcb_check_save() checks CR3 legality only if long mode is active,
> but it really needs to be checked in all cases - the check uses must be
> zero bits of the host, and indeed nested_svm_load_cr3() later will
> reject illegal CR3 in every mode. Move the check earlier, and thus out
> of nested_svm_load_cr3().
>
> Likewise for nested_vmx_load_cr3() and nested_vmx_check_guest_state().

The code looks good, but I think the changelog needs to clarify two things:

1. That nested_vmx_load_cr3() is also used for host_cr3, but that is
already checked on nested VM-Enter and cannot change in the meantime.
2. That nested_svm_load_cr3() also checks L2's CR3 in the restore
path, but that is already checked in svm_set_nested_state() (i.e. in
patch 1).

>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> Tested-by: syzbot@xxxxxxxxxxxxxxxxxxxxxxxxx
> Cc: stable@xxxxxxxxxxxxxxx
> [sean: tag for stable]
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Reviewed-by: Yosry Ahmed <yosry@xxxxxxxxxx>