Commit 93e8960718 for qemu.org
commit 93e8960718e5aef36a1146831c673d428fa87367
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Fri Nov 27 14:44:37 2026 +0000
hw/misc/mac_via: register VM change state handler once
In the mac_via post-load function we register a VM change state
handler callback, which is a one-shot (it deletes itself when run).
However, loading twice before the VM resumes means the post_load hook
adds the handler again, overwriting the old v1s->vmstate. This can
result in a use-after-free on resume because the first-registered
callback does not delete itself (which is permitted) but the
second-registered callback (which is not).
Follow the pattern used by vapic.c and only register the callback
if it has not already been registered.
Cc: qemu-stable@nongnu.org
Fixes: eb064db94ccd62f054 ("q800: add a block backend to the PRAM")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20261127144439.627586-2-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index 26ee230dcc..dfc7d304ff 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -1192,7 +1192,7 @@ static int via1_post_load(void *opaque, int version_id)
{
MOS6522Q800VIA1State *v1s = MOS6522_Q800_VIA1(opaque);
- if (v1s->blk) {
+ if (v1s->blk && !v1s->vmstate) {
v1s->vmstate = qemu_add_vm_change_state_handler(
via1_postload_update_cb, v1s);
}