summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Lieven <pl@kamp.de>2014-06-10 11:29:16 +0200
committerJuan Quintela <quintela@redhat.com>2014-06-16 04:55:27 +0200
commitdb80facefa62dff42bb50c73b0f03eda5f732b49 (patch)
tree3861bb55883487e6d57385ee750d675c6e37c27e
parent2a9343470432573acf06379bcbf8e5e6568507e4 (diff)
downloadqemu-db80facefa62dff42bb50c73b0f03eda5f732b49.tar.gz
migration: catch unknown flags in ram_load
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>
-rw-r--r--arch_init.c42
-rw-r--r--migration.c2
2 files changed, 24 insertions, 20 deletions
diff --git a/arch_init.c b/arch_init.c
index 23044c1d12..8ddaf35191 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1040,17 +1040,15 @@ 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++;
if (version_id != 4) {
ret = -EINVAL;
- goto done;
}
- do {
+ while (!ret) {
addr = qemu_get_be64(f);
flags = addr & ~TARGET_PAGE_MASK;
@@ -1078,7 +1076,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
" in != " RAM_ADDR_FMT, id, length,
block->length);
ret = -EINVAL;
- goto done;
}
break;
}
@@ -1088,21 +1085,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
error_report("Unknown ramblock \"%s\", cannot "
"accept migration", 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;
host = host_from_stream_offset(f, addr, flags);
if (!host) {
+ error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL;
- goto done;
+ break;
}
ch = qemu_get_byte(f);
@@ -1112,33 +1110,39 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
host = host_from_stream_offset(f, addr, flags);
if (!host) {
+ error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL;
- goto done;
+ break;
}
qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
} else if (flags & RAM_SAVE_FLAG_XBZRLE) {
void *host = host_from_stream_offset(f, addr, flags);
if (!host) {
+ error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL;
- goto done;
+ break;
}
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;
diff --git a/migration.c b/migration.c
index 873fa96e54..8d675b31a1 100644
--- a/migration.c
+++ b/migration.c
@@ -98,7 +98,7 @@ static void process_incoming_migration_co(void *opaque)
qemu_fclose(f);
free_xbzrle_decoded_buf();
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();