[PATCH for-11.2 0/3] Fix registering of VM change state handlers in post-load

Peter Maydell posted 3 patches 10 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261127144439.627586-1-peter.maydell@linaro.org
Maintainers: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Amit Machhiwal <amachhiw@linux.ibm.com>
hw/block/pflash_cfi02.c | 2 +-
hw/misc/mac_via.c       | 2 +-
hw/nvram/spapr_nvram.c  | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
[PATCH for-11.2 0/3] Fix registering of VM change state handlers in post-load
Posted by Peter Maydell 10 hours ago
We have a handful of devices which register a VM change state handler
callback in their migration post-load function: vapic, mac_via,
spapr_nvram, pflash_cfi01 and pflash_cfi02. All of these except vapic
have the same bug. The intention is to perform a one-shot operation on
first resume of the VM, so they register a handler in the post-load
hook which then deletes itself when run.

The bug happens if the user performs more than one "migration load"
operation before doing the VM resume. In this case the post_load
hook will run a second time, and the hook gets registered again,
overwriting the state field holding the pointer to the VMChangeStateEntry
struct. Then on resume the core code will call the hook twice; the
first hook called deletes not itself, but the hook registered second.
These callbacks are allowed to delete themselves from the list,
but not other callbacks, and doing so can result in a use-after-free
(because the QTAILQ_FOREACH_SAFE() loop in vm_state_notify() keeps
a pointer to the list entry for the next iteration).

Fix mac_via, spapr_nvram and pflash_cfi02 using the same pattern
vapic already does: only register the callback if it isn't already
registered.

pflash_cfi01 is fixed in a patch from Philippe already on-list:
https://patchew.org/QEMU/20261124185556.81132-1-philmd@oss.qualcomm.com/20261124185556.81132-2-philmd@oss.qualcomm.com/

thanks
-- PMM

Peter Maydell (3):
  hw/misc/mac_via: register VM change state handler once
  hw/nvram/spapr_nvram: register VM change state handler once
  hw/block/pflash_cfi02: register VM change state handler once

 hw/block/pflash_cfi02.c | 2 +-
 hw/misc/mac_via.c       | 2 +-
 hw/nvram/spapr_nvram.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

-- 
2.43.0