libdrgn: detect flattened vmcores and raise error

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 <stephen@brennan.io>
This commit is contained in:
Stephen Brennan 2023-08-15 22:56:06 -07:00 committed by Omar Sandoval
parent 579e68885a
commit 16164dbe6e
2 changed files with 14 additions and 3 deletions

View File

@ -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);

View File

@ -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;
}