Re: [PATCH v1 1/4] KVM: arm64: Validate the host-provided vgic model in pKVM

Fuad Tabba <[email protected]> Thu, 6 Aug 2026 11:40:48 +0100
Newsgroups dev.linux.lists.kvmarm,dev.linux.lists.sashiko-reviews
Message-ID <CA+EHjTzAqGbjVvPSz0nKZzTmH33tJxi2htegrAzRNSjENPcmBw@mail.gmail.com>
On Thu, 6 Aug 2026 at 11:32, <[email protected]> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
> Pre-existing issues:
> - [Critical] Unconditional copy of the host's mdcr_el2 to the protected VM's mdcr_el2 allows the host to reconfigure the guest's secure trap environment.

Coming soon in the second pKVM series.

> - [Medium] The patch fails to sanitize the explicit `__vgic_v5_save_apr` and `__vgic_v5_restore_vmcr_apr` hypercalls, allowing a malicious host to still panic the hypervisor on GICv3 machines.

Patch 2 of this series fixes it.

/fuad

> --
>
> --- Patch [1]: [PATCH v1 1/4] KVM: arm64: Validate the host-provided vgic model in pKVM ---
> commit 3364f007874647c1650c3fc747633d9c5c9b87de
> Author: Fuad Tabba <[email protected]>
>
> KVM: arm64: Validate the host-provided vgic model in pKVM
>
> This commit validates the host-provided vgic_model during initialization
> of a protected VM, ensuring only GICv2 and GICv3 models are permitted.
> This prevents a malicious host from causing a hypervisor panic by setting
> the model to GICv5 on a GICv3 machine.
>
> > diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> > index 24d6f164129ac..59bb15efdca42 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> > @@ -340,13 +340,25 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
> >  {
>
> [ ... ]
>
> > -     /* Preserve the vgic model so that GICv3 emulation works */
> > -     hyp_vm->kvm.arch.vgic.vgic_model = host_kvm->arch.vgic.vgic_model;
> > +     /*
> > +      * Preserve the vgic model for GICv3 emulation, but only what pKVM can
> > +      * run: the GICv5 world switch touches registers UNDEFINED at EL2
> > +      * without FEAT_GCIE. 0 is not a valid kvm_device_type: "no vgic".
> > +      */
> > +     switch (vgic_model) {
> > +     case KVM_DEV_TYPE_ARM_VGIC_V2:
> > +     case KVM_DEV_TYPE_ARM_VGIC_V3:
> > +             break;
> > +     default:
> > +             vgic_model = 0;
> > +     }
> > +     hyp_vm->kvm.arch.vgic.vgic_model = vgic_model;
>
> [Severity: Medium]
> This is a pre-existing issue, but does this validation fully prevent a
> malicious host from triggering a GICv5 panic?
>
> Even with the model restricted here, the explicit GICv5 hypercalls
> remain unconditionally exposed in the always-on band:
>
> arch/arm64/kvm/hyp/nvhe/hyp-main.c:
> static void handle___vgic_v5_save_apr(struct kvm_cpu_context *host_ctxt)
> {
>         DECLARE_REG(struct vgic_v5_cpu_if *, cpu_if, host_ctxt, 1);
>
>         __vgic_v5_save_apr(kern_hyp_va(cpu_if));
> }
>
> static void handle___vgic_v5_restore_vmcr_apr(struct kvm_cpu_context *host_ctxt)
> {
>         DECLARE_REG(struct vgic_v5_cpu_if *, cpu_if, host_ctxt, 1);
>
>         __vgic_v5_restore_vmcr_apr(kern_hyp_va(cpu_if));
> }
>
> Can a compromised host still bypass this vgic_model sanitization by
> directly executing the HVC instruction for
> __KVM_HOST_SMCCC_FUNC___vgic_v5_save_apr or __vgic_v5_restore_vmcr_apr?
>
> If these directly access GICv5 registers, wouldn't this still trigger an
> UNDEFINED exception on machines without FEAT_GCIE?
>
> >       /* No restrictions for non-protected VMs. */
> >       if (!kvm_vm_is_protected(kvm)) {
>
> [ ... ]
>
> Additionally, while reviewing the protected guest state handling, I noticed
> another potential issue in the hypervisor main loop:
>
> arch/arm64/kvm/hyp/nvhe/hyp-main.c:flush_hyp_vcpu() {
>         ...
>         /* __hyp_running_vcpu must be NULL in a guest context. */
>         hyp_vcpu->vcpu.arch.ctxt.__hyp_running_vcpu = NULL;
>
>         hyp_vcpu->vcpu.arch.mdcr_el2    = host_vcpu->arch.mdcr_el2;
>         /*
>          * HCR_EL2.VSE is host-owned (a pending virtual SError to inject), not a
>         ...
> }
>
> [Severity: Critical]
> This isn't a bug introduced by this patch, but does this unconditional
> assignment allow the untrusted host to clobber the securely initialized
> MDCR_EL2 configuration of protected guests on every VCPU entry?
>
> Since flush_hyp_vcpu() overwrites the hyp vCPU's mdcr_el2 with the
> host-controlled host_vcpu->arch.mdcr_el2, could a compromised host use
> this to reconfigure the performance monitor (TPM) and debug (TDA/TDE)
> trap environment of a protected guest?
>
> --
> Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
>