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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0398AC10DCE for ; Fri, 6 Mar 2020 10:54:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CAF2F2084E for ; Fri, 6 Mar 2020 10:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbgCFKyu (ORCPT ); Fri, 6 Mar 2020 05:54:50 -0500 Received: from foss.arm.com ([217.140.110.172]:59570 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbgCFKyt (ORCPT ); Fri, 6 Mar 2020 05:54:49 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 13F5231B; Fri, 6 Mar 2020 02:54:49 -0800 (PST) Received: from [10.1.196.63] (e123195-lin.cambridge.arm.com [10.1.196.63]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1BAA93F6C4; Fri, 6 Mar 2020 02:54:48 -0800 (PST) Subject: Re: [PATCH v2 kvmtool 14/30] vfio/pci: Don't access potentially unallocated regions To: Andre Przywara Cc: kvm@vger.kernel.org, will@kernel.org, julien.thierry.kdev@gmail.com, sami.mujawar@arm.com, lorenzo.pieralisi@arm.com, maz@kernel.org References: <20200123134805.1993-1-alexandru.elisei@arm.com> <20200123134805.1993-15-alexandru.elisei@arm.com> <20200129181708.0c360d71@donnerap.cambridge.arm.com> From: Alexandru Elisei Message-ID: <14f4ee8d-f6b5-c54d-5d81-169d1fd427e5@arm.com> Date: Fri, 6 Mar 2020 10:54:46 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200129181708.0c360d71@donnerap.cambridge.arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi, On 1/29/20 6:17 PM, Andre Przywara wrote: > On Thu, 23 Jan 2020 13:47:49 +0000 > Alexandru Elisei wrote: > > Hi, > >> Don't try to configure a BAR if there is no region associated with it. >> >> Signed-off-by: Alexandru Elisei >> --- >> vfio/pci.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/vfio/pci.c b/vfio/pci.c >> index 1f38f90c3ae9..f86a7d9b7032 100644 >> --- a/vfio/pci.c >> +++ b/vfio/pci.c >> @@ -652,6 +652,8 @@ static int vfio_pci_fixup_cfg_space(struct vfio_device *vdev) >> >> /* Initialise the BARs */ >> for (i = VFIO_PCI_BAR0_REGION_INDEX; i <= VFIO_PCI_BAR5_REGION_INDEX; ++i) { >> + if ((u32)i == vdev->info.num_regions) >> + break; > My inner check-patch complains that we should not have code before declarations. > Can we solve this the same way as below? Sure, I'll change it and update the commit message accordingly. Thanks, Alex > > Cheers, > Andre > > >> u64 base; >> struct vfio_region *region = &vdev->regions[i]; >> >> @@ -853,11 +855,12 @@ static int vfio_pci_configure_bar(struct kvm *kvm, struct vfio_device *vdev, >> u32 bar; >> size_t map_size; >> struct vfio_pci_device *pdev = &vdev->pci; >> - struct vfio_region *region = &vdev->regions[nr]; >> + struct vfio_region *region; >> >> if (nr >= vdev->info.num_regions) >> return 0; >> >> + region = &vdev->regions[nr]; >> bar = pdev->hdr.bar[nr]; >> >> region->vdev = vdev;