From: Peter Xu <peterx@redhat.com>
To: Junjie Cao <junjie.cao@intel.com>
Cc: qemu-devel@nongnu.org, farosas@suse.de,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data
Date: Mon, 16 Mar 2026 16:41:24 -0400 [thread overview]
Message-ID: <abhq9BzuP2bZPLBg@x1.local> (raw)
In-Reply-To: <20260316084618.52-1-junjie.cao@intel.com>
On Mon, Mar 16, 2026 at 04:46:18PM +0800, Junjie Cao wrote:
> 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 changing ret to ssize_t and splitting the error
> handling: use error_prepend() only when qio_channel_pread() itself
> has populated *errp (ret < 0), and error_setg() for the short-read
> case where *errp has not been set. Add ERRP_GUARD() so that
> error_prepend() works correctly even when errp is &error_fatal or
> NULL.
Indeed, this seems problematic.
But is it possible to get partial reads? I don't see why it won't happen..
do we need to fix it too (e.g. introduce qio_channel_pread_all_eof())?
CC Dan.
Thanks,
>
> Signed-off-by: Junjie Cao <junjie.cao@intel.com>
> ---
> migration/file.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/migration/file.c b/migration/file.c
> index 5618aced49..78b274dc32 100644
> --- a/migration/file.c
> +++ b/migration/file.c
> @@ -254,15 +254,21 @@ 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;
> + ssize_t ret;
>
> ret = qio_channel_pread(p->c, (char *) data->opaque,
> data->size, data->file_offset, errp);
> + if (ret < 0) {
> + error_prepend(errp, "multifd recv (%u): ", p->id);
> + return -1;
> + }
> +
> if (ret != data->size) {
> - error_prepend(errp,
> - "multifd recv (%u): read 0x%zx, expected 0x%zx",
> - p->id, ret, data->size);
> + error_setg(errp,
> + "multifd recv (%u): read 0x%zx, expected 0x%zx",
> + p->id, (size_t)ret, data->size);
> return -1;
> }
>
> --
> 2.43.0
>
--
Peter Xu
next prev parent reply other threads:[~2026-03-16 20:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 8:46 [PATCH] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Junjie Cao
2026-03-16 20:41 ` Peter Xu [this message]
2026-03-17 8:58 ` Daniel P. Berrangé
2026-03-18 14:01 ` [PATCH v2 0/3] " Junjie Cao
2026-03-18 14:01 ` [PATCH v2 1/3] io/channel: introduce qio_channel_pread{v, }_all() and preadv_all_eof() Junjie Cao
2026-03-24 10:51 ` Daniel P. Berrangé via qemu development
2026-03-18 14:01 ` [PATCH v2 2/3] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Junjie Cao
2026-03-24 10:53 ` Daniel P. Berrangé
2026-03-18 14:01 ` [PATCH v2 3/3] tests/unit: add pread_all and preadv_all tests for io channel file Junjie Cao
2026-03-24 8:27 ` [PATCH v2 0/3] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Junjie Cao
2026-03-24 10:54 ` Daniel P. Berrangé
2026-03-26 15:21 ` Peter Xu
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=abhq9BzuP2bZPLBg@x1.local \
--to=peterx@redhat.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=junjie.cao@intel.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.