From patchwork Wed Jun 25 09:59:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeokYeon Hwang X-Patchwork-Id: 364010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5E16514009B for ; Wed, 25 Jun 2014 23:59:21 +1000 (EST) Received: from localhost ([::1]:37976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WznjL-0007Pp-Ed for incoming@patchwork.ozlabs.org; Wed, 25 Jun 2014 09:59:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzjzI-0003wX-Es for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzjzA-0007yK-Vg for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:59:32 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:24390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzjzA-0007xY-M5 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:59:24 -0400 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N7P0002JYEWLD00@mailout1.samsung.com> for qemu-devel@nongnu.org; Wed, 25 Jun 2014 18:59:20 +0900 (KST) X-AuditID: cbfee61a-f79e46d00000134f-77-53aa9d781b1a Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C3.36.04943.87D9AA35; Wed, 25 Jun 2014 18:59:20 +0900 (KST) Received: from localhost.localdomain ([182.198.1.3]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N7P00EE5YEV3ZL0@mmp1.samsung.com>; Wed, 25 Jun 2014 18:59:20 +0900 (KST) From: SeokYeon Hwang To: qemu-devel@nongnu.org, mst@redhat.com Date: Wed, 25 Jun 2014 18:59:08 +0900 Message-id: <1403690348-19267-1-git-send-email-syeon.hwang@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLJMWRmVeSWpSXmKPExsVy+t9jAd2KuauCDbZs4rb4/+sVq8Xx3h0s FjfWn2ZzYPZ4cm0zk8f7fVfZPPq2rGIMYI7isklJzcksSy3St0vgytjdYVNwgKNi7pM29gbG z2xdjJwcEgImEhtOz2aBsMUkLtxbDxTn4hASWMQosePhb1YIp4VJonfCMbAqNgE9iQ3LDjB2 MXJwiAhoSkxZZgUSZhaQluj/sBlsqLBAssTXix/YQWwWAVWJPevPMIPYvALuEn+mHYBaLCdx 8thk1gmM3AsYGVYxiqYWJBcUJ6XnGuoVJ+YWl+al6yXn525iBHv6mdQOxpUNFocYBTgYlXh4 L8xeGSzEmlhWXJl7iFGCg1lJhNdxzqpgId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwHWq0DhQTS E0tSs1NTC1KLYLJMHJxSDYwrDqU//nRkzpwaJc+CtRfaFzDXTvl3ebLdE6aS4FSn4ko203+n bqX3X9izw0Hv33+dmZqrpwa/nuIZtKumc+Y3CXPhCXH3jU4fWLC/a9s6BSehpUy6X0O4kk14 rG5OD3e/8ejTBL/21Ae1nztXfeUIDlDssLmxwMz98sSMLJ5zMcs4loj9PGajxFKckWioxVxU nAgANA006vABAAA= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.254.224.24 X-Mailman-Approved-At: Wed, 25 Jun 2014 09:58:58 -0400 Cc: syeon.hwang@samsung.com Subject: [Qemu-devel] [PATCH] pci: add checking whether the device is realized before unlinking the capability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In case of the unrealized "pdev", memory can be illegally accessed and corrupted. Refer to device_unparent() in the commit 5c21ce77d7e5643089ceec556c0408445d017f32. Change-Id: Iacb195a092c86d4c677ad0404582af104b2251ae Signed-off-by: SeokYeon Hwang --- hw/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 49eca95..bb7f0c5 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2056,7 +2056,12 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, /* Unlink capability from the pci config space. */ void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) { - uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev); + uint8_t prev, offset; + /* Check whether the device is realized or not */ + if (!pdev->qdev.realized) { + return; + } + offset = pci_find_capability_list(pdev, cap_id, &prev); if (!offset) return; pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];