The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Validate the SVE vector length in pkvm_vcpu_init_sve()
@ 2026-08-18  9:31 Fuad Tabba
  2026-08-18 12:51 ` Marc Zyngier
  0 siblings, 1 reply; 2+ messages in thread
From: Fuad Tabba @ 2026-08-18  9:31 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton
  Cc: Joey Gouly, Steffen Eiden, Suzuki K Poulose, Zenghui Yu,
	Catalin Marinas, Will Deacon, Quentin Perret, Stefan Teodorescu,
	tabba, linux-arm-kernel, kvmarm, linux-kernel

pkvm_vcpu_init_sve() clamps only the upper bound of the host-provided
sve_max_vl, so an invalid vector length reaches sve_state_size_from_vl()
and the WARN_ON() there, which is fatal at EL2. The existing
!sve_state_size test rejects such a length, but only after the macro has
run.

Check sve_vl_valid() before deriving the state size. A valid length
cannot yield a zero size, so the !sve_state_size test goes with it.

Fixes: 5db1bef93342 ("KVM: arm64: Track SVE state in the hypervisor vcpu structure")
Reported-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---

Notes:
    Based on v7.2. Applies cleanly to kvmarm/next as well:
    pkvm_vcpu_init_sve() is identical on both.

 arch/arm64/kvm/hyp/nvhe/pkvm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
index 24d6f164129ac..095ebfce91b08 100644
--- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
+++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -460,14 +460,15 @@ static int pkvm_vcpu_init_sve(struct pkvm_hyp_vcpu *hyp_vcpu, struct kvm_vcpu *h
 
 	/* Limit guest vector length to the maximum supported by the host. */
 	sve_max_vl = min(READ_ONCE(host_vcpu->arch.sve_max_vl), kvm_host_sve_max_vl);
-	sve_state_size = sve_state_size_from_vl(sve_max_vl);
 	sve_state = kern_hyp_va(READ_ONCE(host_vcpu->arch.sve_state));
 
-	if (!sve_state || !sve_state_size) {
+	if (!sve_vl_valid(sve_max_vl) || !sve_state) {
 		ret = -EINVAL;
 		goto err;
 	}
 
+	sve_state_size = sve_state_size_from_vl(sve_max_vl);
+
 	ret = hyp_pin_shared_mem(sve_state, sve_state + sve_state_size);
 	if (ret)
 		goto err;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: arm64: Validate the SVE vector length in pkvm_vcpu_init_sve()
  2026-08-18  9:31 [PATCH] KVM: arm64: Validate the SVE vector length in pkvm_vcpu_init_sve() Fuad Tabba
@ 2026-08-18 12:51 ` Marc Zyngier
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Zyngier @ 2026-08-18 12:51 UTC (permalink / raw)
  To: Fuad Tabba
  Cc: Oliver Upton, Joey Gouly, Steffen Eiden, Suzuki K Poulose,
	Zenghui Yu, Catalin Marinas, Will Deacon, Quentin Perret,
	Stefan Teodorescu, tabba, linux-arm-kernel, kvmarm, linux-kernel

On Tue, 18 Aug 2026 10:31:17 +0100,
Fuad Tabba <fuad.tabba@linux.dev> wrote:
> 
> pkvm_vcpu_init_sve() clamps only the upper bound of the host-provided
> sve_max_vl, so an invalid vector length reaches sve_state_size_from_vl()
> and the WARN_ON() there, which is fatal at EL2. The existing
> !sve_state_size test rejects such a length, but only after the macro has
> run.
> 
> Check sve_vl_valid() before deriving the state size. A valid length
> cannot yield a zero size, so the !sve_state_size test goes with it.
> 
> Fixes: 5db1bef93342 ("KVM: arm64: Track SVE state in the hypervisor vcpu structure")
> Reported-by: Stefan Teodorescu <fane@google.com>
> Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>

Reviewed-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-18 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18  9:31 [PATCH] KVM: arm64: Validate the SVE vector length in pkvm_vcpu_init_sve() Fuad Tabba
2026-08-18 12:51 ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox