Skip to contentSkip to conversation

hmp: fix "dump-quest-memory" segfault

PATCH In review Laurent Vivier 5 participants 11 messages Sep 13, 2017 – Sep 14, 2017

lore
Share & tools
lore
#0 lore raw

v4 cover hmp: fix "dump-quest-memory" segfault

Fix aarch64 and ppc when dump-guest-memory is used with none machine type and no CPU.

The other machine types don't have the problem.

Update test-hmp, to test none machine type with (2 MB) and without memory, and add a test to test dump-quest-memory without filter parameters

v4:
- update comment in test-hmp.c
- add cohuck's patch

v3:
- remove blank line after a comment
- forbid memory dump when there is no CPU

v2:
- add arm fix
- update test-hmp

Cornelia Huck (1):
dump: do not dump non-existent guest memory

Laurent Vivier (3):
hmp: fix "dump-quest-memory" segfault (ppc)
hmp: fix "dump-quest-memory" segfault (arm) tests/hmp: test "none" machine with memory

 dump.c                 |  6 ++++++
 target/arm/arch_dump.c | 11 +++++++++--
 target/ppc/arch_dump.c | 11 +++++++++--
 tests/test-hmp.c       |  4 ++++
 4 files changed, 28 insertions(+), 4 deletions(-)
Signature · 1 line
2.13.5
#1 lore raw

PATCH v4 1/4 hmp: fix "dump-quest-memory" segfault (ppc)

Running QEMU with
qemu-system-ppc64 -M none -nographic -m 256
and executing

    dump-guest-memory /dev/null 0 8192

results in segfault

Fix by checking if we have CPU, and exit with
error if there is no CPU:

(qemu) dump-guest-memory /dev/null
this feature or command is not currently supported

---
 target/ppc/arch_dump.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
