public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Michael Bommarito <michael.bommarito@gmail•com>
To: Marc Zyngier <maz@kernel•org>, Oliver Upton <oupton@kernel•org>
Cc: Yao Yuan <yaoyuan@linux•alibaba.com>,
	Joey Gouly <joey.gouly@arm•com>,
	Suzuki K Poulose <suzuki.poulose@arm•com>,
	Zenghui Yu <yuzenghui@huawei•com>,
	Catalin Marinas <catalin.marinas@arm•com>,
	Will Deacon <will@kernel•org>,
	linux-arm-kernel@lists•infradead.org, kvmarm@lists•linux.dev,
	linux-kernel@vger•kernel.org
Subject: [PATCH v2] KVM: arm64: vgic-its: reject restored DTE with out-of-range num_eventid_bits
Date: Tue, 19 May 2026 09:25:19 -0400	[thread overview]
Message-ID: <20260519132519.2142458-1-michael.bommarito@gmail.com> (raw)
In-Reply-To: <20260517174955.273004-1-michael.bommarito@gmail.com>

Userspace can restore an ITS Device Table Entry whose Size field encodes
more EventID bits than the virtual ITS supports.  The live MAPD path
rejects that state, but vgic_its_restore_dte() accepts it and stores the
out-of-range value in dev->num_eventid_bits.

Reject restored DTEs with num_eventid_bits > VITS_TYPER_IDBITS before
allocating the device.  This mirrors the MAPD check and prevents the
restored state from reaching vgic_its_restore_itt(), where the unchecked
value can be converted into an oversized scan_its_table() range.

Fixes: 57a9a117154c ("KVM: arm64: vgic-its: Device table save/restore")
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Michael Bommarito <michael.bommarito@gmail•com>
---
Changes in v2:
- Trim the commit message to the root cause and fix.
- Shorten the in-code comment as suggested by Marc.
- Keep the validation logic unchanged.

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

diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 2ea9f1c7ebcd0..1d7e5d560af4c 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -2307,6 +2307,10 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,
 	/* dte entry is valid */
 	offset = (entry & KVM_ITS_DTE_NEXT_MASK) >> KVM_ITS_DTE_NEXT_SHIFT;
 
+	/* Mimic the MAPD behaviour and reject invalid EID bits. */
+	if (num_eventid_bits > VITS_TYPER_IDBITS)
+		return -EINVAL;
+
 	if (!vgic_its_check_id(its, baser, id, NULL))
 		return -EINVAL;
 
-- 
2.53.0


  parent reply	other threads:[~2026-05-19 13:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-17 17:49 [PATCH] KVM: arm64: vgic-its: reject restored DTE with out-of-range num_eventid_bits Michael Bommarito
2026-05-18  6:05 ` Yao Yuan
2026-05-18  8:23   ` Marc Zyngier
2026-05-20  6:04     ` Yao Yuan
2026-05-20  6:52       ` Marc Zyngier
2026-05-18  8:33 ` Marc Zyngier
2026-05-19 13:25 ` Michael Bommarito [this message]
2026-05-20  7:17   ` [PATCH v2] " Marc Zyngier

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=20260519132519.2142458-1-michael.bommarito@gmail.com \
    --to=michael.bommarito@gmail$(echo .)com \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=joey.gouly@arm$(echo .)com \
    --cc=kvmarm@lists$(echo .)linux.dev \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=maz@kernel$(echo .)org \
    --cc=oupton@kernel$(echo .)org \
    --cc=suzuki.poulose@arm$(echo .)com \
    --cc=will@kernel$(echo .)org \
    --cc=yaoyuan@linux$(echo .)alibaba.com \
    --cc=yuzenghui@huawei$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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