diff mbox

[2/2] qcow2: Avoid making the L1 table too big

Message ID 20160615153630.2116-3-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Max Reitz June 15, 2016, 3:36 p.m. UTC
We refuse to open images whose L1 table we deem "too big". Consequently,
we should not produce such images ourselves.

Cc: qemu-stable@nongnu.org
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Blake June 15, 2016, 3:43 p.m. UTC | #1
On 06/15/2016 09:36 AM, Max Reitz wrote:
> We refuse to open images whose L1 table we deem "too big". Consequently,
> we should not produce such images ourselves.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2-cluster.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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

> 
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index 893ddf6..335b9b0 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
>          }
>      }
>  
> -    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
> +    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
>          return -EFBIG;
>      }
>  
>
Kevin Wolf July 6, 2016, 8:40 a.m. UTC | #2
Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:
> We refuse to open images whose L1 table we deem "too big". Consequently,
> we should not produce such images ourselves.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2-cluster.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index 893ddf6..335b9b0 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
>          }
>      }
>  
> -    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
> +    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
>          return -EFBIG;
>      }

Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?

Kevin
Max Reitz July 6, 2016, 12:47 p.m. UTC | #3
On 06.07.2016 10:40, Kevin Wolf wrote:
> Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:
>> We refuse to open images whose L1 table we deem "too big". Consequently,
>> we should not produce such images ourselves.
>>
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  block/qcow2-cluster.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
>> index 893ddf6..335b9b0 100644
>> --- a/block/qcow2-cluster.c
>> +++ b/block/qcow2-cluster.c
>> @@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
>>          }
>>      }
>>  
>> -    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
>> +    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
>>          return -EFBIG;
>>      }
> 
> Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?

Good idea, did that. I changed it directly in my block branch, or do you
think a v2 mail necessary?

Max
Kevin Wolf July 6, 2016, 12:54 p.m. UTC | #4
Am 06.07.2016 um 14:47 hat Max Reitz geschrieben:
> On 06.07.2016 10:40, Kevin Wolf wrote:
> > Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:
> >> We refuse to open images whose L1 table we deem "too big". Consequently,
> >> we should not produce such images ourselves.
> >>
> >> Cc: qemu-stable@nongnu.org
> >> Signed-off-by: Max Reitz <mreitz@redhat.com>
> >> ---
> >>  block/qcow2-cluster.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> >> index 893ddf6..335b9b0 100644
> >> --- a/block/qcow2-cluster.c
> >> +++ b/block/qcow2-cluster.c
> >> @@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
> >>          }
> >>      }
> >>  
> >> -    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
> >> +    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
> >>          return -EFBIG;
> >>      }
> > 
> > Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?
> 
> Good idea, did that. I changed it directly in my block branch, or do you
> think a v2 mail necessary?

No, letting you apply it directly is what I intended.

Kevin
diff mbox

Patch

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 893ddf6..335b9b0 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -65,7 +65,7 @@  int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }