OSDN Git Service

qcow2: Assert that host cluster offsets fit in L2 table entries
authorAlberto Garcia <berto@igalia.com>
Mon, 13 Jan 2020 16:11:46 +0000 (17:11 +0100)
committerMax Reitz <mreitz@redhat.com>
Thu, 6 Feb 2020 12:47:45 +0000 (13:47 +0100)
commit3a75a870ef51f79c2b5f7fc8f7756f9efb500a14
treea21657434086b45c96f211add5823ef20a9b6fdf
parent418fa86dd465b4fd8394373cf83db8fa65d7611c
qcow2: Assert that host cluster offsets fit in L2 table entries

The standard cluster descriptor in L2 table entries has a field to
store the host cluster offset. When we need to get that offset from an
entry we use L2E_OFFSET_MASK to ensure that we only use the bits that
belong to that field.

But while that mask is used every time we read from an L2 entry, it
is never used when we write to it. Due to the QCOW_MAX_CLUSTER_OFFSET
limit set in the cluster allocation code QEMU can never produce
offsets that don't fit in that field so any such offset would indicate
a bug in QEMU.

Compressed cluster descriptors contain two fields (host cluster offset
and size of the compressed data) and the situation with them is
similar. In this case the masks are not constant but are stored in the
csize_mask and cluster_offset_mask fields of BDRVQcow2State.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20200113161146.20099-1-berto@igalia.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
block/qcow2-cluster.c