qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: kwolf@redhat.com
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] qcow2: Add plausibility check for L1/L2 entries
Date: Fri, 17 Apr 2009 16:02:00 +0200	[thread overview]
Message-ID: <1239976920-4912-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1239969879-5611-1-git-send-email-kwolf@redhat.com>

From: Kevin Wolf <kwolf@redhat.com>

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 <kwolf@redhat.com>
---
 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

  parent reply	other threads:[~2009-04-17 14:02 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-17 12:04 [Qemu-devel] [PATCH 0/5] Add qemu-img check subcommand Kevin Wolf
2009-04-17 12:40 ` [Qemu-devel] [PATCH 1/5] qcow2: Fix warnings in check_refcount() Kevin Wolf
2009-04-17 14:01 ` kwolf
2009-04-17 20:39   ` Anthony Liguori
2009-04-17 21:00     ` Kevin Wolf
2009-04-17 21:03       ` Anthony Liguori
2009-04-17 21:19         ` Kevin Wolf
2009-04-17 22:07           ` Anthony Liguori
2009-04-17 22:29             ` Kevin Wolf
2009-04-17 22:31               ` Anthony Liguori
2009-04-18  0:11                 ` Ryan Harper
2009-04-20 13:48                 ` Christoph Hellwig
2009-04-21 16:19         ` Kevin Wolf
2009-04-20 13:46     ` Christoph Hellwig
2009-04-21 23:12   ` Anthony Liguori
2009-04-17 14:01 ` [Qemu-devel] [PATCH 2/5] Introduce bdrv_check kwolf
2009-04-17 14:01 ` [Qemu-devel] [PATCH 3/5] Introduce qemu-img check subcommand kwolf
2009-04-17 14:01 ` [Qemu-devel] [PATCH 4/5] qcow2: Refcount checking code cleanup kwolf
2009-04-21  8:32   ` [Qemu-devel] [PATCH v2 " Kevin Wolf
2009-04-17 14:02 ` kwolf [this message]
2009-04-20 10:30 ` [Qemu-devel] [PATCH 0/5] Add qemu-img check subcommand Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1239976920-4912-5-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).