Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0008-hpet-fix-buffer-overrun-on-invalid-state-load.patch
1 From 5e0e0a12887c9e70356c23d20b08b08eabd4a6df Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:51:23 +0300
4 Subject: [PATCH] hpet: fix buffer overrun on invalid state load
5
6 CVE-2013-4527 hw/timer/hpet.c buffer overrun
7
8 hpet is a VARRAY with a uint8 size but static array of 32
9
10 To fix, make sure num_timers is valid using VMSTATE_VALID hook.
11
12 Reported-by: Anthony Liguori <anthony@codemonkey.ws>
13 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
14 Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
15 Signed-off-by: Juan Quintela <quintela@redhat.com>
16 (cherry picked from commit 3f1c49e2136fa08ab1ef3183fd55def308829584)
17 ---
18  hw/timer/hpet.c | 13 +++++++++++++
19  1 file changed, 13 insertions(+)
20
21 diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
22 index e15d6bc..2792f89 100644
23 --- a/hw/timer/hpet.c
24 +++ b/hw/timer/hpet.c
25 @@ -239,6 +239,18 @@ static int hpet_pre_load(void *opaque)
26      return 0;
27  }
28  
29 +static bool hpet_validate_num_timers(void *opaque, int version_id)
30 +{
31 +    HPETState *s = opaque;
32 +
33 +    if (s->num_timers < HPET_MIN_TIMERS) {
34 +        return false;
35 +    } else if (s->num_timers > HPET_MAX_TIMERS) {
36 +        return false;
37 +    }
38 +    return true;
39 +}
40 +
41  static int hpet_post_load(void *opaque, int version_id)
42  {
43      HPETState *s = opaque;
44 @@ -307,6 +319,7 @@ static const VMStateDescription vmstate_hpet = {
45          VMSTATE_UINT64(isr, HPETState),
46          VMSTATE_UINT64(hpet_counter, HPETState),
47          VMSTATE_UINT8_V(num_timers, HPETState, 2),
48 +        VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers),
49          VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
50                                      vmstate_hpet_timer, HPETTimer),
51          VMSTATE_END_OF_LIST()