qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] qcow2: Limit total allocation range to INT_MAX
Date: Fri, 11 Oct 2019 12:18:32 +0200	[thread overview]
Message-ID: <7a3842fe-0a99-a8d2-9b24-c22493a80e45@redhat.com> (raw)
In-Reply-To: <20191010100858.1261-2-mreitz@redhat.com>

On 10/10/19 12:08 PM, Max Reitz wrote:
> When the COW areas are included, the size of an allocation can exceed
> INT_MAX.  This is kind of limited by handle_alloc() in that it already
> caps avail_bytes at INT_MAX, but the number of clusters still reflects
> the original length.
> 
> This can have all sorts of effects, ranging from the storage layer write
> call failing to image corruption.  (If there were no image corruption,
> then I suppose there would be data loss because the .cow_end area is
> forced to be empty, even though there might be something we need to
> COW.)
> 
> Fix all of it by limiting nb_clusters so the equivalent number of bytes
> will not exceed INT_MAX.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   block/qcow2-cluster.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index 8d5fa1539c..8982b7b762 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -1330,6 +1330,9 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
>       nb_clusters = MIN(nb_clusters, s->l2_slice_size - l2_index);
>       assert(nb_clusters <= INT_MAX);
>   
> +    /* Limit total allocation byte count to INT_MAX */
> +    nb_clusters = MIN(nb_clusters, INT_MAX >> s->cluster_bits);
> +
>       /* Find L2 entry for the first involved cluster */
>       ret = get_cluster_table(bs, guest_offset, &l2_slice, &l2_index);
>       if (ret < 0) {
> @@ -1412,7 +1415,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
>        * request actually writes to (excluding COW at the end)
>        */
>       uint64_t requested_bytes = *bytes + offset_into_cluster(s, guest_offset);
> -    int avail_bytes = MIN(INT_MAX, nb_clusters << s->cluster_bits);
> +    int avail_bytes = nb_clusters << s->cluster_bits;
>       int nb_bytes = MIN(requested_bytes, avail_bytes);
>       QCowL2Meta *old_m = *m;
>   
> 


  parent reply	other threads:[~2019-10-11 10:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 10:08 [PATCH 0/2] qcow2: Limit total allocation range to INT_MAX Max Reitz
2019-10-10 10:08 ` [PATCH 1/2] " Max Reitz
2019-10-10 15:56   ` Eric Blake
2019-10-11 10:18   ` Philippe Mathieu-Daudé [this message]
2019-10-10 10:08 ` [PATCH 2/2] iotests: Test large write request to qcow2 file Max Reitz
2019-10-10 16:25   ` Eric Blake
2019-10-14 15:12 ` [PATCH 0/2] qcow2: Limit total allocation range to INT_MAX Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a3842fe-0a99-a8d2-9b24-c22493a80e45@redhat.com \
    --to=philmd@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).