From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJlyD-0004eb-C0 for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJly9-0000nT-8b for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJly9-0000nK-0o for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t16GfOP2012709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Feb 2015 11:41:24 -0500 From: Kevin Wolf Date: Fri, 6 Feb 2015 17:40:31 +0100 Message-Id: <1423240849-15499-25-git-send-email-kwolf@redhat.com> In-Reply-To: <1423240849-15499-1-git-send-email-kwolf@redhat.com> References: <1423240849-15499-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 24/42] block/dmg: validate chunk size to avoid overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Peter Wu Previously the chunk size was not checked, allowing for a large memory allocation. This patch checks whether the chunks size is within the resource fork length, and whether the resource fork is below the trailer of the dmg file. Signed-off-by: Peter Wu Reviewed-by: John Snow Message-id: 1420566495-13284-6-git-send-email-peter@lekensteyn.nl Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/dmg.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/dmg.c b/block/dmg.c index 4f56227..5c2c2c2 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -317,7 +317,7 @@ static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds, ret = read_uint32(bs, offset, &count); if (ret < 0) { goto fail; - } else if (count == 0) { + } else if (count == 0 || count > info_end - offset) { ret = -EINVAL; goto fail; } @@ -377,6 +377,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (rsrc_fork_offset >= offset || + rsrc_fork_length > offset - rsrc_fork_offset) { + ret = -EINVAL; + goto fail; + } if (rsrc_fork_length != 0) { ret = dmg_read_resource_fork(bs, &ds, rsrc_fork_offset, rsrc_fork_length); -- 1.8.3.1