Skip to content

Commit 289ef5f

Browse files
Vladimir Sementsov-OgievskiyXanClic
authored andcommitted
qcow2-refcount: check_refcounts_l2(): check reserved bits
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Eric Blake <[email protected]> Tested-by: Kirill Tkhai <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> [hreitz: Separated `type` declaration from statements] Signed-off-by: Hanna Reitz <[email protected]>
1 parent 9631c78 commit 289ef5f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

block/qcow2-refcount.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,10 +1680,22 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
16801680
for (i = 0; i < s->l2_size; i++) {
16811681
uint64_t coffset;
16821682
int csize;
1683+
QCow2ClusterType type;
1684+
16831685
l2_entry = get_l2_entry(s, l2_table, i);
16841686
l2_bitmap = get_l2_bitmap(s, l2_table, i);
1687+
type = qcow2_get_cluster_type(bs, l2_entry);
1688+
1689+
if (type != QCOW2_CLUSTER_COMPRESSED) {
1690+
/* Check reserved bits of Standard Cluster Descriptor */
1691+
if (l2_entry & L2E_STD_RESERVED_MASK) {
1692+
fprintf(stderr, "ERROR found l2 entry with reserved bits set: "
1693+
"%" PRIx64 "\n", l2_entry);
1694+
res->corruptions++;
1695+
}
1696+
}
16851697

1686-
switch (qcow2_get_cluster_type(bs, l2_entry)) {
1698+
switch (type) {
16871699
case QCOW2_CLUSTER_COMPRESSED:
16881700
/* Compressed clusters don't have QCOW_OFLAG_COPIED */
16891701
if (l2_entry & QCOW_OFLAG_COPIED) {

block/qcow2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ typedef enum QCow2MetadataOverlap {
587587

588588
#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
589589
#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
590+
#define L2E_STD_RESERVED_MASK 0x3f000000000001feULL
590591

591592
#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
592593

0 commit comments

Comments
 (0)