From patchwork Sat Sep 10 08:23:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 114149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AE804B6F85 for ; Sat, 10 Sep 2011 18:23:30 +1000 (EST) Received: from localhost ([::1]:54435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2IqU-000835-6a for incoming@patchwork.ozlabs.org; Sat, 10 Sep 2011 04:23:26 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2IqP-00082m-1q for qemu-devel@nongnu.org; Sat, 10 Sep 2011 04:23:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R2IqN-0007An-VF for qemu-devel@nongnu.org; Sat, 10 Sep 2011 04:23:21 -0400 Received: from mail-fx0-f45.google.com ([209.85.161.45]:55338) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2IqN-0007Aj-Ql for qemu-devel@nongnu.org; Sat, 10 Sep 2011 04:23:19 -0400 Received: by fxh13 with SMTP id 13so206633fxh.4 for ; Sat, 10 Sep 2011 01:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=jwwy5rY9x9sy3IPpgOBm+/lMJkWRd9uKyYWu4Ovnm3c=; b=G0jG83z0dQyODBRSWb6ijOCL0t1jhjGjF+M79iWFRqph6NYeiF5uoX9Vunfm1FcJxc HQDxC+LmIk2eqhIc0z33MxTqwNH7goM70ileLBKi2vI6bvyDIQ5p5Xj94PX2X4cx3Mw5 o4igdVntFe+IRjOPaxyOGWZWseCUChAmqwscc= Received: by 10.223.17.3 with SMTP id q3mr1478728faa.71.1315642998535; Sat, 10 Sep 2011 01:23:18 -0700 (PDT) Received: from obol602.localdomain (net-2-37-111-0.cust.dsl.vodafone.it [2.37.111.0]) by mx.google.com with ESMTPS id g5sm3320719fad.19.2011.09.10.01.23.16 (version=SSLv3 cipher=OTHER); Sat, 10 Sep 2011 01:23:17 -0700 (PDT) From: Frediano Ziglio To: kwolf@redhat.com Date: Sat, 10 Sep 2011 10:23:56 +0200 Message-Id: <1315643036-22322-1-git-send-email-freddy77@gmail.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.45 Cc: qemu-devel@nongnu.org, Frediano Ziglio Subject: [Qemu-devel] [PATCH] qcow2: fix range check 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 QCowL2Meta::offset is not cluster aligned but only sector aligned however nb_clusters count cluster from cluster start. This fix range check. Note that old code have no corruption issues related to this check cause it only cause intersection to occur when shouldn't. Signed-off-by: Frediano Ziglio --- block/qcow2-cluster.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 428b5ad..2f76311 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -776,17 +776,17 @@ again: */ QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) { - uint64_t end_offset = offset + nb_clusters * s->cluster_size; - uint64_t old_offset = old_alloc->offset; - uint64_t old_end_offset = old_alloc->offset + - old_alloc->nb_clusters * s->cluster_size; + uint64_t start = offset >> s->cluster_bits; + uint64_t end = start + nb_clusters; + uint64_t old_start = old_alloc->offset >> s->cluster_bits; + uint64_t old_end = old_start + old_alloc->nb_clusters; - if (end_offset < old_offset || offset > old_end_offset) { + if (end < old_start || start > old_end) { /* No intersection */ } else { - if (offset < old_offset) { + if (start < old_start) { /* Stop at the start of a running allocation */ - nb_clusters = (old_offset - offset) >> s->cluster_bits; + nb_clusters = old_start - start; } else { nb_clusters = 0; }