1 From 70488d5f1746b720bc141ea6b9850585e9c42121 Mon Sep 17 00:00:00 2001
2 From: Michael Roth <mdroth@linux.vnet.ibm.com>
3 Date: Mon, 28 Apr 2014 16:08:17 +0300
4 Subject: [PATCH] openpic: avoid buffer overrun on incoming migration
8 opp->nb_cpus is read from the wire and used to determine how many
9 IRQDest elements to read into opp->dst[]. If the value exceeds the
10 length of opp->dst[], MAX_CPU, opp->dst[] can be overrun with arbitrary
13 Fix this by failing migration if the value read from the wire exceeds
16 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
17 Reviewed-by: Alexander Graf <agraf@suse.de>
18 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
19 Signed-off-by: Juan Quintela <quintela@redhat.com>
20 (cherry picked from commit 73d963c0a75cb99c6aaa3f6f25e427aa0b35a02e)
22 hw/intc/openpic.c | 16 ++++++++++++++--
23 1 file changed, 14 insertions(+), 2 deletions(-)
25 diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
26 index be76fbd..17136c9 100644
27 --- a/hw/intc/openpic.c
28 +++ b/hw/intc/openpic.c
30 #include "hw/sysbus.h"
31 #include "hw/pci/msi.h"
32 #include "qemu/bitops.h"
33 +#include "qapi/qmp/qerror.h"
35 //#define DEBUG_OPENPIC
37 @@ -1416,7 +1417,7 @@ static void openpic_load_IRQ_queue(QEMUFile* f, IRQQueue *q)
38 static int openpic_load(QEMUFile* f, void *opaque, int version_id)
40 OpenPICState *opp = (OpenPICState *)opaque;
42 + unsigned int i, nb_cpus;
44 if (version_id != 1) {
46 @@ -1428,7 +1429,11 @@ static int openpic_load(QEMUFile* f, void *opaque, int version_id)
47 qemu_get_be32s(f, &opp->spve);
48 qemu_get_be32s(f, &opp->tfrr);
50 - qemu_get_be32s(f, &opp->nb_cpus);
51 + qemu_get_be32s(f, &nb_cpus);
52 + if (opp->nb_cpus != nb_cpus) {
55 + assert(nb_cpus > 0 && nb_cpus <= MAX_CPU);
57 for (i = 0; i < opp->nb_cpus; i++) {
58 qemu_get_sbe32s(f, &opp->dst[i].ctpr);
59 @@ -1567,6 +1572,13 @@ static void openpic_realize(DeviceState *dev, Error **errp)
63 + if (opp->nb_cpus > MAX_CPU) {
64 + error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
65 + TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
66 + (uint64_t)0, (uint64_t)MAX_CPU);
71 case OPENPIC_MODEL_FSL_MPIC_20: