migration: don't segfault on invalid input
PATCH 1/1 migration: don't segfault on invalid input
host_from_stream_offset returns NULL on error, return error instead of trying to use that address, to avoid segfault on invalid stream.
--- arch_init.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch_init.c +5 -0
@@ -116,6 +116,8 @@ static int ram_save_block(QEMUFile *f)if (!block) block =QLIST_FIRST (&ram_list.blocks); +if (!last_block) + last_block = block; current_addr = block->offset + offset;
@@ -390,6 +392,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) host =qemu_get_ram_ptr (addr); else host =host_from_stream_offset (f, addr, flags); +if (!host) { +return -EINVAL ; + } ch =qemu_get_byte (f);memset (host, ch,TARGET_PAGE_SIZE );
Signature · 1 line
1.7.3-rc1
Alex Williamson
NAKQuoted 14 lines · Michael S. Tsirkin
host_from_stream_offsetreturns NULL on error, return error instead of trying to use that address, to avoid segfault on invalid stream.Signed-off-by Michael S. Tsirkin <[email protected]>--- arch_init.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)arch_init.c +0
-0
arch_init.c static int ram_save_block(QEMUFile *f) · line 122
Quoted 7 lines
arch_init.c +2
-0@@ -116,6 +116,8 @@ static int ram_save_block(QEMUFile *f)if (!block) block =QLIST_FIRST (&ram_list.blocks); +if (!last_block) + last_block = block; current_addr = block->offset + offset;
NAK, last_block == block will cause us to set the continue flag on the first block. I assume you're trying to prevent the last_block->offset segv in the while test, but that should never happen. The only time last_block is NULL is at the beginning of stage 1, where all pages are dirty. At that point we should always enter the if {} block at the beginning of the do {} while, which breaks out rather than hitting the segv. We'll then set last_block for the next pass.
arch_init.c int ram_load(QEMUFile *f, void *opaque, int version_id) · line 398
Quoted 8 lines
arch_init.c +3
-0@@ -390,6 +392,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) host =qemu_get_ram_ptr (addr); else host =host_from_stream_offset (f, addr, flags); +if (!host) { +return -EINVAL ; + }
This should also never happen since we've synchronized ramblocks at the beginning of migration, but probably a good idea to return an error. Thanks,
Alex
Quoted 21 lines · Alex Williamson
Quoted 20 lines · Michael S. Tsirkin
host_from_stream_offsetreturns NULL on error, return error instead of trying to use that address, to avoid segfault on invalid stream.Signed-off-by Michael S. Tsirkin <[email protected]>--- arch_init.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)arch_init.c +2
-0@@ -116,6 +116,8 @@ static int ram_save_block(QEMUFile *f)if (!block) block =QLIST_FIRST (&ram_list.blocks); +if (!last_block) + last_block = block;
Quoted 9 lines
arch_init.c static int ram_save_block(QEMUFile *f) · line 122
Quoted 1 line
arch_init.c +0
-0current_addr = block->offset + offset;NAK,
last_block== block will cause us to set the continue flag on the first block. I assume you're trying to prevent thelast_block->offsetsegv in the while test, but that should never happen. The only timelast_blockis NULL is at the beginning of stage 1, where all pages are dirty. At that point we should always enter the if {} block at the beginning of the do {} while, which breaks out rather than hitting the segv. We'll then setlast_blockfor the next pass.
Sorry, sent this chunk in error.
Quoted 14 lines
arch_init.c int ram_load(QEMUFile *f, void *opaque, int version_id) · line 398
Quoted 8 lines
arch_init.c +3
-0@@ -390,6 +392,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) host =qemu_get_ram_ptr (addr); else host =host_from_stream_offset (f, addr, flags); +if (!host) { +return -EINVAL ; + }This should also never happen since we've synchronized ramblocks at the beginning of migration, but probably a good idea to return an error. Thanks,
Alex