qcow2: Assert that L2 table offsets fit in the L1 table
PATCH 1/1 qcow2: Assert that L2 table offsets fit in the L1 table
L1 table entries have a field to store the offset of an L2 table. The rest of the bits of the entry are currently reserved except from bit 63, which stores the COPIED flag.
The offset is always taken from the entry using L1E_OFFSET_MASK to ensure that we only use the bits that belong to that field.
While that mask is used every time we read from the L1 table, it is never used when we write to it. Due to the limits set elsewhere in the code QEMU can never produce L2 table offsets that don't fit in that field so any such offset when allocating an L2 table would indicate a bug in QEMU.
--- block/qcow2-cluster.c | 3 +++ 1 file changed, 3 insertions(+)
block/qcow2-cluster.c +3 -0
@@ -285,6 +285,9 @@ static int l2_allocate(BlockDriverState *bs, int l1_index) goto fail; } +/* The offset must fit in the offset field of the L1 table entry */ +assert ((l2_offset &L1E_OFFSET_MASK ) == l2_offset); +/* If we're allocating the table at offset 0 then something is wrong */ if (l2_offset ==0 ) { qcow2_signal_corruption(bs, true, -1, -1, "Preventing invalid "
Signature · 1 line
2.11.0
Quoted 13 lines · Alberto Garcia
L1 table entries have a field to store the offset of an L2 table. The rest of the bits of the entry are currently reserved except from bit 63, which stores the COPIED flag.
The offset is always taken from the entry using
L1E_OFFSET_MASKto ensure that we only use the bits that belong to that field.While that mask is used every time we read from the L1 table, it is never used when we write to it. Due to the limits set elsewhere in the code QEMU can never produce L2 table offsets that don't fit in that field so any such offset when allocating an L2 table would indicate a bug in QEMU.
Quoted 4 lines
Signed-off-by Alberto Garcia <[email protected]>--- block/qcow2-cluster.c | 3 +++ 1 file changed, 3 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
ping
Quoted 34 lines · Alberto Garcia
L1 table entries have a field to store the offset of an L2 table. The rest of the bits of the entry are currently reserved except from bit 63, which stores the COPIED flag.
The offset is always taken from the entry using
L1E_OFFSET_MASKto ensure that we only use the bits that belong to that field.While that mask is used every time we read from the L1 table, it is never used when we write to it. Due to the limits set elsewhere in the code QEMU can never produce L2 table offsets that don't fit in that field so any such offset when allocating an L2 table would indicate a bug in QEMU.
Signed-off-by Alberto Garcia <[email protected]>--- block/qcow2-cluster.c | 3 +++ 1 file changed, 3 insertions(+)block/qcow2-cluster.c +3
-0@@ -285,6 +285,9 @@ static int l2_allocate(BlockDriverState *bs, int l1_index) goto fail; } +/* The offset must fit in the offset field of the L1 table entry */ +assert ((l2_offset &L1E_OFFSET_MASK ) == l2_offset); +/* If we're allocating the table at offset 0 then something is wrong */ if (l2_offset ==0 ) { qcow2_signal_corruption(bs, true, -1, -1, "Preventing invalid "Signature · 1 line
2.11.0
Kevin Wolf
AppliedAm 08.02.2019 um 16:44 hat Alberto Garcia geschrieben:
Quoted 7 lines
L1 table entries have a field to store the offset of an L2 table. The rest of the bits of the entry are currently reserved except from bit 63, which stores the COPIED flag.
The offset is always taken from the entry using
L1E_OFFSET_MASKto ensure that we only use the bits that belong to that field.
Quoted 7 lines
While that mask is used every time we read from the L1 table, it is never used when we write to it. Due to the limits set elsewhere in the code QEMU can never produce L2 table offsets that don't fit in that field so any such offset when allocating an L2 table would indicate a bug in QEMU.
Signed-off-by Alberto Garcia <[email protected]>
Thanks, applied to the block branch.
Kevin