From: Fuad Tabba <fuad.tabba@linux.dev>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Sascha Bischoff <sascha.bischoff@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Fuad Tabba <tabba@google.com>
Subject: [PATCH v2] KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits
Date: Wed, 2 Dec 2026 10:05:59 +0000 [thread overview]
Message-ID: <20261202100559.1607674-1-fuad.tabba@linux.dev> (raw)
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
reply other threads:[~2026-12-02 10:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261202100559.1607674-1-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sascha.bischoff@arm.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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 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.