From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS614-0002Yr-6Q for qemu-devel@nongnu.org; Mon, 24 Mar 2014 10:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WS60y-0000Co-Sl for qemu-devel@nongnu.org; Mon, 24 Mar 2014 10:38:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS60y-0000Cf-LC for qemu-devel@nongnu.org; Mon, 24 Mar 2014 10:38:12 -0400 Date: Mon, 24 Mar 2014 16:38:16 +0200 From: "Michael S. Tsirkin" Message-ID: <1395671853-2685-6-git-send-email-mst@redhat.com> References: <1395671853-2685-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1395671853-2685-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [RFC v2 5/5] hpet: fix buffer overrun on invalid state load List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Anthony Liguori 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_TEST hook. Reported-by: Anthony Liguori Signed-off-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/timer/hpet.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 1ee0640..67671bc 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -248,6 +248,22 @@ static int hpet_pre_load(void *opaque) return 0; } +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 bool hpet_fix_num_timers(HPETState *s) +{ +} + static int hpet_post_load(void *opaque, int version_id) { HPETState *s = opaque; @@ -318,6 +334,7 @@ static const VMStateDescription vmstate_hpet = { VMSTATE_UINT64(isr, HPETState), VMSTATE_UINT64(hpet_counter, HPETState), VMSTATE_UINT8_V(num_timers, HPETState, 2), + VMSTATE_TEST("num_timers in range", hpet_validate_num_timers); VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0, vmstate_hpet_timer, HPETTimer), VMSTATE_END_OF_LIST() -- MST