]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
migration/multifd: fix off-by-one in recv channel ID validation
authorBin Guo <guobin@linux.alibaba.com>
Mon, 18 May 2026 11:01:09 +0000 (19:01 +0800)
committerPeter Xu <peterx@redhat.com>
Wed, 20 May 2026 19:41:33 +0000 (15:41 -0400)
multifd_recv_initial_packet() validates the channel ID received from
the source against the configured number of channels. The current
check uses '>' which allows msg.id == N to pass through. This ID is
then used to index multifd_recv_state->params[msg.id], which was
allocated with g_new0(MultiFDRecvParams, N) -- an out-of-bounds
access.

A malicious or buggy source could send id == N and cause heap
corruption on the destination.

Fix by changing '>' to '>='. Also fix the error message to say
"exceeds channel count" for accuracy.

Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20260518110112.21395-6-guobin@linux.alibaba.com
Signed-off-by: Peter Xu <peterx@redhat.com>
migration/multifd.c

index 035cb70f7b1cb93579094afeb6b76726733cf170..b3eef875cc5610e5ade652f2ef42eb32482699e9 100644 (file)
@@ -210,9 +210,9 @@ static int multifd_recv_initial_packet(QIOChannel *c, Error **errp)
         return -1;
     }
 
-    if (msg.id > migrate_multifd_channels()) {
-        error_setg(errp, "multifd: received channel id %u is greater than "
-                   "number of channels %u", msg.id, migrate_multifd_channels());
+    if (msg.id >= migrate_multifd_channels()) {
+        error_setg(errp, "multifd: received channel id %u exceeds "
+                   "channel count %u", msg.id, migrate_multifd_channels());
         return -1;
     }