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 01908C27C79 for ; Thu, 20 Jun 2024 22:25:35 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=2HOphrwM8ahMoEd8ea1CfPz+XIb/VONzJcmnDUUVW20=; b=1/SMn7gChj71wPJf0PdZqnxE56 7DSb6RNYnVbmPW3kWNeJltzABNvBaYEkGC5l+OhYXhkFkBd75/hwhZomiR5IgB/2zjQq8xxZ5kuCT f2OeQxqRAg4lLP2UE9Ip6+X1hWKfrJPlgR7nG3DuQ525OyuJF7gmLMRh1J9wPki/qocXLc3w3Ab+n n9P1dtG/uqyOuQB7kD4sO0gvKtmMUBHGHBbEja+2+Zz7xYWK0oDDxnNipvBsWHXBDbIs9ldJOlr9R GPhJpM4rCmU+4SC/7KAchPcYEHJTmAQ2JnSSJTO6ElnhvQtDkYSZp00zDUN1TOHWfcbrBD0+eAMty S592Khmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQDb-00000006wkC-1XCu; Thu, 20 Jun 2024 22:25:23 +0000 Received: from out-171.mta0.migadu.com ([2001:41d0:1004:224b::ab]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQDX-00000006wjC-23WU for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 22:25:21 +0000 X-Envelope-To: jiangkunkun@huawei.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718922314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2HOphrwM8ahMoEd8ea1CfPz+XIb/VONzJcmnDUUVW20=; b=pEdK0dhlAlB2nt4kZOtVidCzxzCpFUa7hGiAp1o2YOcqeqIp4RuLtQA62ti0lET9UHXlOL 1iivbVqTGJHkNQy1kYysKggv+uSsTLzW637k0pACCMfgN6HtagWWmByJ1Lfc5cJneorwi1 kgwGf9DdN0EC2jFP9XCiTNdeFmI4hk8= X-Envelope-To: maz@kernel.org X-Envelope-To: james.morse@arm.com X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: yuzenghui@huawei.com X-Envelope-To: catalin.marinas@arm.com X-Envelope-To: will@kernel.org X-Envelope-To: rdunlap@infradead.org X-Envelope-To: eauger@redhat.com X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: kvmarm@lists.linux.dev X-Envelope-To: wanghaibin.wang@huawei.com X-Envelope-To: lishusen2@huawei.com Date: Thu, 20 Jun 2024 22:25:02 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Kunkun Jiang Cc: Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Randy Dunlap , Eric Auger , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, wanghaibin.wang@huawei.com, lishusen2@huawei.com Subject: Re: [PATCH 1/3] KVM: arm64: vgic-its: Add a data length check in vgic_its_save_* Message-ID: References: <20240620130650.1279-1-jiangkunkun@huawei.com> <20240620130650.1279-2-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240620130650.1279-2-jiangkunkun@huawei.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240620_152520_205847_8DEC3824 X-CRM114-Status: GOOD ( 17.94 ) 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 Hi, On Thu, Jun 20, 2024 at 09:06:48PM +0800, Kunkun Jiang wrote: > In all the vgic_its_save_*() functinos, it does not check > whether the data length is larger than 8 bytes before > calling vgic_write_guest_lock. This patch add the check. > > Link: https://lore.kernel.org/kvmarm/86v82ckimh.wl-maz@kernel.org/ > Signed-off-by: Kunkun Jiang > --- > arch/arm64/kvm/vgic/vgic-its.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > index 40bb43f20bf3..060605fba3b6 100644 > --- a/arch/arm64/kvm/vgic/vgic-its.c > +++ b/arch/arm64/kvm/vgic/vgic-its.c > @@ -2094,6 +2094,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, > ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) | > ite->collection->collection_id; > val = cpu_to_le64(val); > + BUG_ON(ite_esz > sizeof(val)); Does it really make sense to blow up the kernel over this? (hint: no) What _might_ make sense if if you bugged the VM and failed the ioctl, i.e. if (KVM_BUG_ON(ite_esz != sizeof(val), kvm)) return -EINVAL; Also, this isn't even asserting the right thing. You want to assert that the u64 being written to memory is *exactly* the size of a single ITE. No more, no less. > return vgic_write_guest_lock(kvm, gpa, &val, ite_esz); > } > > @@ -2246,6 +2247,7 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, > (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) | > (dev->num_eventid_bits - 1)); > val = cpu_to_le64(val); > + BUG_ON(dte_esz > sizeof(dte_esz)); Did you even test this? A bit of substitution arrives at: BUG_ON(8 > sizeof(unsigned int)); See the issue? Please do not test these sort of untested patches on the list, it is a waste of everyone's time. -- Thanks, Oliver