target/ppc/arch_dump.c +9 -2
index 8e9397aa58..95b9ab6f29 100644
@@ -224,8 +224,15 @@ typedef struct NoteFuncDescStruct NoteFuncDesc;
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const struct GuestPhysBlockList *guest_phys_blocks)
 {
-    PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
-    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
+    PowerPCCPU *cpu;
+    PowerPCCPUClass *pcc;
+
+    if (first_cpu == NULL) {
+        return -1;
+    }
+
+    cpu = POWERPC_CPU(first_cpu);
+    pcc = POWERPC_CPU_GET_CLASS(cpu);
 
     info->d_machine = PPC_ELF_MACHINE;
     info->d_class = ELFCLASS;
Signature · 1 line
2.13.5
Acked-by on v4 1/4
#2 lore raw

Re: [Qemu-arm] [PATCH v4 1/4] hmp: fix "dump-quest-memory" segfault (ppc)

Quoted 9 lines · Laurent Vivier

Running QEMU with
qemu-system-ppc64 -M none -nographic -m 256
and executing

    dump-guest-memory /dev/null 0 8192

results in segfault

Fix by checking if we have CPU, and exit with
error if there is no CPU:

Quoted 6 lines

(qemu) dump-guest-memory /dev/null
this feature or command is not currently supported

Quoted 26 lines
---
 target/ppc/arch_dump.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
target/ppc/arch_dump.c +9 -2
index 8e9397aa58..95b9ab6f29 100644
@@ -224,8 +224,15 @@ typedef struct NoteFuncDescStruct NoteFuncDesc;
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const struct GuestPhysBlockList *guest_phys_blocks)
 {
-    PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
-    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
+    PowerPCCPU *cpu;
+    PowerPCCPUClass *pcc;
+
+    if (first_cpu == NULL) {
+        return -1;
+    }
+
+    cpu = POWERPC_CPU(first_cpu);
+    pcc = POWERPC_CPU_GET_CLASS(cpu);
 
     info->d_machine = PPC_ELF_MACHINE;
     info->d_class = ELFCLASS;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

PATCH v4 2/4 hmp: fix "dump-quest-memory" segfault (arm)

In reply to Laurent Vivier

Running QEMU with
qemu-system-aarch64 -M none -nographic -m 256
and executing

    dump-guest-memory /dev/null 0 8192

results in segfault

Fix by checking if we have CPU, and exit with
error if there is no CPU:

(qemu) dump-guest-memory /dev/null
this feature or command is not currently supported

---
 target/arm/arch_dump.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
target/arm/arch_dump.c +9 -2
index 1a9861f69b..9e5b2fb31c 100644
@@ -273,11 +273,18 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const GuestPhysBlockList *guest_phys_blocks)
 {
-    ARMCPU *cpu = ARM_CPU(first_cpu);
-    CPUARMState *env = &cpu->env;
+    ARMCPU *cpu;
+    CPUARMState *env;
     GuestPhysBlock *block;
     hwaddr lowest_addr = ULLONG_MAX;
 
+    if (first_cpu == NULL) {
+        return -1;
+    }
+
+    cpu = ARM_CPU(first_cpu);
+    env = &cpu->env;
+
     /* Take a best guess at the phys_base. If we get it wrong then crash
      * will need '--machdep phys_offset=<phys-offset>' added to its command
      * line, which isn't any worse than assuming we can use zero, but being
Signature · 1 line
2.13.5
Reviewed-by Tested-by on v4 2/4
#4 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v4 2/4] hmp: fix "dump-quest-memory" segfault (arm)

Hi Laurent,

Quoted 9 lines · Laurent Vivier

Running QEMU with
qemu-system-aarch64 -M none -nographic -m 256
and executing

    dump-guest-memory /dev/null 0 8192

results in segfault

Fix by checking if we have CPU, and exit with
error if there is no CPU:

Quoted 6 lines

(qemu) dump-guest-memory /dev/null
this feature or command is not currently supported

Thanks

Eric

Quoted 30 lines
---
 target/arm/arch_dump.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
target/arm/arch_dump.c +9 -2
index 1a9861f69b..9e5b2fb31c 100644
@@ -273,11 +273,18 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const GuestPhysBlockList *guest_phys_blocks)
 {
-    ARMCPU *cpu = ARM_CPU(first_cpu);
-    CPUARMState *env = &cpu->env;
+    ARMCPU *cpu;
+    CPUARMState *env;
     GuestPhysBlock *block;
     hwaddr lowest_addr = ULLONG_MAX;
 
+    if (first_cpu == NULL) {
+        return -1;
+    }
+
+    cpu = ARM_CPU(first_cpu);
+    env = &cpu->env;
+
     /* Take a best guess at the phys_base. If we get it wrong then crash
      * will need '--machdep phys_offset=<phys-offset>' added to its command
      * line, which isn't any worse than assuming we can use zero, but being
#5 lore raw

PATCH v4 3/4 dump: do not dump non-existent guest memory

In reply to Laurent Vivier

From: Cornelia Huck <[email protected]>

It does not really make sense to dump memory that is not there.

Moreover, that fixes a segmentation fault when calling dump-guest-memory with no filter for a machine with no memory defined.

New behaviour is:

(qemu) dump-guest-memory /dev/null
dump: no guest memory to dump
(qemu) dump-guest-memory /dev/null 0 4096
dump: no guest memory to dump

---
 dump.c | 6 ++++++
 1 file changed, 6 insertions(+)
dump.c +6 -0
index a79773d0f7..d2093e141b 100644
@@ -1536,6 +1536,12 @@ static void dump_init(DumpState *s, int fd, bool has_format,
     fprintf(stderr, "DUMP: total memory to dump: %lu\n", s->total_size);
 #endif
 
+    /* it does not make sense to dump non-existent memory */
+    if (!s->total_size) {
+        error_setg(errp, "dump: no guest memory to dump");
+        goto cleanup;
+    }
+
     s->start = get_start_block(s);
     if (s->start == -1) {
         error_setg(errp, QERR_INVALID_PARAMETER, "begin");
Signature · 1 line
2.13.5
#6 lore raw

Re: [Qemu-arm] [PATCH v4 3/4] dump: do not dump non-existent guest memory

Quoted 14 lines · On Wed, 13 Sep 2017 16:20:35 +0200 Laurent Vivier <[email protected]> wrote:

From: Cornelia Huck <[email protected]>

It does not really make sense to dump memory that is not there.

Moreover, that fixes a segmentation fault when calling dump-guest-memory with no filter for a machine with no memory defined.

New behaviour is:

(qemu) dump-guest-memory /dev/null
dump: no guest memory to dump
(qemu) dump-guest-memory /dev/null 0 4096
dump: no guest memory to dump

Quoted 8 lines
---
 dump.c | 6 ++++++
 1 file changed, 6 insertions(+)

You need to supply your s-o-b as well, no?

#7 lore raw

Re: [Qemu-arm] [PATCH v4 3/4] dump: do not dump non-existent guest memory

Quoted 26 lines · Cornelia Huck
Quoted 14 lines · On Wed, 13 Sep 2017 16:20:35 +0200 Laurent Vivier <[email protected]> wrote:

From: Cornelia Huck <[email protected]>

It does not really make sense to dump memory that is not there.

Moreover, that fixes a segmentation fault when calling dump-guest-memory with no filter for a machine with no memory defined.

New behaviour is:

(qemu) dump-guest-memory /dev/null
dump: no guest memory to dump
(qemu) dump-guest-memory /dev/null 0 4096
dump: no guest memory to dump

Quoted 8 lines
---
 dump.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 2 lines

You need to supply your s-o-b as well, no?

I was wondering... theoretically, yes, so:

Thanks,
Laurent

#8 lore raw

Re: [Qemu-arm] [PATCH v4 3/4] dump: do not dump non-existent guest memory

Quoted 27 lines · * Laurent Vivier ([email protected]) wrote:
Quoted 26 lines · Cornelia Huck
Quoted 22 lines · On Wed, 13 Sep 2017 16:20:35 +0200 Laurent Vivier <[email protected]> wrote:

From: Cornelia Huck <[email protected]>

It does not really make sense to dump memory that is not there.

Moreover, that fixes a segmentation fault when calling dump-guest-memory with no filter for a machine with no memory defined.

New behaviour is:

(qemu) dump-guest-memory /dev/null
dump: no guest memory to dump
(qemu) dump-guest-memory /dev/null 0 4096
dump: no guest memory to dump

---
 dump.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 6 lines
Quoted 2 lines

You need to supply your s-o-b as well, no?

I was wondering... theoretically, yes, so:

Thanks.

Dave

Quoted 2 lines

Thanks,
Laurent

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

#9 lore raw

PATCH v4 4/4 tests/hmp: test "none" machine with memory

In reply to Laurent Vivier

and add a test case of dump-guest-memory without
"[begin length]" parameters.

---
 tests/test-hmp.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/test-hmp.c +4 -0
index 729c0339f7..d124e81850 100644
@@ -35,6 +35,7 @@ static const char *hmp_cmds[] = {
     "mouse_button 0",
     "device_del mouse1",
     "dump-guest-memory /dev/null 0 4096",
+    "dump-guest-memory /dev/null",
     "gdbserver",
     "host_net_add user id=net0",
     "hostfwd_add tcp::43210-:43210",
@@ -159,5 +160,8 @@ int main(int argc, char **argv)
 
     qtest_cb_for_every_machine(add_machine_test_case);
 
+    /* as none machine has no memory by default, add a test case with memory */
+    qtest_add_data_func("hmp/none+2MB", g_strdup("none -m 2"), test_machine);
+
     return g_test_run();
 }
Signature · 1 line
2.13.5
#10 lore raw
In reply to Laurent Vivier
Quoted 8 lines · * Laurent Vivier ([email protected]) wrote:

Fix aarch64 and ppc when dump-guest-memory is used with none machine type and no CPU.

The other machine types don't have the problem.

Update test-hmp, to test none machine type with (2 MB) and without memory, and add a test to test dump-quest-memory without filter parameters

Queued for HMP

Dave

Quoted 21 lines

v4:
- update comment in test-hmp.c
- add cohuck's patch

v3:
- remove blank line after a comment
- forbid memory dump when there is no CPU

v2:
- add arm fix
- update test-hmp

Cornelia Huck (1):
dump: do not dump non-existent guest memory

Laurent Vivier (3):
hmp: fix "dump-quest-memory" segfault (ppc)
hmp: fix "dump-quest-memory" segfault (arm) tests/hmp: test "none" machine with memory

Quoted 9 lines
 dump.c                 |  6 ++++++
 target/arm/arch_dump.c | 11 +++++++++--
 target/ppc/arch_dump.c | 11 +++++++++--
 tests/test-hmp.c       |  4 ++++
 4 files changed, 28 insertions(+), 4 deletions(-)
Signature · 1 line
2.13.5

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