From patchwork Fri Aug 5 09:24:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9265071 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 3311060839 for ; Fri, 5 Aug 2016 09:25:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 231472804C for ; Fri, 5 Aug 2016 09:25:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17E8F283FC; Fri, 5 Aug 2016 09:25:26 +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 2732C2804C for ; Fri, 5 Aug 2016 09:25:25 +0000 (UTC) Received: from localhost ([::1]:43723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVbNc-0003Bl-2w for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Aug 2016 05:25:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVbN3-000380-Rh for qemu-devel@nongnu.org; Fri, 05 Aug 2016 05:24:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVbN1-0000NC-LD for qemu-devel@nongnu.org; Fri, 05 Aug 2016 05:24:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVbN1-0000Mw-FA for qemu-devel@nongnu.org; Fri, 05 Aug 2016 05:24:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D20DBDA5; Fri, 5 Aug 2016 09:24:46 +0000 (UTC) Received: from localhost (ovpn-112-69.ams2.redhat.com [10.36.112.69]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u759Oik7013333; Fri, 5 Aug 2016 05:24:45 -0400 From: Stefan Hajnoczi To: Date: Fri, 5 Aug 2016 10:24:38 +0100 Message-Id: <1470389082-15298-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1470389082-15298-1-git-send-email-stefanha@redhat.com> References: <1470389082-15298-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 05 Aug 2016 09:24:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.7 1/5] block/parallels: check new image size 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: "Denis V . Lunev" , Peter Maydell , Stefan Hajnoczi , Klim Kireev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Klim Kireev Before this patch incorrect image could be created via qemu-img (Example: qemu-img create -f parallels -o size=4096T hack.img), incorrect images cannot be used due to overflow in main image structure. This patch add check of size in image creation. After reading size it compare it with UINT32_MAX * cluster_size. Signed-off-by: Klim Kireev Signed-off-by: Denis V. Lunev Message-id: 1469639300-12155-1-git-send-email-den@openvz.org CC: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi --- block/parallels.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index 807a801..2ccefa7 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -43,6 +43,7 @@ #define HEADER_MAGIC2 "WithouFreSpacExt" #define HEADER_VERSION 2 #define HEADER_INUSE_MAGIC (0x746F6E59) +#define MAX_PARALLELS_IMAGE_FACTOR (1ull << 32) #define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ @@ -475,6 +476,10 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) BDRV_SECTOR_SIZE); cl_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, DEFAULT_CLUSTER_SIZE), BDRV_SECTOR_SIZE); + if (total_size >= MAX_PARALLELS_IMAGE_FACTOR * cl_size) { + error_propagate(errp, local_err); + return -E2BIG; + } ret = bdrv_create_file(filename, opts, &local_err); if (ret < 0) {