From patchwork Fri May 22 15:26:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 475664 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 6CB6C1402A5 for ; Sat, 23 May 2015 01:31:45 +1000 (AEST) Received: from localhost ([::1]:34587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvovH-00049a-Jj for incoming@patchwork.ozlabs.org; Fri, 22 May 2015 11:31:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvoqZ-0004Fs-MV for qemu-devel@nongnu.org; Fri, 22 May 2015 11:26:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YvoqY-0006XV-Po for qemu-devel@nongnu.org; Fri, 22 May 2015 11:26:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47705) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvoqW-0006WS-WC; Fri, 22 May 2015 11:26:49 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id A7A592BB38D; Fri, 22 May 2015 15:26:48 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4MFQf9V016774; Fri, 22 May 2015 11:26:47 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 22 May 2015 17:26:22 +0200 Message-Id: <1432308400-13958-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1432308400-13958-1-git-send-email-kwolf@redhat.com> References: <1432308400-13958-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 04/22] vmdk: Fix overflow if l1_size is 0x20000000 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 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 --- block/vmdk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index 4b4a862..b66745d 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);