Skip to content

Commit

Permalink
qcow2: Add plausibility check for L1/L2 entries (Kevin Wolf)
Browse files Browse the repository at this point in the history
From: Kevin Wolf <[email protected]>

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 <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7217 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
aliguori committed Apr 21, 2009
1 parent ae2f14a commit 54c4236
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions block-qcow2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 54c4236

Please sign in to comment.