From: Michael S. Tsirkin Date: Wed, 4 Mar 2015 16:39:58 +0000 (+0000) Subject: hpet: fix buffer overrun on invalid state load X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=857f258638f48ae390e98e9d161b402a86956459;p=qemu-upstream-4.3-testing.git hpet: fix buffer overrun on invalid state load CVE-2013-4527 hw/timer/hpet.c buffer overrun hpet is a VARRAY with a uint8 size but static array of 32 To fix, make sure num_timers is valid using VMSTATE_VALID hook. Reported-by: Anthony Liguori Signed-off-by: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela Signed-off-by: Stefano Stabellini --- diff --git a/hw/hpet.c b/hw/hpet.c index 50ac067ec..dd80f7dfb 100644 --- a/hw/hpet.c +++ b/hw/hpet.c @@ -222,10 +222,25 @@ static int hpet_pre_load(void *opaque) return 0; } +static bool hpet_validate_num_timers(void *opaque, int version_id) +{ + HPETState *s = opaque; + + if (s->num_timers < HPET_MIN_TIMERS) { + return false; + } else if (s->num_timers > HPET_MAX_TIMERS) { + return false; + } + return true; +} + static int hpet_post_load(void *opaque, int version_id) { HPETState *s = opaque; + if (!hpet_validate_num_timers(s, version_id)) + return -EINVAL; + /* Recalculate the offset between the main counter and guest time */ s->hpet_offset = ticks_to_ns(s->hpet_counter) - qemu_get_clock_ns(vm_clock);