From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: [PATCH 3/5] pci: Error on PCI capability collisions Date: Fri, 03 Dec 2010 12:33:57 -0700 Message-ID: <20101203193351.3579.5502.stgit@s20.home> References: <20101203192343.3579.73722.stgit@s20.home> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: alex.williamson@redhat.com, ddutile@redhat.com, mst@redhat.com, chrisw@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:26958 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753000Ab0LCTd6 (ORCPT ); Fri, 3 Dec 2010 14:33:58 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB3JXwOP026105 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 3 Dec 2010 14:33:58 -0500 In-Reply-To: <20101203192343.3579.73722.stgit@s20.home> Sender: kvm-owner@vger.kernel.org List-ID: Nothing good can happen when we overlap capabilities Signed-off-by: Alex Williamson --- hw/pci.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index b08113d..288d6fd 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1845,6 +1845,20 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, if (!offset) { return -ENOSPC; } + } else { + int i; + + for (i = offset; i < offset + size; i++) { + if (pdev->config_map[i]) { + fprintf(stderr, "ERROR: %04x:%02x:%02x.%x " + "Attempt to add PCI capability %x at offset " + "%x overlaps existing capability %x at offset %x\n", + pci_find_domain(pdev->bus), pci_bus_num(pdev->bus), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + cap_id, offset, pdev->config_map[i], i); + return -EFAULT; + } + } } config = pdev->config + offset;