Blame 0008-hpet-fix-buffer-overrun-on-invalid-state-load.patch

70114f
From 5e0e0a12887c9e70356c23d20b08b08eabd4a6df Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:51:23 +0300
70114f
Subject: [PATCH] hpet: fix buffer overrun on invalid state load
70114f
70114f
CVE-2013-4527 hw/timer/hpet.c buffer overrun
70114f
70114f
hpet is a VARRAY with a uint8 size but static array of 32
70114f
70114f
To fix, make sure num_timers is valid using VMSTATE_VALID hook.
70114f
70114f
Reported-by: Anthony Liguori <anthony@codemonkey.ws>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 3f1c49e2136fa08ab1ef3183fd55def308829584)
70114f
---
70114f
 hw/timer/hpet.c | 13 +++++++++++++
70114f
 1 file changed, 13 insertions(+)
70114f
70114f
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
70114f
index e15d6bc..2792f89 100644
70114f
--- a/hw/timer/hpet.c
70114f
+++ b/hw/timer/hpet.c
70114f
@@ -239,6 +239,18 @@ static int hpet_pre_load(void *opaque)
70114f
     return 0;
70114f
 }
70114f
 
70114f
+static bool hpet_validate_num_timers(void *opaque, int version_id)
70114f
+{
70114f
+    HPETState *s = opaque;
70114f
+
70114f
+    if (s->num_timers < HPET_MIN_TIMERS) {
70114f
+        return false;
70114f
+    } else if (s->num_timers > HPET_MAX_TIMERS) {
70114f
+        return false;
70114f
+    }
70114f
+    return true;
70114f
+}
70114f
+
70114f
 static int hpet_post_load(void *opaque, int version_id)
70114f
 {
70114f
     HPETState *s = opaque;
70114f
@@ -307,6 +319,7 @@ static const VMStateDescription vmstate_hpet = {
70114f
         VMSTATE_UINT64(isr, HPETState),
70114f
         VMSTATE_UINT64(hpet_counter, HPETState),
70114f
         VMSTATE_UINT8_V(num_timers, HPETState, 2),
70114f
+        VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers),
70114f
         VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
70114f
                                     vmstate_hpet_timer, HPETTimer),
70114f
         VMSTATE_END_OF_LIST()