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
6 CVE-2013-4527 hw/timer/hpet.c buffer overrun
8 hpet is a VARRAY with a uint8 size but static array of 32
10 To fix, make sure num_timers is valid using VMSTATE_VALID hook.
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)
18 hw/timer/hpet.c | 13 +++++++++++++
19 1 file changed, 13 insertions(+)
21 diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
22 index e15d6bc..2792f89 100644
25 @@ -239,6 +239,18 @@ static int hpet_pre_load(void *opaque)
29 +static bool hpet_validate_num_timers(void *opaque, int version_id)
31 + HPETState *s = opaque;
33 + if (s->num_timers < HPET_MIN_TIMERS) {
35 + } else if (s->num_timers > HPET_MAX_TIMERS) {
41 static int hpet_post_load(void *opaque, int version_id)
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),