From patchwork Fri Jan 23 18:20:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 432253 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 66988140281 for ; Sat, 24 Jan 2015 05:21:25 +1100 (AEDT) Received: from localhost ([::1]:60757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEirD-0003jm-Hz for incoming@patchwork.ozlabs.org; Fri, 23 Jan 2015 13:21:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEiqN-0002SK-RY for qemu-devel@nongnu.org; Fri, 23 Jan 2015 13:20:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEiqL-0000pd-D1 for qemu-devel@nongnu.org; Fri, 23 Jan 2015 13:20:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEiqK-0000pW-Ri for qemu-devel@nongnu.org; Fri, 23 Jan 2015 13:20:29 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0NIKRwh006517 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 23 Jan 2015 13:20:28 -0500 Received: from noname.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0NIKMBs025228; Fri, 23 Jan 2015 13:20:26 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 23 Jan 2015 19:20:09 +0100 Message-Id: <1422037218-31855-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1422037218-31855-1-git-send-email-kwolf@redhat.com> References: <1422037218-31855-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 03/12] qcow2: Add two more unalignment checks 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: Max Reitz This adds checks for unaligned L2 table offsets and unaligned data cluster offsets (actually the preallocated offsets for zero clusters) to the zero cluster expansion function. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 1fea514..183177d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1651,6 +1651,14 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, continue; } + if (offset_into_cluster(s, l2_offset)) { + qcow2_signal_corruption(bs, true, -1, -1, "L2 table offset %#" + PRIx64 " unaligned (L1 index: %#x)", + l2_offset, i); + ret = -EIO; + goto fail; + } + if (is_active_l1) { /* get active L2 tables from cache */ ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, @@ -1709,6 +1717,19 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, } } + if (offset_into_cluster(s, offset)) { + qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset " + "%#" PRIx64 " unaligned (L2 offset: %#" + PRIx64 ", L2 index: %#x)", offset, + l2_offset, j); + if (!preallocated) { + qcow2_free_clusters(bs, offset, s->cluster_size, + QCOW2_DISCARD_ALWAYS); + } + ret = -EIO; + goto fail; + } + ret = qcow2_pre_write_overlap_check(bs, 0, offset, s->cluster_size); if (ret < 0) { if (!preallocated) {