All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Junjie Cao <junjie.cao@intel.com>, qemu-devel@nongnu.org
Cc: berrange@redhat.com, peterx@redhat.com, junjie.cao@intel.com
Subject: Re: [PATCH v3 3/4] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data
Date: Tue, 14 Apr 2026 12:55:38 -0300	[thread overview]
Message-ID: <87bjflzgcl.fsf@suse.de> (raw)
In-Reply-To: <20260413214549.926435-4-junjie.cao@intel.com>

Junjie Cao <junjie.cao@intel.com> writes:

> multifd_file_recv_data() stores the return value of qio_channel_pread()
> (ssize_t) in a size_t variable.  On I/O error the -1 return value wraps
> to SIZE_MAX, producing a nonsensical read size in the error message.
>
> More critically, a short read (0 <= ret < data->size) is possible when
> the migration file is truncated.  In that case qio_channel_pread()
> returns a non-negative value without setting *errp.  The function then
> calls error_prepend(errp, ...) which dereferences *errp -- a NULL
> pointer -- crashing QEMU.
>
> Fix both issues by switching to qio_channel_pread_all() introduced in
> a previous patch, which retries on short reads and treats end-of-file
> as an error, so the caller no longer needs to check the byte count
> manually.  Add ERRP_GUARD() so that error_prepend() works correctly
> even when errp is &error_fatal or NULL.
>
> Fixes: a49d15a38d3d ("migration/multifd: Support incoming mapped-ram stream format")
> Suggested-by: Peter Xu <peterx@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Junjie Cao <junjie.cao@intel.com>
> ---
>  migration/file.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/migration/file.c b/migration/file.c
> index 5618aced49..0853188601 100644
> --- a/migration/file.c
> +++ b/migration/file.c
> @@ -254,15 +254,16 @@ int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov,
>  
>  int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp)
>  {
> +    ERRP_GUARD();
>      MultiFDRecvData *data = p->data;
> -    size_t ret;
> +    int ret;
>  
> -    ret = qio_channel_pread(p->c, (char *) data->opaque,
> -                            data->size, data->file_offset, errp);
> -    if (ret != data->size) {
> +    ret = qio_channel_pread_all(p->c, (char *) data->opaque,
> +                                data->size, data->file_offset, errp);
> +    if (ret != 0) {
>          error_prepend(errp,
> -                      "multifd recv (%u): read 0x%zx, expected 0x%zx",
> -                      p->id, ret, data->size);
> +                      "multifd recv (%u): ",
> +                      p->id);
>          return -1;
>      }

Reviewed-by: Fabiano Rosas <farosas@suse.de>


  reply	other threads:[~2026-04-14 15:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 21:45 [PATCH v3 0/4] io/channel: complete pread/pwrite_all API and fix multifd_file_recv_data Junjie Cao
2026-04-13 21:45 ` [PATCH v3 1/4] io/channel: introduce qio_channel_pread{v, }_all{, _eof}() Junjie Cao
2026-04-14 15:49   ` Fabiano Rosas
2026-04-17  9:45   ` [PATCH v3 1/4] io/channel: introduce qio_channel_pread{v,}_all{,_eof}() Daniel P. Berrangé
2026-04-13 21:45 ` [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v,}_all() Junjie Cao
2026-04-14 15:54   ` [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v, }_all() Fabiano Rosas
2026-04-17  9:46   ` Daniel P. Berrangé via qemu development
2026-04-13 21:45 ` [PATCH v3 3/4] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Junjie Cao
2026-04-14 15:55   ` Fabiano Rosas [this message]
2026-04-13 21:45 ` [PATCH v3 4/4] tests/unit: add pread/pwrite _all tests for io channel file Junjie Cao
2026-04-14 16:01   ` Fabiano Rosas
2026-04-17  9:47   ` Daniel P. Berrangé
2026-04-17 16:51 ` [PATCH v3 0/4] io/channel: complete pread/pwrite_all API and fix multifd_file_recv_data Junjie Cao
2026-04-17  9:48   ` Daniel P. Berrangé
2026-04-17 14:04     ` Peter Xu
2026-04-26  8:15 ` Michael Tokarev
2026-04-26  8:21   ` Michael Tokarev
2026-04-29 14:24     ` Fabiano Rosas

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=87bjflzgcl.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=berrange@redhat.com \
    --cc=junjie.cao@intel.com \
    --cc=peterx@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.