qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] virtio-pci: properly validate address before accessing config
@ 2013-04-26  8:34 Jason Wang
  2013-04-26  8:34 ` [Qemu-devel] [PATCH 2/3] virtio-ccw: check config length before accessing it Jason Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Jason Wang @ 2013-04-26  8:34 UTC (permalink / raw)
  To: aliguori, mst, qemu-devel; +Cc: Jason Wang, pmatouse

There are several several issues in the current checking:

- The check was based on the minus of unsigned values which can overflow
- It was done after .{set|get}_config() which can lead crash when config_len is
  zero since vdev->config is NULL

Fix this by:

- Validate the address in virtio_pci_config_{read|write}() before
  .{set|get}_config
- Use addition instead minus to do the validation

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Petr Matousek <pmatouse@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio-pci.c |    9 +++++++++
 hw/virtio/virtio.c     |   18 ------------------
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index a1f15a8..7f6c7d1 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -400,6 +400,10 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
     }
     addr -= config;
 
+    if (addr + size > proxy->vdev->config_len) {
+        return (uint32_t)-1;
+    }
+
     switch (size) {
     case 1:
         val = virtio_config_readb(proxy->vdev, addr);
@@ -430,6 +434,11 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
         return;
     }
     addr -= config;
+
+    if (addr + size > proxy->vdev->config_len) {
+        return;
+    }
+
     /*
      * Virtio-PCI is odd. Ioports are LE but config space is target native
      * endian.
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 1c2282c..3397b5e 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -563,9 +563,6 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
 
     vdev->get_config(vdev, vdev->config);
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return (uint32_t)-1;
-
     val = ldub_p(vdev->config + addr);
     return val;
 }
@@ -576,9 +573,6 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
 
     vdev->get_config(vdev, vdev->config);
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return (uint32_t)-1;
-
     val = lduw_p(vdev->config + addr);
     return val;
 }
@@ -589,9 +583,6 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
 
     vdev->get_config(vdev, vdev->config);
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return (uint32_t)-1;
-
     val = ldl_p(vdev->config + addr);
     return val;
 }
@@ -600,9 +591,6 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
     uint8_t val = data;
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return;
-
     stb_p(vdev->config + addr, val);
 
     if (vdev->set_config)
@@ -613,9 +601,6 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
     uint16_t val = data;
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return;
-
     stw_p(vdev->config + addr, val);
 
     if (vdev->set_config)
@@ -626,9 +611,6 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
     uint32_t val = data;
 
-    if (addr > (vdev->config_len - sizeof(val)))
-        return;
-
     stl_p(vdev->config + addr, val);
 
     if (vdev->set_config)
-- 
1.7.1

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

end of thread, other threads:[~2013-05-07  5:43 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-26  8:34 [Qemu-devel] [PATCH 1/3] virtio-pci: properly validate address before accessing config Jason Wang
2013-04-26  8:34 ` [Qemu-devel] [PATCH 2/3] virtio-ccw: check config length before accessing it Jason Wang
2013-04-28  8:32   ` Michael S. Tsirkin
2013-04-28  8:40     ` Jason Wang
2013-05-07  5:42       ` Jason Wang
2013-04-26  8:34 ` [Qemu-devel] [PATCH 3/3] s390-virtio-bus: sync config only when config_len is not zero Jason Wang
2013-04-26 17:07   ` Alexander Graf
2013-04-27  5:14     ` Jason Wang
2013-04-28  8:31   ` Michael S. Tsirkin
2013-04-28  8:39     ` Jason Wang
2013-04-26 14:27 ` [Qemu-devel] [PATCH 1/3] virtio-pci: properly validate address before accessing config Petr Matousek
2013-04-27  5:13   ` Jason Wang
2013-04-28 11:29     ` Petr Matousek
2013-04-29  7:34       ` [Qemu-devel] [oss-security] " Kurt Seifried
2013-04-29  7:51         ` Michael S. Tsirkin
2013-04-27 19:05   ` [Qemu-devel] " Michael S. Tsirkin
2013-04-27 19:26 ` Michael S. Tsirkin
2013-04-28  7:54   ` Jason Wang
2013-04-28  8:35     ` Michael S. Tsirkin
2013-05-02 14:35       ` Andreas Färber
2013-05-06  3:17         ` Jason Wang

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).