From patchwork Mon Aug 7 03:08:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9884323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E230603F2 for ; Mon, 7 Aug 2017 03:09:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36EFE28537 for ; Mon, 7 Aug 2017 03:09:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B65828538; Mon, 7 Aug 2017 03:09:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B259928477 for ; Mon, 7 Aug 2017 03:09:40 +0000 (UTC) Received: from localhost ([::1]:35135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deYQE-0003jB-6h for patchwork-qemu-devel@patchwork.kernel.org; Sun, 06 Aug 2017 23:09:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deYP9-0003h3-4o for qemu-devel@nongnu.org; Sun, 06 Aug 2017 23:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deYP8-0005q2-0Y for qemu-devel@nongnu.org; Sun, 06 Aug 2017 23:08:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1deYP4-0005oB-GA; Sun, 06 Aug 2017 23:08:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1595278EB7; Mon, 7 Aug 2017 03:08:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1595278EB7 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDB8581E1A; Mon, 7 Aug 2017 03:08:23 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Sun, 6 Aug 2017 23:08:20 -0400 Message-Id: <403586fbd705655c9e861b9e57648b598b651896.1502075213.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 07 Aug 2017 03:08:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] block/vhdx: check for offset overflow to bdrv_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP VHDX uses uint64_t types for most offsets, following the VHDX spec. However, bdrv_truncate() takes an int64_t value for the truncating offset. Check for overflow before calling bdrv_truncate(). N.B.: For a compliant image this is not an issue, as the maximum VHDX image size is defined per the spec to be 64TB. Signed-off-by: Jeff Cody Reviewed-by: Kevin Wolf Reviewed-by: Eric Blake --- block/vhdx-log.c | 4 ++++ block/vhdx.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/block/vhdx-log.c b/block/vhdx-log.c index fd4e7af..3b74e5d 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -554,6 +554,10 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s, if (new_file_size % (1024*1024)) { /* round up to nearest 1MB boundary */ new_file_size = ((new_file_size >> 20) + 1) << 20; + if (new_file_size > INT64_MAX) { + ret = -EINVAL; + goto exit; + } bdrv_truncate(bs->file, new_file_size, PREALLOC_MODE_OFF, NULL); } } diff --git a/block/vhdx.c b/block/vhdx.c index 6a14999..c45af73 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1177,6 +1177,9 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s, /* per the spec, the address for a block is in units of 1MB */ *new_offset = ROUND_UP(*new_offset, 1024 * 1024); + if (*new_offset > INT64_MAX) { + return -EINVAL; + } return bdrv_truncate(bs->file, *new_offset + s->block_size, PREALLOC_MODE_OFF, NULL);