Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752286AbcD1LGF (ORCPT ); Thu, 28 Apr 2016 07:06:05 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:57507 "EHLO e23smtp08.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750923AbcD1LGB (ORCPT ); Thu, 28 Apr 2016 07:06:01 -0400 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: aik@ozlabs.ru X-IBM-RcptTo: kvm@vger.kernel.org;linux-kernel@vger.kernel.org From: Alexey Kardashevskiy To: Alex Williamson Cc: Alexey Kardashevskiy , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Herrenschmidt , Gavin Shan , Alistair Popple Subject: [PATCH kernel] vfio_pci: Make extended capabilities test more robust Date: Thu, 28 Apr 2016 21:04:52 +1000 Message-Id: <1461841492-29277-1-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16042811-0029-0000-0000-0000457A48E4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1485 Lines: 35 VFIO reads a dword beyond the standard PCI config space (256 bytes) to know if there are extended config space (4096 bytes). It relies on the platform to return zero if there is no extended space. However at least on PPC64/POWERNV platform, the system firmware (OPAL) returns 0xffffffff in this case. VFIO treats it as a proof that there is extended config space and calls vfio_ecap_init() which fails to parse capabilities (which is expected) but right before the exit, it writes zero at offset of 256 which is beyond the buffer allocated for vdev->vconfig - it is 256 bytes for a device without extended config space. This adds an additional check that config space read returned non-zero and non-ffffffff value. Signed-off-by: Alexey Kardashevskiy --- drivers/vfio/pci/vfio_pci_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 142c533..8a53421 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -1140,7 +1140,7 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) case PCI_CAP_ID_EXP: /* Test for extended capabilities */ pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword); - vdev->extended_caps = (dword != 0); + vdev->extended_caps = (dword != 0) && (dword != 0xffffffff); /* length based on version */ if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1) -- 2.5.0.rc3