From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, Fabiano Rosas <farosas@suse.de>,
Juraj Marcin <jmarcin@redhat.com>,
Tristan Madani <tristan@talencesecurity.com>
Subject: [PATCH 5/5] migration/ram: Check for RAMBlock size mismatch when parsing
Date: Tue, 28 Jul 2026 11:52:47 -0400 [thread overview]
Message-ID: <20260728155247.1894355-6-peterx@redhat.com> (raw)
In-Reply-To: <20260728155247.1894355-1-peterx@redhat.com>
Add an underflow check for the subtract of total RAMBlock size to make sure
it won't underflow. It should not happen in production systems but only if
the migration stream was hijacked, which is not a real concern since
migration channel is trusted. Still protect against it.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4013
Reported-by: Tristan Madani <tristan@talencesecurity.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/ram.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 8918b2f03b..85feff578c 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4268,7 +4268,7 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)
int ret = 0;
/* Synchronize RAM block list */
- while (!ret && total_ram_bytes) {
+ while (total_ram_bytes) {
RAMBlock *block;
char id[256];
ram_addr_t length;
@@ -4285,8 +4285,15 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)
error_report("Unknown ramblock \"%s\", cannot accept "
"migration", id);
ret = -EINVAL;
+ break;
+ }
+
+ if (usub64_overflow(total_ram_bytes, length, &total_ram_bytes)) {
+ error_report("%s: RAMBlock '%s' size underflow total RAM size",
+ __func__, block->idstr);
+ ret = -EFAULT;
+ break;
}
- total_ram_bytes -= length;
}
return ret;
--
2.54.0
next prev parent reply other threads:[~2026-07-28 15:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 15:52 [PATCH 0/5] migration: Hardening fixes for 11.2 Peter Xu
2026-07-28 15:52 ` [PATCH 1/5] migration: Fix possible overflow in vmstate_handle_alloc() Peter Xu
2026-07-28 19:19 ` Fabiano Rosas
2026-07-28 15:52 ` [PATCH 2/5] migration/multifd: Validate next_packet_size in zlib/zstd recv Peter Xu
2026-07-28 19:44 ` Fabiano Rosas
2026-07-28 15:52 ` [PATCH 3/5] migration/multifd: Replace assert() with error_setg() in recv paths Peter Xu
2026-07-28 19:51 ` Fabiano Rosas
2026-07-28 20:28 ` Peter Xu
2026-07-28 20:59 ` Fabiano Rosas
2026-07-28 15:52 ` [PATCH 4/5] migration: Fix rare hang of migration_channel_read_peek() Peter Xu
2026-07-28 16:24 ` Daniel P. Berrangé
2026-07-28 17:09 ` Peter Xu
2026-07-28 17:12 ` Daniel P. Berrangé
2026-07-28 19:59 ` Fabiano Rosas
2026-07-28 20:46 ` Peter Xu
2026-07-28 15:52 ` Peter Xu [this message]
2026-07-28 19:54 ` [PATCH 5/5] migration/ram: Check for RAMBlock size mismatch when parsing 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=20260728155247.1894355-6-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tristan@talencesecurity.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.