From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFUbZ-0005bi-LU for qemu-devel@nongnu.org; Thu, 07 Aug 2014 16:48:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFUbR-0006M8-Mg for qemu-devel@nongnu.org; Thu, 07 Aug 2014 16:48:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFUbR-0006M4-EX for qemu-devel@nongnu.org; Thu, 07 Aug 2014 16:48:01 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s77Km0vN014469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 7 Aug 2014 16:48:00 -0400 From: Max Reitz Date: Thu, 7 Aug 2014 22:47:53 +0200 Message-Id: <1407444475-19516-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1407444475-19516-1-git-send-email-mreitz@redhat.com> References: <1407444475-19516-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] qcow2: Catch !*host_offset for data allocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz qcow2_alloc_cluster_offset() uses host_offset == 0 as "no preferred offset" for the (data) cluster range to be allocated. However, this offset is actually valid and may be allocated on images with a corrupted refcount table or first refcount block. In this case, the corruption prevention should normally catch that write anyway (because it would overwrite the image header). But since 0 is a special value here, the function assumes that nothing has been allocated at all which it asserts against. Because this condition is not qemu's fault but rather that of a broken image, it shouldn't throw an assertion but rather mark the image corrupt and show an appropriate message, which this patch does by calling the corruption check earlier than it would be called normally (before the assertion). Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 4208dc0..c6af456 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1106,6 +1106,17 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, return 0; } + /* !*host_offset would overwrite the image header and is reserved for "no + * host offset preferred". If 0 was a valid host offset, it'd trigger the + * following overlap check; do that now to avoid having an invalid value in + * *host_offset. */ + if (!alloc_cluster_offset) { + ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset, + nb_clusters * s->cluster_size); + assert(ret < 0); + goto fail; + } + /* * Save info needed for meta data update. * -- 2.0.3