VMBus.rx_queue has HV_MSG_QUEUE_LEN (16) entries, and vmbus_post_load() schedules process_message(), which indexes vmbus->rx_queue[vmbus->rx_queue_head] directly.
vmstate_rx_queue loads rx_queue_head and rx_queue_size as uint8_t values without bounds checking. Add a post_load hook to reject rx_queue_head >= HV_MSG_QUEUE_LEN or rx_queue_size > HV_MSG_QUEUE_LEN. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4776 Signed-off-by: lbyxiaolizi <[email protected]> --- hw/hyperv/vmbus.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c index 3973ca8..a542a3b 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -2607,11 +2607,23 @@ static bool vmbus_rx_queue_needed(void *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),
