9ae3a8
From 4b41911968cb53458b86b027f0d028e38618df46 Mon Sep 17 00:00:00 2001
9ae3a8
From: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Date: Wed, 14 May 2014 08:52:54 +0200
9ae3a8
Subject: [PATCH 23/31] hpet: fix buffer overrun on invalid state load
9ae3a8
9ae3a8
RH-Author: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Message-id: <1400057538-6975-5-git-send-email-mst@redhat.com>
9ae3a8
Patchwork-id: 58871
9ae3a8
O-Subject: [PATCH qemu-kvm RHEL7.1 4/5] hpet: fix buffer overrun on invalid state load
9ae3a8
Bugzilla: 1095707
9ae3a8
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
9ae3a8
CVE-2013-4527 hw/timer/hpet.c buffer overrun
9ae3a8
9ae3a8
hpet is a VARRAY with a uint8 size but static array of 32
9ae3a8
9ae3a8
To fix, make sure num_timers is valid using VMSTATE_VALID hook.
9ae3a8
9ae3a8
Reported-by: Anthony Liguori <anthony@codemonkey.ws>
9ae3a8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
(cherry picked from commit 3f1c49e2136fa08ab1ef3183fd55def308829584)
9ae3a8
9ae3a8
Tested: lightly on developer's box
9ae3a8
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7452039
9ae3a8
Bugzilla:1095707
9ae3a8
---
9ae3a8
 hw/timer/hpet.c | 13 +++++++++++++
9ae3a8
 1 file changed, 13 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/timer/hpet.c |   13 +++++++++++++
9ae3a8
 1 files changed, 13 insertions(+), 0 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
9ae3a8
index dd486a1..54ffa49 100644
9ae3a8
--- a/hw/timer/hpet.c
9ae3a8
+++ b/hw/timer/hpet.c
9ae3a8
@@ -222,6 +222,18 @@ static int hpet_pre_load(void *opaque)
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static bool hpet_validate_num_timers(void *opaque, int version_id)
9ae3a8
+{
9ae3a8
+    HPETState *s = opaque;
9ae3a8
+
9ae3a8
+    if (s->num_timers < HPET_MIN_TIMERS) {
9ae3a8
+        return false;
9ae3a8
+    } else if (s->num_timers > HPET_MAX_TIMERS) {
9ae3a8
+        return false;
9ae3a8
+    }
9ae3a8
+    return true;
9ae3a8
+}
9ae3a8
+
9ae3a8
 static int hpet_post_load(void *opaque, int version_id)
9ae3a8
 {
9ae3a8
     HPETState *s = opaque;
9ae3a8
@@ -290,6 +302,7 @@ static const VMStateDescription vmstate_hpet = {
9ae3a8
         VMSTATE_UINT64(isr, HPETState),
9ae3a8
         VMSTATE_UINT64(hpet_counter, HPETState),
9ae3a8
         VMSTATE_UINT8_V(num_timers, HPETState, 2),
9ae3a8
+        VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers),
9ae3a8
         VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
9ae3a8
                                     vmstate_hpet_timer, HPETTimer),
9ae3a8
         VMSTATE_END_OF_LIST()
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8