From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LuoeF-0001Dn-DV for qemu-devel@nongnu.org; Fri, 17 Apr 2009 10:02:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LuoeA-0001Ab-FY for qemu-devel@nongnu.org; Fri, 17 Apr 2009 10:02:30 -0400 Received: from [199.232.76.173] (port=47601 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LuoeA-0001AT-8s for qemu-devel@nongnu.org; Fri, 17 Apr 2009 10:02:26 -0400 Received: from mo-p05-ob.rzone.de ([81.169.146.182]:44139) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Luoe9-0005pc-L6 for qemu-devel@nongnu.org; Fri, 17 Apr 2009 10:02:25 -0400 From: kwolf@redhat.com Date: Fri, 17 Apr 2009 16:02:00 +0200 Message-Id: <1239976920-4912-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1239969879-5611-1-git-send-email-kwolf@redhat.com> References: <1239969879-5611-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 5/5] qcow2: Add plausibility check for L1/L2 entries Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf From: Kevin Wolf All L1 and L2 entries must point at the start of a cluster. If there is some offset into the cluster, the entry is corrupted. Signed-off-by: Kevin Wolf --- block-qcow2.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/block-qcow2.c b/block-qcow2.c index 2e91e6e..25c1d23 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -2666,6 +2666,13 @@ static int check_refcounts_l2(BlockDriverState *bs, errors += inc_refcounts(bs, refcount_table, refcount_table_size, offset, s->cluster_size); + + /* Correct offsets are cluster aligned */ + if (offset & (s->cluster_size - 1)) { + fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not " + "properly aligned; L2 entry corrupted.\n", offset); + errors++; + } } } } @@ -2734,6 +2741,13 @@ static int check_refcounts_l1(BlockDriverState *bs, l2_offset, s->cluster_size); + /* L2 tables are cluster aligned */ + if (l2_offset & (s->cluster_size - 1)) { + fprintf(stderr, "ERROR l2_offset=%" PRIx64 ": Table is not " + "cluster aligned; L1 entry corrupted\n", l2_offset); + errors++; + } + /* Process and check L2 entries */ ret = check_refcounts_l2(bs, refcount_table, refcount_table_size, l2_offset, check_copied); -- 1.6.0.6