From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBDDFCD4F3C for ; Mon, 18 May 2026 08:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DbZZTEOYgnznlEBlXZmmNIdMePa7w/xJfaHACc0l0Pc=; b=RPVQCcOWPo4JhZA+NrvW9Klwa8 LuZVvS6tvbCXI25eFjQyytrLXIQDMgl3rgMxQdGw8efQCO0hAlJvJtlklCsxQnqI3f88Inmn462DZ KpTtoO2HtBsqs2lfgM5QYZmzmVe//Rfh5OjXygNGQ3onBYcVieiYP/2Hf7RP/kPJhZ4hhch5c8HLX JX59rD4acYRIYfCs06UZ+ubsW8kw8yLFwuMdRyjGP7zJ/9/5J9lHNGKhu5nBqpEMcKpiahvvtpoO4 vjOKkQiIpYkOqcZZxXM3tKCQzREAzMaG43JLFOYm6TOtrffScPA2yDKlu1HeB7wd2k3YIVLqFmOZv +ojb18tA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOtQ6-0000000EpAt-1xM1; Mon, 18 May 2026 08:33:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOtQ5-0000000EpAF-0Vda for linux-arm-kernel@bombadil.infradead.org; Mon, 18 May 2026 08:33:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DbZZTEOYgnznlEBlXZmmNIdMePa7w/xJfaHACc0l0Pc=; b=WJQd1+Lexyp9VIwaEnL4gWgl9J Mmup6PxeAR7CBWWBQovaTWWDf8lQPQgNpzzGxgda0QjzC+zhXJ8w3uUprXS542Tx2RkuUXRZWi70S pyjT4Ql+5pTHZpgLVARCOlFYI8ez1KyCQJ+CvB9/uTAKugLKJNcw3dOmNw7Ckjwno9jW8ThleCK9s oHL7nloOPRaollo3FPP1JnR+RnoNnv+wO9JKqQ5DGYuH4DsJn/7KKVL5kLyDxru97moQfmu8QG21p zUyZOsY5RbyspAm1BmTuUWUK5ApVCrkk1pb3idBZaS+uYBKRLqvDWqzQSHSTmbY5nw+c9B/90OvrX TzI83HnA==; Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by desiato.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOtQ1-0000000AOXq-3W7k for linux-arm-kernel@lists.infradead.org; Mon, 18 May 2026 08:33:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 2313540B7E; Mon, 18 May 2026 08:33:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F33BBC2BCB7; Mon, 18 May 2026 08:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779093222; bh=/yn5AaMzJ9BgnhIOhBP334j/TdcMsLgg4RzjCIiAFaQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NnF2XX+foXJmxANzHYbYc2oOmrtQJsbxRDRdUAV9Tdw5gVh7TsGQBI7+Fh85hnbiW 4YXWuZyV1l7DTbPwwUsR2/MxHJIshAM71lg4mb+T9IaCsBCyK9azfrZe0vSC9tQFoM XgTH0HjNsenfFlbYM346k103qA5QUN9zHq9lKlFgl3CvzQIYXxjvSUuht+JSKw93EB pWTDSv46QEYD2c0L/OyXT7wkU0qZTWjSdLaGG5P9697ldOF/Ez/zOesysxN561/KA5 1ON7gL1i8aOKwwlLOto6l5swfmaQ5tILXYN+R2op/gRdP3DICH7FkEA4UpsEVk7dIe iGqXsaBXgJlZg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wOtPv-00000003QcE-2skF; Mon, 18 May 2026 08:33:39 +0000 Date: Mon, 18 May 2026 09:33:39 +0100 Message-ID: <861pf9xgkc.wl-maz@kernel.org> From: Marc Zyngier To: Michael Bommarito Cc: Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: vgic-its: reject restored DTE with out-of-range num_eventid_bits In-Reply-To: <20260517174955.273004-1-michael.bommarito@gmail.com> References: <20260517174955.273004-1-michael.bommarito@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: michael.bommarito@gmail.com, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260518_093346_547257_C01D277D X-CRM114-Status: GOOD ( 33.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, 17 May 2026 18:49:55 +0100, Michael Bommarito wrote: > > Userspace can trigger a host-side denial of service via > KVM_DEV_ARM_ITS_RESTORE_TABLES. A Device Table Entry whose Size > field encodes num_eventid_bits > VITS_TYPER_IDBITS reaches > scan_its_table() with a sign-extended ~18 EiB length, where the > loop holds the per-ITS mutex and never calls cond_resched(), > pinning a host CPU for a time linear in registered guest memslot > size. The accessor is any process that can open /dev/kvm and > create a VM. The same out-of-range value also disables a > subsequent live bounds check on EventID, as described below. > > The MAPD command handler already rejects this case in the live > path: > > if (valid && num_eventid_bits > VITS_TYPER_IDBITS) > return E_ITS_MAPD_ITTSIZE_OOR; > > vgic_its_restore_dte() reconstructs num_eventid_bits from the DTE > Size field but does not apply the same cap, so userspace can > install device state that the live MAPD path is documented to > reject. The restored value is stored in dev->num_eventid_bits and > is then used by vgic_its_restore_itt(): > > size_t max_size = BIT_ULL(dev->num_eventid_bits) * ite_esz; > ret = scan_its_table(its, base, max_size, ite_esz, ...); > > scan_its_table() takes the size as int and assigns it to > unsigned long in the callee: > > static int scan_its_table(struct vgic_its *its, gpa_t base, > int size, u32 esz, ...) > { > unsigned long len = size; > > For num_eventid_bits = 28 the size_t value 0x80000000 truncates to > INT_MIN as int and sign-extends to ~18 EiB as unsigned long. The > scan loop then walks the registered guest memslot one ite_esz at > a time with the per-ITS mutex held and no cond_resched(). In a > QEMU TCG arm64 guest at EL2 on v7.1-rc1, with an empty ITT, the > ioctl returned -EFAULT after about 14 seconds with a 256 MiB > memslot and about 56 seconds with a 1 GiB memslot (linear in > memslot size). The per-iteration cost on native arm64 KVM > hardware will differ; the loop shape, and so the linear scaling, > will not. > > The same out-of-range num_eventid_bits also disables the live > vgic_its_check_event_id() bounds check, because event_id is u32 > and BIT_ULL(32) is unreachable in that comparison, leaving > subsequent MAPI/MAPTI handling without an effective EventID cap. > > Mirror the MAPD cap in vgic_its_restore_dte() before allocating > the device, so out-of-range restored DTEs are rejected with > -EINVAL up front rather than triggering the int-truncated scan or > installing a device whose num_eventid_bits silently disables the > live bounds check. Sizes within [1, VITS_TYPER_IDBITS] are > unaffected. This commit message is way too verbose, and really looks like a copy paste from an LLM analysis. This needs trimming (the initial paragraph has most of it...). > > Fixes: 57a9a117154c ("KVM: arm64: vgic-its: Device table save/restore") > Assisted-by: Claude:claude-opus-4-7 > Signed-off-by: Michael Bommarito > --- > arch/arm64/kvm/vgic/vgic-its.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > index 2ea9f1c7ebcd0..a5dcf9a6a2854 100644 > --- a/arch/arm64/kvm/vgic/vgic-its.c > +++ b/arch/arm64/kvm/vgic/vgic-its.c > @@ -2307,6 +2307,15 @@ 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; > > + /* > + * The MAPD command rejects this case; mirror the cap here so a > + * restored DTE cannot install an out-of-range num_eventid_bits > + * that vgic_its_restore_itt() would then convert into a > + * sign-extended scan_its_table() length. > + */ Same here. Something like: /* Mimic the MAPD behaviour and reject invalid EID bits */ would be enough. > + if (num_eventid_bits > VITS_TYPER_IDBITS) > + return -EINVAL; > + > if (!vgic_its_check_id(its, baser, id, NULL)) > return -EINVAL; > Otherwise looks good. M. -- Without deviation from the norm, progress is not possible.