Skip to content

Commit 8f5d0a0

Browse files
committed
memory snapshots fix use after free on flatview copy
When restoring a snapshot with memory the flatview must be restored before the memory reagions are filtered. Because the AddressSpaceDispatcher also has pointer to the MemoryRegions and on copy they need to be cleared. The memory_filter_subregions function frees MemoryRegions which are not used at the time of the snapshot.
1 parent 088c066 commit 8f5d0a0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

uc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,10 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
24392439

24402440
if (uc->context_content & UC_CTL_CONTEXT_MEMORY) {
24412441
uc->snapshot_level = context->snapshot_level;
2442+
if (!uc->flatview_copy(uc, uc->address_space_memory.current_map,
2443+
context->fv, true)) {
2444+
return UC_ERR_NOMEM;
2445+
}
24422446
ret = uc_restore_latest_snapshot(uc);
24432447
if (ret != UC_ERR_OK) {
24442448
restore_jit_state(uc);
@@ -2447,10 +2451,6 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
24472451
uc_snapshot(uc);
24482452
uc->ram_list.freed = context->ramblock_freed;
24492453
uc->ram_list.last_block = context->last_block;
2450-
if (!uc->flatview_copy(uc, uc->address_space_memory.current_map,
2451-
context->fv, true)) {
2452-
return UC_ERR_NOMEM;
2453-
}
24542454
uc->tcg_flush_tlb(uc);
24552455
}
24562456

0 commit comments

Comments
 (0)