All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table
@ 2019-02-08 15:44 Alberto Garcia
  2019-02-08 15:50 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alberto Garcia @ 2019-02-08 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alberto Garcia, qemu-block, Kevin Wolf, Max Reitz

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.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/qcow2-cluster.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 30eca26c47..179aa2c728 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -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 "
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table
  2019-02-08 15:44 [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table Alberto Garcia
@ 2019-02-08 15:50 ` Eric Blake
  2019-02-25 13:06 ` Alberto Garcia
  2019-02-25 14:05 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2019-02-08 15:50 UTC (permalink / raw)
  To: Alberto Garcia, qemu-devel; +Cc: Kevin Wolf, qemu-block, Max Reitz

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

On 2/8/19 9:44 AM, Alberto Garcia wrote:
> 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.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/qcow2-cluster.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table
  2019-02-08 15:44 [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table Alberto Garcia
  2019-02-08 15:50 ` Eric Blake
@ 2019-02-25 13:06 ` Alberto Garcia
  2019-02-25 14:05 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Alberto Garcia @ 2019-02-25 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, Kevin Wolf, Max Reitz

ping

On Fri 08 Feb 2019 04:44:53 PM CET, Alberto Garcia wrote:
> 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.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/qcow2-cluster.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index 30eca26c47..179aa2c728 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -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 "
> -- 
> 2.11.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table
  2019-02-08 15:44 [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table Alberto Garcia
  2019-02-08 15:50 ` Eric Blake
  2019-02-25 13:06 ` Alberto Garcia
@ 2019-02-25 14:05 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2019-02-25 14:05 UTC (permalink / raw)
  To: Alberto Garcia; +Cc: qemu-devel, qemu-block, Max Reitz

Am 08.02.2019 um 16:44 hat Alberto Garcia geschrieben:
> 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.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-25 14:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-08 15:44 [Qemu-devel] [PATCH] qcow2: Assert that L2 table offsets fit in the L1 table Alberto Garcia
2019-02-08 15:50 ` Eric Blake
2019-02-25 13:06 ` Alberto Garcia
2019-02-25 14:05 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.