Commit 0522a9457b for qemu.org
commit 0522a9457b071fcdb3470278e3df78c1e773d432
Author: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Date: Tue Nov 24 19:32:52 2026 +0100
hw/block/pflash_cfi01: Register VM change handler once
Each pflash_post_load() added a VM change-state handler and
overwrote pfl->vmstate. Loading twice before the VM resumes
left the first entry on the list, and resuming then ran a
freed entry. Register the handler only when none is held.
Cc: qemu-stable@nongnu.org
Fixes: 90c647db8d59 ("Fix pflash migration")
Reported-by: Wang Jianqiang <wjq.sec@gmail.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2635
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20261124185556.81132-2-philmd@oss.qualcomm.com>
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 486fc6350d..78cb221dda 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -1039,7 +1039,8 @@ static int pflash_post_load(void *opaque, int version_id)
memory_region_rom_device_set_romd(&pfl->mem, false);
}
- if (!pfl->ro) {
+ /* A second load before the VM resumes must not add a duplicate entry */
+ if (!pfl->ro && !pfl->vmstate) {
pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb,
pfl);
}