From patchwork Wed Dec 4 14:34:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 296552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7E8002C007C for ; Thu, 5 Dec 2013 02:18:32 +1100 (EST) Received: from localhost ([::1]:48849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoEDe-0004zL-FM for incoming@patchwork.ozlabs.org; Wed, 04 Dec 2013 10:18:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoDY1-0002Sz-RB for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoDXg-0003Cd-Jf for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:29 -0500 Received: from e32.co.us.ibm.com ([32.97.110.150]:37934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoDXg-0003CK-5S for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:08 -0500 Received: from /spool/local by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Dec 2013 07:35:07 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Dec 2013 07:35:05 -0700 Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id DB46719D8053; Wed, 4 Dec 2013 07:34:58 -0700 (MST) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by b03cxnp07027.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rB4CX0Uw57344002; Wed, 4 Dec 2013 13:33:00 +0100 Received: from d03av05.boulder.ibm.com (localhost [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rB4EZ4en019200; Wed, 4 Dec 2013 07:35:04 -0700 Received: from localhost ([9.41.105.190]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rB4EZ4PO019159; Wed, 4 Dec 2013 07:35:04 -0700 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 4 Dec 2013 08:34:32 -0600 Message-Id: <1386167679-13021-26-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1386167679-13021-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1386167679-13021-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13120414-0928-0000-0000-000004501F34 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.110.150 Cc: qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 25/32] qcow2: fix possible corruption when reading multiple clusters 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: Peter Lieven if multiple sectors spanning multiple clusters are read the function count_contiguous_clusters should ensure that the cluster type should not change between the clusters. Especially the for-loop should break when we have one or more normal clusters followed by a compressed cluster. Unfortunately the wrong macro was used in the mask to compare the flags. This was discovered while debugging a data corruption issue when converting a compressed qcow2 image to raw. qemu-img reads 2MB chunks which span multiple clusters. CC: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf (cherry picked from commit 78a52ad5acca7053b774fcc80290e7b7e224c80a) Signed-off-by: Michael Roth --- block/qcow2-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index fd3054b..b558eb0 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -266,7 +266,7 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, uint64_t *l2_table, uint64_t start, uint64_t stop_flags) { int i; - uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED; + uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; uint64_t first_entry = be64_to_cpu(l2_table[0]); uint64_t offset = first_entry & mask;