qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] pci: add checking whether the device is realized before unlinking the capability
@ 2014-06-25  9:59 SeokYeon Hwang
  2014-06-25 12:03 ` Michael S. Tsirkin
  0 siblings, 1 reply; 6+ messages in thread
From: SeokYeon Hwang @ 2014-06-25  9:59 UTC (permalink / raw)
  To: qemu-devel, mst; +Cc: syeon.hwang

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 <syeon.hwang@samsung.com>
---
 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];
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-28  6:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-25  9:59 [Qemu-devel] [PATCH] pci: add checking whether the device is realized before unlinking the capability SeokYeon Hwang
2014-06-25 12:03 ` Michael S. Tsirkin
2014-06-25 12:28   ` Marcel Apfelbaum
2014-06-26  3:48     ` SeokYeon Hwang
2014-06-26  7:07       ` Michael S. Tsirkin
2014-06-28  6:39         ` SeokYeon Hwang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).