Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0022-openpic-avoid-buffer-overrun-on-incoming-migration.patch
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
5
6 CVE-2013-4534
7
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
11 data from the wire.
12
13 Fix this by failing migration if the value read from the wire exceeds
14 MAX_CPU.
15
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)
21 ---
22  hw/intc/openpic.c | 16 ++++++++++++++--
23  1 file changed, 14 insertions(+), 2 deletions(-)
24
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
29 @@ -41,6 +41,7 @@
30  #include "hw/sysbus.h"
31  #include "hw/pci/msi.h"
32  #include "qemu/bitops.h"
33 +#include "qapi/qmp/qerror.h"
34  
35  //#define DEBUG_OPENPIC
36  
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)
39  {
40      OpenPICState *opp = (OpenPICState *)opaque;
41 -    unsigned int i;
42 +    unsigned int i, nb_cpus;
43  
44      if (version_id != 1) {
45          return -EINVAL;
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);
49  
50 -    qemu_get_be32s(f, &opp->nb_cpus);
51 +    qemu_get_be32s(f, &nb_cpus);
52 +    if (opp->nb_cpus != nb_cpus) {
53 +        return -EINVAL;
54 +    }
55 +    assert(nb_cpus > 0 && nb_cpus <= MAX_CPU);
56  
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)
60          {NULL}
61      };
62  
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);
67 +        return;
68 +    }
69 +
70      switch (opp->model) {
71      case OPENPIC_MODEL_FSL_MPIC_20:
72      default: