Skip to content

Commit 2bd861f

Browse files
committed
libdrgn: program: detect QEMU guest memory dumps without VMCOREINFO
Issue osandov#182 reported that a core dump created by QEMU's dump-guest-memory command confuses drgn: by default, it only has NT_PRSTATUS notes and QEMU state notes for each CPU, so drgn thinks it's a userspace core dump, and it doesn't have the necessary VMCOREINFO to use it as a Linux kernel core dump. It turns out that QEMU and Linux can cooperate to add a VMCOREINFO note to the guest memory dump, which suffices for drgn. Let's detect a QEMU guest memory dump without a VMCOREINFO note and include instructions on how to capture a QEMU dump that makes drgn happy. Signed-off-by: Omar Sandoval <[email protected]>
1 parent e0b2490 commit 2bd861f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libdrgn/program.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ drgn_program_set_core_dump(struct drgn_program *prog, const char *path)
236236
size_t phnum, i;
237237
size_t num_file_segments, j;
238238
bool have_phys_addrs = false;
239+
bool have_qemu_note = false;
239240
const char *vmcoreinfo_note = NULL;
240241
size_t vmcoreinfo_size = 0;
241242
bool have_nt_taskstruct = false, is_proc_kcore;
@@ -355,6 +356,10 @@ drgn_program_set_core_dump(struct drgn_program *prog, const char *path)
355356
* may be valid.
356357
*/
357358
have_phys_addrs = true;
359+
} else if (nhdr.n_namesz == sizeof("QEMU") &&
360+
memcmp(name, "QEMU",
361+
sizeof("QEMU")) == 0) {
362+
have_qemu_note = true;
358363
}
359364
}
360365
}
@@ -525,6 +530,15 @@ drgn_program_set_core_dump(struct drgn_program *prog, const char *path)
525530
prog->core = NULL;
526531
} else if (vmcoreinfo_note) {
527532
prog->flags |= DRGN_PROGRAM_IS_LINUX_KERNEL;
533+
} else if (have_qemu_note) {
534+
err = drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT,
535+
"unrecognized QEMU memory dump; "
536+
"for Linux guests, run QEMU with '-device vmcoreinfo', "
537+
"compile the kernel with CONFIG_CRASH_CORE and CONFIG_FW_CFG, "
538+
"and load the qemu_fw_cfg kernel module "
539+
"before dumping the guest memory "
540+
"(requires Linux >= 4.17 and QEMU >= 2.11)");
541+
goto out_segments;
528542
}
529543
if (prog->flags & DRGN_PROGRAM_IS_LINUX_KERNEL) {
530544
err = drgn_program_add_object_finder(prog,

0 commit comments

Comments
 (0)