Skip to content

Commit

Permalink
migration: Fix use-after-free of migration state object
Browse files Browse the repository at this point in the history
We're currently allowing the process_incoming_migration_bh bottom-half
to run without holding a reference to the 'current_migration' object,
which leads to a segmentation fault if the BH is still live after
migration_shutdown() has dropped the last reference to
current_migration.

In my system the bug manifests as migrate_multifd() returning true
when it shouldn't and multifd_load_shutdown() calling
multifd_recv_terminate_threads() which crashes due to an uninitialized
multifd_recv_state.

Fix the issue by holding a reference to the object when scheduling the
BH and dropping it before returning from the BH. The same is already
done for the cleanup_bh at migrate_fd_cleanup_schedule().

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1969
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20240119233922.32588-2-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
(cherry picked from commit 27eb849)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
Fabiano Rosas authored and Michael Tokarev committed Jan 29, 2024
1 parent e589e5a commit 106aa13
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions migration/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ static void process_incoming_migration_bh(void *opaque)
MIGRATION_STATUS_COMPLETED);
qemu_bh_delete(mis->bh);
migration_incoming_state_destroy();
object_unref(OBJECT(migrate_get_current()));
}

static void coroutine_fn
Expand Down Expand Up @@ -708,6 +709,7 @@ process_incoming_migration_co(void *opaque)
}

mis->bh = qemu_bh_new(process_incoming_migration_bh, mis);
object_ref(OBJECT(migrate_get_current()));
qemu_bh_schedule(mis->bh);
return;
fail:
Expand Down

0 comments on commit 106aa13

Please sign in to comment.