From patchwork Mon Mar 31 14:16:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 335395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 98F30140095 for ; Tue, 1 Apr 2014 01:21:49 +1100 (EST) Received: from localhost ([::1]:48933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd5v-0008Gu-AO for incoming@patchwork.ozlabs.org; Mon, 31 Mar 2014 10:21:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd0l-0008U3-5s for qemu-devel@nongnu.org; Mon, 31 Mar 2014 10:16:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUd0g-0000Y1-Br for qemu-devel@nongnu.org; Mon, 31 Mar 2014 10:16:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd0f-0000Xj-TS; Mon, 31 Mar 2014 10:16:22 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2VEGIbD001868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 Mar 2014 10:16:18 -0400 Received: from redhat.com (vpn1-4-232.ams2.redhat.com [10.36.4.232]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id s2VEGEUh006383; Mon, 31 Mar 2014 10:16:15 -0400 Date: Mon, 31 Mar 2014 17:16:44 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1396275242-10810-13-git-send-email-mst@redhat.com> References: <1396275242-10810-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1396275242-10810-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com, Juan Quintela , Alexey Kardashevskiy , qemu-stable@nongnu.org, dgilbert@redhat.com, Anthony Liguori , =?us-ascii?B?PT9VVEYtOD9xP0FuZHJlYXM9MjBGPUMzPUE0cmJlcj89?= Subject: [Qemu-devel] [PATCH v4 12/30] vmstate: fix buffer overflow in target-arm/machine.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org CVE-2013-4531 cpreg_vmstate_indexes is a VARRAY_INT32. A negative value for cpreg_vmstate_array_len will cause a buffer overflow. VMSTATE_INT32_LE was supposed to protect against this but doesn't because it doesn't validate that input is non-negative. Fix this macro to valide the value appropriately. The only other user of VMSTATE_INT32_LE doesn't ever use negative numbers so it doesn't care. Reported-by: Anthony Liguori Signed-off-by: Michael S. Tsirkin --- vmstate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vmstate.c b/vmstate.c index 02d5d94..e1e9cae 100644 --- a/vmstate.c +++ b/vmstate.c @@ -340,8 +340,9 @@ const VMStateInfo vmstate_info_int32_equal = { .put = put_int32, }; -/* 32 bit int. Check that the received value is less than or equal to - the one in the field */ +/* 32 bit int. Check that the received value is non-negative + * and less than or equal to the one in the field. + */ static int get_int32_le(QEMUFile *f, void *pv, size_t size) { @@ -349,7 +350,7 @@ static int get_int32_le(QEMUFile *f, void *pv, size_t size) int32_t loaded; qemu_get_sbe32s(f, &loaded); - if (loaded <= *cur) { + if (loaded >= 0 && loaded <= *cur) { *cur = loaded; return 0; }