Skip to content

Commit

Permalink
libdrgn: detect flattened vmcores and raise error
Browse files Browse the repository at this point in the history
The makedumpfile flattened format is occasionally seen by users, but is
not read by libkdumpfile and thus unsupported by Drgn. A simple
'reassembly' process is all that is necessary to allow Drgn to open the
vmcore, but this fact isn't easily discoverable, resulting in issues
like #344. To help users, detect this when we're testing for kdump
signatures, and raise an error with reassembly instructions.

For further details on the flattened format, consult makedumpfile(8),
particularly the sections documenting options -F and -R.

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 authored and osandov committed Aug 16, 2023
1 parent 579e688 commit 16164db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libdrgn/linux_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ linux_kernel_report_debug_info(struct drgn_debug_info_load_state *load);
#define KDUMP_SIGNATURE "KDUMP "
#define KDUMP_SIG_LEN (sizeof(KDUMP_SIGNATURE) - 1)

#define FLATTENED_SIGNATURE "makedumpfile"
#define FLATTENED_SIG_LEN (sizeof(FLATTENED_SIGNATURE) - 1)

#ifdef WITH_LIBKDUMPFILE
struct drgn_error *drgn_program_cache_kdump_notes(struct drgn_program *prog);
struct drgn_error *drgn_program_set_kdump(struct drgn_program *prog);
Expand Down
14 changes: 11 additions & 3 deletions libdrgn/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,20 @@ drgn_program_check_initialized(struct drgn_program *prog)
static struct drgn_error *has_kdump_signature(const char *path, int fd,
bool *ret)
{
char signature[KDUMP_SIG_LEN];
char signature[max_iconst(KDUMP_SIG_LEN, FLATTENED_SIG_LEN)];
ssize_t r = pread_all(fd, signature, sizeof(signature), 0);
if (r < 0)
return drgn_error_create_os("pread", errno, path);
*ret = (r == sizeof(signature)
&& memcmp(signature, KDUMP_SIGNATURE, sizeof(signature)) == 0);
if (r >= FLATTENED_SIG_LEN
&& memcmp(signature, FLATTENED_SIGNATURE, FLATTENED_SIG_LEN) == 0) {
return drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT,
"the given file is in the makedumpfile flattened "
"format, which drgn does not support; use "
"'makedumpfile -R newfile <oldfile' to reassemble "
"the file into a format drgn can read");
}
*ret = (r >= KDUMP_SIG_LEN
&& memcmp(signature, KDUMP_SIGNATURE, KDUMP_SIG_LEN) == 0);
return NULL;
}

Expand Down

0 comments on commit 16164db

Please sign in to comment.