Skip to contentSkip to conversation

vl.c/memdev: Error on bad memory backend

PATCH In review Dr. David Alan Gilbert (git) 2 participants 3 messages Mar 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl.c/memdev: Error on bad memory backend

From: "Dr. David Alan Gilbert" <[email protected]>

If memory-backend is a non-existent object, qemu crashes. Check that the backend actually resolves.

e.g. ./qemu-system-x86_64 -machine pc,accel=kvm,memory-backend=foo

---
 softmmu/vl.c | 5 +++++
 1 file changed, 5 insertions(+)
softmmu/vl.c +5 -0
index ff2685dff8..76507e99c4 100644
@@ -4288,6 +4288,11 @@ void qemu_init(int argc, char **argv, char **envp)
 
         backend = object_resolve_path_type(current_machine->ram_memdev_id,
                                            TYPE_MEMORY_BACKEND, NULL);
+        if (!backend) {
+            error_report("Unknown memory backend object id '%s'",
+                         current_machine->ram_memdev_id);
+            exit(EXIT_FAILURE);
+        }
         backend_size = object_property_get_uint(backend, "size",  &error_abort);
         if (have_custom_ram_size && backend_size != ram_size) {
                 error_report("Size specified by -m option must match size of "
Signature · 1 line
2.24.1
#1 lore raw
Quoted 6 lines · On Tue, 17 Mar 2020 12:07:59 +0000 "Dr. David Alan Gilbert (git)"…

From: "Dr. David Alan Gilbert" <[email protected]>

If memory-backend is a non-existent object, qemu crashes. Check that the backend actually resolves.

e.g. ./qemu-system-x86_64 -machine pc,accel=kvm,memory-backend=foo

there is a patch to fix it already
[PATCH] softmmu: fix crash with invalid -M memory-backend=
by Marc-André

but looks like it fell through cracks ...

Quoted 22 lines
---
 softmmu/vl.c | 5 +++++
 1 file changed, 5 insertions(+)
softmmu/vl.c +5 -0
index ff2685dff8..76507e99c4 100644
@@ -4288,6 +4288,11 @@ void qemu_init(int argc, char **argv, char **envp)
 
         backend = object_resolve_path_type(current_machine->ram_memdev_id,
                                            TYPE_MEMORY_BACKEND, NULL);
+        if (!backend) {
+            error_report("Unknown memory backend object id '%s'",
+                         current_machine->ram_memdev_id);
+            exit(EXIT_FAILURE);
+        }
         backend_size = object_property_get_uint(backend, "size",  &error_abort);
         if (have_custom_ram_size && backend_size != ram_size) {
                 error_report("Size specified by -m option must match size of "
#2 lore raw
Quoted 8 lines · * Igor Mammedov ([email protected]) wrote:
Quoted 5 lines · On Tue, 17 Mar 2020 12:07:59 +0000 "Dr. David Alan Gilbert (git)"…

From: "Dr. David Alan Gilbert" <[email protected]>

If memory-backend is a non-existent object, qemu crashes. Check that the backend actually resolves.

Quoted 7 lines
Quoted 1 line

e.g. ./qemu-system-x86_64 -machine pc,accel=kvm,memory-backend=foo

there is a patch to fix it already
[PATCH] softmmu: fix crash with invalid -M memory-backend=
by Marc-André

but looks like it fell through cracks ...

Oops, didn't see that.
(I tripped over this because I hadn't originally realised that it was an object ID rather than object type with options)

Dave

Quoted 12 lines
Quoted 12 lines
---
 softmmu/vl.c | 5 +++++
 1 file changed, 5 insertions(+)
softmmu/vl.c +0 -0
index ff2685dff8..76507e99c4 100644
@@ -4288,6 +4288,11 @@ void qemu_init(int argc, char **argv, char **envp)
 
Quoted 11 lines

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4298

Quoted 10 lines
softmmu/vl.c +5 -0
         backend = object_resolve_path_type(current_machine->ram_memdev_id,
                                            TYPE_MEMORY_BACKEND, NULL);
+        if (!backend) {
+            error_report("Unknown memory backend object id '%s'",
+                         current_machine->ram_memdev_id);
+            exit(EXIT_FAILURE);
+        }
         backend_size = object_property_get_uint(backend, "size",  &error_abort);
         if (have_custom_ram_size && backend_size != ram_size) {
                 error_report("Size specified by -m option must match size of "

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK