Skip to content

Commit

Permalink
migration: catch unknown flags in ram_load
Browse files Browse the repository at this point in the history
if a saved vm has unknown flags in the memory data qemu
currently simply ignores this flag and continues which
yields in an unpredictable result.

This patch catches all unknown flags and aborts the
loading of the vm. Additionally error reports are thrown
if the migration aborts abnormally.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Juan Quintela <quintela@redhat.com>
(cherry picked from commit db80fac)

Conflicts:
	arch_init.c

*removed unecessary context from 4798fe5

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
plieven authored and mdroth committed Jul 1, 2014
1 parent 3102b1a commit 69b7aac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions arch_init.c
Expand Up @@ -857,7 +857,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
{
ram_addr_t addr;
int flags, ret = 0;
int error;
static uint64_t seq_iter;

seq_iter++;
Expand All @@ -866,7 +865,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
return -EINVAL;
}

do {
while (!ret) {
addr = qemu_get_be64(f);

flags = addr & ~TARGET_PAGE_MASK;
Expand Down Expand Up @@ -895,7 +894,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
" in != " RAM_ADDR_FMT "\n", id, length,
block->length);
ret = -EINVAL;
goto done;
}
break;
}
Expand All @@ -905,14 +903,14 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
fprintf(stderr, "Unknown ramblock \"%s\", cannot "
"accept migration\n", id);
ret = -EINVAL;
goto done;
}
if (ret) {
break;
}

total_ram_bytes -= length;
}
}

if (flags & RAM_SAVE_FLAG_COMPRESS) {
} else if (flags & RAM_SAVE_FLAG_COMPRESS) {
void *host;
uint8_t ch;

Expand All @@ -939,20 +937,24 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
}

if (load_xbzrle(f, addr, host) < 0) {
error_report("Failed to decompress XBZRLE page at "
RAM_ADDR_FMT, addr);
ret = -EINVAL;
goto done;
break;
}
} else if (flags & RAM_SAVE_FLAG_HOOK) {
ram_control_load_hook(f, flags);
} else if (flags & RAM_SAVE_FLAG_EOS) {
/* normal exit */
break;
} else {
error_report("Unknown migration flags: %#x", flags);
ret = -EINVAL;
break;
}
error = qemu_file_get_error(f);
if (error) {
ret = error;
goto done;
}
} while (!(flags & RAM_SAVE_FLAG_EOS));
ret = qemu_file_get_error(f);
}

done:
DPRINTF("Completed load of VM with exit code %d seq iteration "
"%" PRIu64 "\n", ret, seq_iter);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion migration.c
Expand Up @@ -105,7 +105,7 @@ static void process_incoming_migration_co(void *opaque)
ret = qemu_loadvm_state(f);
qemu_fclose(f);
if (ret < 0) {
fprintf(stderr, "load of migration failed\n");
error_report("load of migration failed: %s", strerror(-ret));
exit(EXIT_FAILURE);
}
qemu_announce_self();
Expand Down

0 comments on commit 69b7aac

Please sign in to comment.