Skip to contentSkip to conversation

qcow2: Correct endianness in overlap check

PATCH Applied Max Reitz 3 participants 4 messages Sep 30, 2013 – Oct 2, 2013 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2: Correct endianness in overlap check

If an inactive L1 table is loaded from disk, its entries are in big endian and have to be converted to host byte order before using them.

---
 block/qcow2-refcount.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/qcow2-refcount.c +2 -2
index d2b7064..364eeba 100644
@@ -1733,8 +1733,8 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int chk, int64_t offset,
             }
 
             for (j = 0; j < l1_sz; j++) {
-                if ((l1[j] & L1E_OFFSET_MASK) &&
-                    overlaps_with(l1[j] & L1E_OFFSET_MASK, s->cluster_size)) {
+                uint64_t l2_ofs = be64_to_cpu(l1[j]) & L1E_OFFSET_MASK;
+                if (l2_ofs && overlaps_with(l2_ofs, s->cluster_size)) {
                     g_free(l1);
                     return QCOW2_OL_INACTIVE_L2;
                 }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

Am 30.09.2013 um 08:59 hat Max Reitz geschrieben:

Quoted 4 lines

If an inactive L1 table is loaded from disk, its entries are in big endian and have to be converted to host byte order before using them.

Sounds like there's yet a test case missing? (But it requires the runtime options for enabling these checks, obviously)

Kevin

author
#2 lore raw
Quoted 9 lines · Kevin Wolf

Am 30.09.2013 um 08:59 hat Max Reitz geschrieben:

Quoted 4 lines

If an inactive L1 table is loaded from disk, its entries are in big endian and have to be converted to host byte order before using them.

Sounds like there's yet a test case missing? (But it requires the runtime options for enabling these checks, obviously)

Yes to both. For now, I just couldn't write such a test case.

Max