render / rpms / qemu

Forked from rpms/qemu 5 months ago
Clone

Blame 0022-openpic-avoid-buffer-overrun-on-incoming-migration.patch

70114f
From 70488d5f1746b720bc141ea6b9850585e9c42121 Mon Sep 17 00:00:00 2001
70114f
From: Michael Roth <mdroth@linux.vnet.ibm.com>
70114f
Date: Mon, 28 Apr 2014 16:08:17 +0300
70114f
Subject: [PATCH] openpic: avoid buffer overrun on incoming migration
70114f
70114f
CVE-2013-4534
70114f
70114f
opp->nb_cpus is read from the wire and used to determine how many
70114f
IRQDest elements to read into opp->dst[]. If the value exceeds the
70114f
length of opp->dst[], MAX_CPU, opp->dst[] can be overrun with arbitrary
70114f
data from the wire.
70114f
70114f
Fix this by failing migration if the value read from the wire exceeds
70114f
MAX_CPU.
70114f
70114f
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
70114f
Reviewed-by: Alexander Graf <agraf@suse.de>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 73d963c0a75cb99c6aaa3f6f25e427aa0b35a02e)
70114f
---
70114f
 hw/intc/openpic.c | 16 ++++++++++++++--
70114f
 1 file changed, 14 insertions(+), 2 deletions(-)
70114f
70114f
diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
70114f
index be76fbd..17136c9 100644
70114f
--- a/hw/intc/openpic.c
70114f
+++ b/hw/intc/openpic.c
70114f
@@ -41,6 +41,7 @@
70114f
 #include "hw/sysbus.h"
70114f
 #include "hw/pci/msi.h"
70114f
 #include "qemu/bitops.h"
70114f
+#include "qapi/qmp/qerror.h"
70114f
 
70114f
 //#define DEBUG_OPENPIC
70114f
 
70114f
@@ -1416,7 +1417,7 @@ static void openpic_load_IRQ_queue(QEMUFile* f, IRQQueue *q)
70114f
 static int openpic_load(QEMUFile* f, void *opaque, int version_id)
70114f
 {
70114f
     OpenPICState *opp = (OpenPICState *)opaque;
70114f
-    unsigned int i;
70114f
+    unsigned int i, nb_cpus;
70114f
 
70114f
     if (version_id != 1) {
70114f
         return -EINVAL;
70114f
@@ -1428,7 +1429,11 @@ static int openpic_load(QEMUFile* f, void *opaque, int version_id)
70114f
     qemu_get_be32s(f, &opp->spve);
70114f
     qemu_get_be32s(f, &opp->tfrr);
70114f
 
70114f
-    qemu_get_be32s(f, &opp->nb_cpus);
70114f
+    qemu_get_be32s(f, &nb_cpus);
70114f
+    if (opp->nb_cpus != nb_cpus) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
+    assert(nb_cpus > 0 && nb_cpus <= MAX_CPU);
70114f
 
70114f
     for (i = 0; i < opp->nb_cpus; i++) {
70114f
         qemu_get_sbe32s(f, &opp->dst[i].ctpr);
70114f
@@ -1567,6 +1572,13 @@ static void openpic_realize(DeviceState *dev, Error **errp)
70114f
         {NULL}
70114f
     };
70114f
 
70114f
+    if (opp->nb_cpus > MAX_CPU) {
70114f
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
70114f
+                  TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
70114f
+                  (uint64_t)0, (uint64_t)MAX_CPU);
70114f
+        return;
70114f
+    }
70114f
+
70114f
     switch (opp->model) {
70114f
     case OPENPIC_MODEL_FSL_MPIC_20:
70114f
     default: