From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKm89-0006y2-Mt for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKm88-0002xF-Mt for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:09 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:49103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKm88-0002x2-F5 for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:08 -0400 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Jul 2015 05:36:08 -0600 From: Michael Roth Date: Thu, 30 Jul 2015 06:32:21 -0500 Message-Id: <1438255988-10418-7-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1438255988-10418-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1438255988-10418-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 06/53] vmdk: Fix overflow if l1_size is 0x20000000 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , qemu-stable@nongnu.org From: Fam Zheng Richard Jones caught this bug with afl fuzzer. In fact, that's the only possible value to overflow (extent->l1_size = 0x20000000) l1_size: l1_size = extent->l1_size * sizeof(long) => 0x80000000; g_try_malloc returns NULL because l1_size is interpreted as negative during type casting from 'int' to 'gsize', which yields a enormous value. Hence, by coincidence, we get a "not too bad" behavior: qemu-img: Could not open '/tmp/afl6.img': Could not open '/tmp/afl6.img': Cannot allocate memory Values larger than 0x20000000 will be refused by the validation in vmdk_add_extent. Values smaller than 0x20000000 will not overflow l1_size. Cc: qemu-stable@nongnu.org Reported-by: Richard W.M. Jones Signed-off-by: Fam Zheng Reviewed-by: Max Reitz Tested-by: Richard W.M. Jones Signed-off-by: Kevin Wolf (cherry picked from commit 13c4941cdd8685d28c7e3a09e393a5579b58db46) Signed-off-by: Michael Roth --- block/vmdk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index bb093dd..bd74050 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -451,7 +451,8 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, Error **errp) { int ret; - int l1_size, i; + size_t l1_size; + int i; /* read the L1 table */ l1_size = extent->l1_size * sizeof(uint32_t); -- 1.9.1