hw/hyperv/vmbus: missing .post_load bounds checks in vmstate_rx_queue and vmstate_gpadl allow out-of-bounds read/write
Host environment
-
Operating system: Debian GNU/Linux 12 (bookworm)
-
OS/kernel version:
Linux 6.1.0-51-cloud-amd64 x86_64 -
Architecture:
x86_64 -
QEMU flavor:
qemu-system-x86_64 -
QEMU version: Verified on QEMU
9.0.2,11.1.1, and current upstreammaster(73294d096cc591e122fde9e63db4739de6d84f2b, 2026-10-28) -
QEMU command line:
./qemu-system-x86_64 -machine q35,accel=kvm -cpu host,hv-synic,hv-vpindex -device vmbus-bridge -incoming tcp:127.0.0.1:4444
Emulated/Virtualized environment
- Operating system: Guest-agnostic (device state deserialization / post-migration access)
- OS/kernel version: N/A
- Architecture: x86_64 (
pc/q35with Hyper-Vvmbus-bridge)
Description of problem
Tooling Disclosure (per QEMU bug reporting policy): This issue was identified with the assistance of a static analysis screener checking VMStateDescription deserialization invariants across QEMU device models, and was manually triaged, audited against upstream master (73294d096cc591e122fde9e63db4739de6d84f2b), and paired with a compiler-verified .post_load patch by the reporter prior to submission.
hw/hyperv/vmbus.c contains two VMStateDescription subsections that deserialize array indices and counts without .post_load validation:
-
vmstate_rx_queue(hw/hyperv/vmbus.c:2571-2585):VMBus.rx_queueis a fixed-size 16-entry ring buffer (struct hyperv_post_message_input rx_queue[HV_MSG_QUEUE_LEN], whereHV_MSG_QUEUE_LEN = 16). Runtime enqueue (enqueue_incoming_message) and dequeue (process_message) maintainrx_queue_head < HV_MSG_QUEUE_LENandrx_queue_size <= HV_MSG_QUEUE_LEN. However,vmstate_rx_queuedeserializesVMSTATE_UINT8(rx_queue_head, VMBus)andVMSTATE_UINT8(rx_queue_size, VMBus)(0..255) with no.post_loadcheck. At the end ofvmbus_post_load(),vmbus_resched(vmbus)schedulesprocess_message(vmbus), which immediately accesses:hv_msg = &vmbus->rx_queue[vmbus->rx_queue_head]; /* hw/hyperv/vmbus.c:2101 */When
rx_queue_head >= 16, this reads pastvmbus->rx_queue[16]. -
vmstate_gpadl(hw/hyperv/vmbus.c:525-539):vmstate_gpadldeserializesuint32_t num_gfns,uint32_t seen_gfns, and allocatesgpadl->gfnsof lengthnum_gfnsviaVMSTATE_VARRAY_UINT32_ALLOC(gfns, VMBusGpadl, num_gfns, ...). It does not validateseen_gfns <= num_gfns. If a migrated GPADL hasseen_gfns > num_gfnsand subsequently receives aVMBUS_MSG_GPADL_BODYmessage inhandle_gpadl_body()(hw/hyperv/vmbus.c:1846-1852):num_gfns_left = gpadl->num_gfns - gpadl->seen_gfns; /* 32-bit unsigned underflow */ assert(num_gfns_left); for (i = 0; i < num_gfns_left && (void *)&msg->pfn_array[i + 1] <= (void *)msg + msglen; i++) { gpadl->gfns[gpadl->seen_gfns++] = msg->pfn_array[i]; /* heap OOB write */ }num_gfns_leftwraps around as an unsigned 32-bit integer andgpadl->gfns[gpadl->seen_gfns++]writes past the end of thenum_gfns-element heap allocation.
Steps to reproduce
- Start QEMU with
-device vmbus-bridge. - Restore a migration state where either
VMBus.rx_queue_head >= 16(withrx_queue_size > 0) orVMBusGpadl.seen_gfns > VMBusGpadl.num_gfns. - Upon resume,
vmbus_resched() -> process_message()readsvmbus->rx_queue[rx_queue_head]out of bounds, or sendingVMBUS_MSG_GPADL_BODYtriggers an out-of-bounds heap write ongpadl->gfns[].
Additional information
Proposed Fix Patch (04-hw-hyperv-vmbus-vmstate-postload.patch, verified against master 73294d096cc591e122fde9e63db4739de6d84f2b)
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index f33afeee..b88447e1 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -513,28 +513,39 @@ void vmbus_unmap_sgl(VMBusChanReq *req, DMADirection dir, struct iovec *iov,
unsigned iov_cnt, size_t accessed)
{
QEMUSGList *sgl = &req->sgl;
unsigned i;
for (i = 0; i < iov_cnt; i++) {
size_t acsd = MIN(accessed, iov[i].iov_len);
dma_memory_unmap(sgl->as, iov[i].iov_base, iov[i].iov_len, dir, acsd);
accessed -= acsd;
}
}
+static int vmbus_gpadl_post_load(void *opaque, int version_id)
+{
+ VMBusGpadl *gpadl = opaque;
+
+ if (gpadl->seen_gfns > gpadl->num_gfns) {
+ return -EINVAL;
+ }
+ return 0;
+}
+
static const VMStateDescription vmstate_gpadl = {
.name = "vmbus/gpadl",
.version_id = 0,
.minimum_version_id = 0,
+ .post_load = vmbus_gpadl_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT32(id, VMBusGpadl),
VMSTATE_UINT32(child_relid, VMBusGpadl),
VMSTATE_UINT32(num_gfns, VMBusGpadl),
VMSTATE_UINT32(seen_gfns, VMBusGpadl),
VMSTATE_VARRAY_UINT32_ALLOC(gfns, VMBusGpadl, num_gfns, 0,
vmstate_info_uint64, uint64_t),
VMSTATE_UINT8(state, VMBusGpadl),
VMSTATE_END_OF_LIST()
}
};
@@ -2559,29 +2570,41 @@ static const VMStateDescription vmstate_post_message_input = {
VMSTATE_UINT8_ARRAY(payload, struct hyperv_post_message_input,
HV_MESSAGE_PAYLOAD_SIZE),
VMSTATE_END_OF_LIST()
}
};
static bool vmbus_rx_queue_needed(void *opaque)
{
VMBus *vmbus = VMBUS(opaque);
return vmbus->rx_queue_size;
}
+static int vmbus_rx_queue_post_load(void *opaque, int version_id)
+{
+ VMBus *vmbus = VMBUS(opaque);
+
+ if (vmbus->rx_queue_head >= HV_MSG_QUEUE_LEN ||
+ vmbus->rx_queue_size > HV_MSG_QUEUE_LEN) {
+ return -EINVAL;
+ }
+ return 0;
+}
+
static const VMStateDescription vmstate_rx_queue = {
.name = "vmbus/rx_queue",
.version_id = 0,
.minimum_version_id = 0,
.needed = vmbus_rx_queue_needed,
+ .post_load = vmbus_rx_queue_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT8(rx_queue_head, VMBus),
VMSTATE_UINT8(rx_queue_size, VMBus),
VMSTATE_STRUCT_ARRAY(rx_queue, VMBus,
HV_MSG_QUEUE_LEN, 0,
vmstate_post_message_input,
struct hyperv_post_message_input),
VMSTATE_END_OF_LIST()
}
};
static const VMStateDescription vmstate_vmbus = {