From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-stable <qemu-stable@nongnu.org>,
Yuan Liu <yuan1.liu@intel.com>,
Yichen Wang <yichen.wang@bytedance.com>
Subject: [PULL 08/10] migration/multifd: Replace assert() with error_setg() in recv paths
Date: Wed, 12 Aug 2026 11:14:41 -0400 [thread overview]
Message-ID: <20260812151444.2611689-9-peterx@redhat.com> (raw)
In-Reply-To: <20260812151444.2611689-1-peterx@redhat.com>
QPL and UADK multifd backends use assert() to validate wire-controlled
fields like per-page compressed lengths and packet size consistency. These
asserts will stop working with -DNDEBUG builds, so may stop working.
Replace all assert() calls in the receive path with proper error_setg() so
validation failures are reported gracefully rather than crashing or
silently ignored.
While at it, touch up an assert() in qatzip recv path too.
Cc: qemu-stable <qemu-stable@nongnu.org>
Cc: Yuan Liu <yuan1.liu@intel.com>
Cc: Yichen Wang <yichen.wang@bytedance.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20260728210417.1925078-4-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/multifd-qatzip.c | 5 ++++-
migration/multifd-qpl.c | 24 ++++++++++++++++++++----
migration/multifd-uadk.c | 24 ++++++++++++++++++++----
3 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/migration/multifd-qatzip.c b/migration/multifd-qatzip.c
index 7419e5dc0d..0262e81eac 100644
--- a/migration/multifd-qatzip.c
+++ b/migration/multifd-qatzip.c
@@ -348,7 +348,10 @@ static int qatzip_recv(MultiFDRecvParams *p, Error **errp)
multifd_recv_zero_page_process(p);
if (!p->normal_num) {
- assert(in_size == 0);
+ if (in_size != 0) {
+ error_setg(errp, "multifd %u: expected empty packet", p->id);
+ return -1;
+ }
return 0;
}
diff --git a/migration/multifd-qpl.c b/migration/multifd-qpl.c
index 52902eb00c..3826e7f340 100644
--- a/migration/multifd-qpl.c
+++ b/migration/multifd-qpl.c
@@ -664,26 +664,42 @@ static int multifd_qpl_recv(MultiFDRecvParams *p, Error **errp)
}
multifd_recv_zero_page_process(p);
if (!p->normal_num) {
- assert(in_size == 0);
+ if (in_size != 0) {
+ error_setg(errp, "multifd %u: expected empty packet", p->id);
+ return -1;
+ }
return 0;
}
/* read compressed page lengths */
len = p->normal_num * sizeof(uint32_t);
- assert(len < in_size);
+ if (len >= in_size) {
+ error_setg(errp, "multifd %u: header len %"PRIu32
+ " >= packet size %"PRIu32, p->id, len, in_size);
+ return -1;
+ }
ret = qio_channel_read_all(p->c, (void *) qpl->zlen, len, errp);
if (ret != 0) {
return ret;
}
for (int i = 0; i < p->normal_num; i++) {
qpl->zlen[i] = be32_to_cpu(qpl->zlen[i]);
- assert(qpl->zlen[i] <= multifd_ram_page_size());
+ if (qpl->zlen[i] > multifd_ram_page_size()) {
+ error_setg(errp, "multifd %u: page %d compressed len %"
+ PRIu32" too large", p->id, i, qpl->zlen[i]);
+ return -1;
+ }
zbuf_len += qpl->zlen[i];
ramblock_recv_bitmap_set_offset(p->block, p->normal[i]);
}
/* read compressed pages */
- assert(in_size == len + zbuf_len);
+ if (in_size != len + zbuf_len) {
+ error_setg(errp, "multifd %u: packet size %"PRIu32
+ " != header %"PRIu32" + data %"PRIu32,
+ p->id, in_size, len, zbuf_len);
+ return -1;
+ }
ret = qio_channel_read_all(p->c, (void *) qpl->zbuf, zbuf_len, errp);
if (ret != 0) {
return ret;
diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
index fd7cd9b5e8..d373615ba8 100644
--- a/migration/multifd-uadk.c
+++ b/migration/multifd-uadk.c
@@ -245,12 +245,19 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
multifd_recv_zero_page_process(p);
if (!p->normal_num) {
- assert(in_size == 0);
+ if (in_size != 0) {
+ error_setg(errp, "multifd %u: expected empty packet", p->id);
+ return -1;
+ }
return 0;
}
/* read compressed data lengths */
- assert(hdr_len < in_size);
+ if (hdr_len >= in_size) {
+ error_setg(errp, "multifd %u: header len %"PRIu32
+ " >= packet size %"PRIu32, p->id, hdr_len, in_size);
+ return -1;
+ }
ret = qio_channel_read_all(p->c, (void *) uadk_data->buf_hdr,
hdr_len, errp);
if (ret != 0) {
@@ -259,12 +266,21 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
for (int i = 0; i < p->normal_num; i++) {
uadk_data->buf_hdr[i] = be32_to_cpu(uadk_data->buf_hdr[i]);
+ if (uadk_data->buf_hdr[i] > page_size) {
+ error_setg(errp, "multifd %u: page %d compressed len %"PRIu32
+ " too large", p->id, i, uadk_data->buf_hdr[i]);
+ return -1;
+ }
data_len += uadk_data->buf_hdr[i];
- assert(uadk_data->buf_hdr[i] <= page_size);
}
/* read compressed data */
- assert(in_size == hdr_len + data_len);
+ if (in_size != hdr_len + data_len) {
+ error_setg(errp, "multifd %u: packet size %"PRIu32
+ " != header %"PRIu32" + data %"PRIu32,
+ p->id, in_size, hdr_len, data_len);
+ return -1;
+ }
ret = qio_channel_read_all(p->c, (void *)buf, data_len, errp);
if (ret != 0) {
return ret;
--
2.54.0
next prev parent reply other threads:[~2026-08-12 15:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 15:14 [PULL 00/10] Next patches Peter Xu
2026-08-12 15:14 ` [PULL 01/10] docs: Add security considerations for migration Peter Xu
2026-08-12 15:14 ` [PULL 02/10] migration/cpr: Add HMP support for cpr-transfer Peter Xu
2026-08-12 15:14 ` [PULL 03/10] system/memory: Use memmove() for directly accessible regions Peter Xu
2026-08-12 15:14 ` [PULL 04/10] system/memory: Use qemu_ram_move() " Peter Xu
2026-08-12 15:14 ` [PULL 05/10] system/memory: Make ram device region directly accessible Peter Xu
2026-08-12 15:14 ` [PULL 06/10] tests/qtest/migration: Only build tls_no_hostname test with TASN1 Peter Xu
2026-08-12 15:14 ` [PULL 07/10] migration/multifd: Validate next_packet_size in zlib/zstd recv Peter Xu
2026-08-12 15:14 ` Peter Xu [this message]
2026-08-12 15:14 ` [PULL 09/10] migration/ram: Check for RAMBlock size mismatch when parsing Peter Xu
2026-08-12 15:14 ` [PULL 10/10] migration: Fix rare hang of migration_channel_read_peek() Peter Xu
2026-08-12 22:01 ` [PULL 00/10] Next patches Richard Henderson
2026-08-13 12:38 ` Peter Xu
2026-08-13 13:41 ` Peter Xu
2026-08-13 14:14 ` Richard Henderson
2026-08-13 14:51 ` Philippe Mathieu-Daudé
2026-08-13 15:05 ` Peter Xu
2026-08-13 15:18 ` Philippe Mathieu-Daudé
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=20260812151444.2611689-9-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=yichen.wang@bytedance.com \
--cc=yuan1.liu@intel.com \
/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.