Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdrgn: accept flattened KDUMP format #366

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions libdrgn/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "helpers.h"
#include "io.h"
#include "language.h"
#include "log.h"
#include "linux_kernel.h"
#include "memory_reader.h"
#include "minmax.h"
Expand Down Expand Up @@ -215,23 +216,24 @@ drgn_program_check_initialized(struct drgn_program *prog)
return NULL;
}

static struct drgn_error *has_kdump_signature(const char *path, int fd,
bool *ret)
static struct drgn_error *
has_kdump_signature(struct drgn_program *prog, const char *path, bool *ret)
{
char signature[max_iconst(KDUMP_SIG_LEN, FLATTENED_SIG_LEN)];
ssize_t r = pread_all(fd, signature, sizeof(signature), 0);
ssize_t r = pread_all(prog->core_fd, signature, sizeof(signature), 0);
if (r < 0)
return drgn_error_create_os("pread", errno, path);
*ret = false;
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);
drgn_log_warning(prog,
"the given file is in the makedumpfile flattened "
"format; if open fails or is too slow, reassemble "
"it with 'makedumpfile -R newfile <oldfile'");
*ret = true;
} else if (r >= KDUMP_SIG_LEN
&& memcmp(signature, KDUMP_SIGNATURE, KDUMP_SIG_LEN) == 0)
*ret = true;
return NULL;
}

Expand All @@ -252,7 +254,7 @@ drgn_program_set_core_dump_fd_internal(struct drgn_program *prog, int fd,
bool have_nt_taskstruct = false, is_proc_kcore;

prog->core_fd = fd;
err = has_kdump_signature(path, prog->core_fd, &is_kdump);
err = has_kdump_signature(prog, path, &is_kdump);
if (err)
goto out_fd;
if (is_kdump) {
Expand Down