All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits
@ 2026-12-02 10:05 Fuad Tabba
  0 siblings, 0 replies; only message in thread
From: Fuad Tabba @ 2026-12-02 10:05 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton
  Cc: kvmarm, linux-arm-kernel, linux-kernel, Sascha Bischoff,
	Joey Gouly, Suzuki K Poulose, Zenghui Yu, Steffen Eiden,
	Catalin Marinas, Will Deacon, Fuad Tabba

KVM limits a GICv5 guest to 16 ID bits, but a userspace write to
IRS_IDR2 accepts an ID_BITS as large as the host IRS's. Without
two-level IST support in the host IRS, KVM backs the guest's LPI IST
with a single kzalloc(), which warns and fails once the IST is larger
than KMALLOC_MAX_SIZE.

Reject more than 16 ID bits. Userspace writes to IRS_IDR2 are new in
this cycle, so no release has them.

Fixes: 71091136d1452 ("KVM: arm64: gic-v5: Handle userspace accesses to IRS MMIO region")
Suggested-by: Sascha Bischoff <sascha.bischoff@arm.com>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---

Notes:
    v2:
    - Reject more than 16 ID bits, as Sascha suggested, and drop v1's
      KMALLOC_MAX_SIZE check. With 16 ID bits a linear IST is at most
      1MB.
    
    v1: https://lore.kernel.org/r/20261126100023.1286902-1-fuad.tabba@linux.dev
    
    Tested on FVP, VHE and nVHE hosts, with and without two-level IST
    support in the IRS. The vgic_v5 selftest passes. A reproducer that
    sets ID_BITS to 24 and restores an IST that wide hits the kzalloc()
    warning without this patch. With the patch, the reproducer's
    IRS_IDR2 writes with an ID_BITS of 17 or more are rejected.
    
    Based on Linux 7.4-rc3 (aebb727447640).

 arch/arm64/kvm/vgic/vgic-irs-v5.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/kvm/vgic/vgic-irs-v5.c b/arch/arm64/kvm/vgic/vgic-irs-v5.c
index f73349c02656c..7a615895d997d 100644
--- a/arch/arm64/kvm/vgic/vgic-irs-v5.c
+++ b/arch/arm64/kvm/vgic/vgic-irs-v5.c
@@ -648,6 +648,10 @@ static int vgic_v5_mmio_uaccess_write_irs(struct kvm_vcpu *vcpu, gpa_t addr,
 		    vgic_v5_irs_ist_id_bits(&irs_caps))
 			return -EINVAL;
 
+		/* We limit the CPU interface to 16 ID bits, so match that here */
+		if (FIELD_GET(GICV5_IRS_IDR2_ID_BITS, val) > 16)
+			return -EINVAL;
+
 		/* Min LPI ID bits must be greater than or equal to the HW */
 		if (FIELD_GET(GICV5_IRS_IDR2_MIN_LPI_ID_BITS, val) <
 		    vgic_v5_irs_min_lpi_id_bits(&irs_caps))

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.47.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 10:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 10:05 [PATCH v2] KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits Fuad Tabba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.