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>
(cherry picked from commit db80facefa)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
Peter Lieven 2014-06-10 11:29:16 +02:00 committed by Michael Roth
parent 86cfc10440
commit 6ea6bd5d75
2 changed files with 24 additions and 20 deletions

View File

@ -992,17 +992,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
{ {
ram_addr_t addr; ram_addr_t addr;
int flags, ret = 0; int flags, ret = 0;
int error;
static uint64_t seq_iter; static uint64_t seq_iter;
seq_iter++; seq_iter++;
if (version_id != 4) { if (version_id != 4) {
ret = -EINVAL; ret = -EINVAL;
goto done;
} }
do { while (!ret) {
addr = qemu_get_be64(f); addr = qemu_get_be64(f);
flags = addr & ~TARGET_PAGE_MASK; flags = addr & ~TARGET_PAGE_MASK;
@ -1031,7 +1029,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
" in != " RAM_ADDR_FMT "\n", id, length, " in != " RAM_ADDR_FMT "\n", id, length,
block->length); block->length);
ret = -EINVAL; ret = -EINVAL;
goto done;
} }
break; break;
} }
@ -1041,21 +1038,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
fprintf(stderr, "Unknown ramblock \"%s\", cannot " fprintf(stderr, "Unknown ramblock \"%s\", cannot "
"accept migration\n", id); "accept migration\n", id);
ret = -EINVAL; ret = -EINVAL;
goto done; }
if (ret) {
break;
} }
total_ram_bytes -= length; total_ram_bytes -= length;
} }
} } else if (flags & RAM_SAVE_FLAG_COMPRESS) {
if (flags & RAM_SAVE_FLAG_COMPRESS) {
void *host; void *host;
uint8_t ch; uint8_t ch;
host = host_from_stream_offset(f, addr, flags); host = host_from_stream_offset(f, addr, flags);
if (!host) { if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL; ret = -EINVAL;
goto done; break;
} }
ch = qemu_get_byte(f); ch = qemu_get_byte(f);
@ -1065,33 +1063,39 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
host = host_from_stream_offset(f, addr, flags); host = host_from_stream_offset(f, addr, flags);
if (!host) { if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL; ret = -EINVAL;
goto done; break;
} }
qemu_get_buffer(f, host, TARGET_PAGE_SIZE); qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
} else if (flags & RAM_SAVE_FLAG_XBZRLE) { } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
void *host = host_from_stream_offset(f, addr, flags); void *host = host_from_stream_offset(f, addr, flags);
if (!host) { if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL; ret = -EINVAL;
goto done; break;
} }
if (load_xbzrle(f, addr, host) < 0) { if (load_xbzrle(f, addr, host) < 0) {
error_report("Failed to decompress XBZRLE page at "
RAM_ADDR_FMT, addr);
ret = -EINVAL; ret = -EINVAL;
goto done; break;
} }
} else if (flags & RAM_SAVE_FLAG_HOOK) { } else if (flags & RAM_SAVE_FLAG_HOOK) {
ram_control_load_hook(f, flags); 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); ret = qemu_file_get_error(f);
if (error) { }
ret = error;
goto done;
}
} while (!(flags & RAM_SAVE_FLAG_EOS));
done:
DPRINTF("Completed load of VM with exit code %d seq iteration " DPRINTF("Completed load of VM with exit code %d seq iteration "
"%" PRIu64 "\n", ret, seq_iter); "%" PRIu64 "\n", ret, seq_iter);
return ret; return ret;

View File

@ -98,7 +98,7 @@ static void process_incoming_migration_co(void *opaque)
qemu_fclose(f); qemu_fclose(f);
free_xbzrle_decoded_buf(); free_xbzrle_decoded_buf();
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "load of migration failed\n"); error_report("load of migration failed: %s", strerror(-ret));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
qemu_announce_self(); qemu_announce_self();