Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fuad Tabba" <fuad.tabba@linux.dev>
Cc: "Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v6 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch
Date: Wed, 15 Jul 2026 08:37:07 +0000	[thread overview]
Message-ID: <20260715083708.68D2A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715081238.1891918-7-fuad.tabba@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] handle___vgic_v3_save_aprs silently overwrites host modifications to vgic_vmcr with a stale value.

Pre-existing issues:
- [Critical] The patch addresses the host-pointer trust vulnerability for GICv3 but leaves the identical vulnerability open for GICv5.
--

--- Patch [6]: [PATCH v6 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch ---
commit d47381d6be1828e59e8906a9d69d3c104d673dc3
Author: Marc Zyngier <maz@kernel.org>

KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch

This commit modifies the world switch to stop EL2 from dereferencing the host's
vgic_v3_cpu_if pointer wholesale. It copies only vgic_vmcr and active priority 
registers to the hyp-side state.

> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> index 45d717889f6ea..f3233ee343a39 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
[ ... ]
> @@ -508,16 +520,63 @@ static void handle___vgic_v3_init_lrs(struct kvm_cpu_context *host_ctxt)
>  
>  static void handle___vgic_v3_save_aprs(struct kvm_cpu_context *host_ctxt)
>  {
> -	DECLARE_REG(struct vgic_v3_cpu_if *, cpu_if, host_ctxt, 1);
> +	struct pkvm_hyp_vcpu *hyp_vcpu;
> +	struct kvm_vcpu *host_vcpu;
>  
> -	__vgic_v3_save_aprs(kern_hyp_va(cpu_if));
> +	host_vcpu = get_host_hyp_vcpus_from_vgic_v3_cpu_if(host_ctxt, 1,
> +							   &hyp_vcpu);
> +	if (!host_vcpu)
> +		return;
> +
> +	if (unlikely(hyp_vcpu)) {
> +		struct vgic_v3_cpu_if *hyp_cpu_if, *host_cpu_if;
> +		int i;
> +
> +		hyp_cpu_if = &hyp_vcpu->vcpu.arch.vgic_cpu.vgic_v3;
> +		__vgic_v3_save_aprs(hyp_cpu_if);
> +
> +		host_cpu_if = &host_vcpu->arch.vgic_cpu.vgic_v3;
> +		host_cpu_if->vgic_vmcr = hyp_cpu_if->vgic_vmcr;

[Severity: High]
Does this assignment overwrite host modifications to vgic_vmcr with a stale
value?

When userspace modifies a VMCR field (like SYS_ICC_PMR_EL1) via
KVM_SET_ONE_REG, the execution flow modifies the host state:

kvm_vcpu_ioctl()
  vcpu_load()
    handle___vgic_v3_restore_vmcr_aprs()
  // ioctl modifies host_cpu_if->vgic_vmcr
  vcpu_put()
    handle___vgic_v3_save_aprs()

Since __vgic_v3_save_aprs() does not read ICH_VMCR_EL2 from the hardware,
hyp_cpu_if->vgic_vmcr contains the old value. Does copying it back to
host_cpu_if->vgic_vmcr here cause the userspace changes to be lost?

> +		for (i = 0; i < ARRAY_SIZE(host_cpu_if->vgic_ap0r); i++) {
> +			host_cpu_if->vgic_ap0r[i] = hyp_cpu_if->vgic_ap0r[i];
> +			host_cpu_if->vgic_ap1r[i] = hyp_cpu_if->vgic_ap1r[i];
> +		}
> +	} else {
> +		__vgic_v3_save_aprs(&host_vcpu->arch.vgic_cpu.vgic_v3);
> +	}
>  }
[ ... ]

[Severity: Critical]
This is a pre-existing issue and was not introduced by the patch under review,
but does the same pattern remain open for GICv5?

Looking at handle___vgic_v5_save_apr():

arch/arm64/kvm/hyp/nvhe/hyp-main.c:handle___vgic_v5_save_apr() {
	DECLARE_REG(struct vgic_v5_cpu_if *, cpu_if, host_ctxt, 1);
	__vgic_v5_save_apr(kern_hyp_va(cpu_if));
}

And similarly in handle___vgic_v5_restore_vmcr_apr():

arch/arm64/kvm/hyp/nvhe/hyp-main.c:handle___vgic_v5_restore_vmcr_apr() {
	DECLARE_REG(struct vgic_v5_cpu_if *, cpu_if, host_ctxt, 1);
	__vgic_v5_restore_vmcr_apr(kern_hyp_va(cpu_if));
}

Since these handlers apply kern_hyp_va() to an untrusted host pointer without
validation, and kern_hyp_va() is idempotent for already-hyp-tagged pointers,
could a malicious host provide a pointer to EL2 private metadata?

Could this allow the host to arbitrarily read or write EL2 memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260715081238.1891918-1-fuad.tabba@linux.dev?part=6

  reply	other threads:[~2026-07-15  8:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  8:12 [PATCH v6 0/8] KVM: arm64: pKVM vCPU state management at EL2 Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 1/8] KVM: arm64: Extract MPIDR computation into a shared header Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 3/8] KVM: arm64: Factor out reusable vCPU reset helpers Fuad Tabba
2026-07-17 12:43   ` Steffen Eiden
2026-07-15  8:12 ` [PATCH v6 4/8] KVM: arm64: Move PSCI helper functions to a shared header Fuad Tabba
2026-07-15  8:24   ` sashiko-bot
2026-07-15  8:28     ` Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 5/8] KVM: arm64: Add host and hypervisor vCPU lookup primitives Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch Fuad Tabba
2026-07-15  8:37   ` sashiko-bot [this message]
2026-07-15  9:18     ` Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 7/8] KVM: arm64: Add primitives to flush/sync the VGIC state at EL2 Fuad Tabba
2026-07-15  8:12 ` [PATCH v6 8/8] KVM: arm64: Implement lazy vCPU state sync for non-protected guests Fuad Tabba
2026-07-15  8:34   ` sashiko-bot
2026-07-15  9:20     ` Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260715083708.68D2A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fuad.tabba@linux.dev \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox