All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dave@treblig.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] virtio: fail early on bad config_len in migration
Date: Sat, 25 Jul 2026 20:53:37 +0000	[thread overview]
Message-ID: <amUiUdfC2kpx1qLq@gallifrey> (raw)
In-Reply-To: <cfbefa358af5885eb386637216552bfeba5e7bbc.1784898922.git.mst@redhat.com>

* Michael S. Tsirkin (mst@redhat.com) wrote:
> virtio_load() attempts to load config_len bytes from the migration
> stream. If that's huge (e.g. 4g) this will uselessly spin
> beyond the end of the stream for seconds. Not nice.
> Check qemu_file_get_error() and bail out early, instead.
> 
> Also note that config_len is int32_t but is coerced to unsigned when
> used. Switch it to uint32_t to make this clearer.

That in a way feels like the more important fix (I hate to
think what that MIN(int32_t, size_t) does.

> Fixes: 2f5732e964 ("Allow mismatched virtio config-len")
> Cc: Dr. David Alan Gilbert <dave@treblig.org>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3891
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>

> ---
>  hw/virtio/virtio.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 8add4d5d99..72d828d33f 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3516,7 +3516,7 @@ int coroutine_mixed_fn
>  virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
>  {
>      int i, ret;
> -    int32_t config_len;
> +    uint32_t config_len;
>      uint32_t num;
>      uint32_t features;
>      BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
> @@ -3564,6 +3564,9 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
>      qemu_get_buffer(f, vdev->config, MIN(config_len, vdev->config_len));
>  
>      while (config_len > vdev->config_len) {
> +        if (qemu_file_get_error(f)) {
> +            return -1;
> +        }
>          qemu_get_byte(f);
>          config_len--;
>      }
> -- 
> MST
> 
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/


      reply	other threads:[~2026-07-25 20:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 13:15 [PATCH] virtio: fail early on bad config_len in migration Michael S. Tsirkin
2026-07-25 20:53 ` Dr. David Alan Gilbert [this message]

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=amUiUdfC2kpx1qLq@gallifrey \
    --to=dave@treblig.org \
    --cc=mst@redhat.com \
    --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 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.