Skip to contentSkip to conversation

KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits

PATCH New Fuad Tabba 1 participant 1 message Dec 2

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

PATCH v2 1/1 KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits

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")

---

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/[email protected]

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(+)
arch/arm64/kvm/vgic/vgic-irs-v5.c +4 -0
index f73349c02656c..7a615895d997d 100644
@@ -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

Signature · 1 line
2.47.3