Skip to content

Commit 7d442a3

Browse files
makb-juniperkees
authored andcommitted
binfmt_elf: Dump smaller VMAs first in ELF cores
Large cores may be truncated in some scenarios, such as with daemons with stop timeouts that are not large enough or lack of disk space. This impacts debuggability with large core dumps since critical information necessary to form a usable backtrace, such as stacks and shared library information, are omitted. We attempted to figure out which VMAs are needed to create a useful backtrace, and it turned out to be a non-trivial problem. Instead, we try simply sorting the VMAs by size, which has the intended effect. By sorting VMAs by dump size and dumping in that order, we have a simple, yet effective heuristic. Signed-off-by: Brian Mak <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent fb97d2e commit 7d442a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/coredump.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/personality.h>
1919
#include <linux/binfmts.h>
2020
#include <linux/coredump.h>
21+
#include <linux/sort.h>
2122
#include <linux/sched/coredump.h>
2223
#include <linux/sched/signal.h>
2324
#include <linux/sched/task_stack.h>
@@ -1249,6 +1250,18 @@ static void free_vma_snapshot(struct coredump_params *cprm)
12491250
}
12501251
}
12511252

1253+
static int cmp_vma_size(const void *vma_meta_lhs_ptr, const void *vma_meta_rhs_ptr)
1254+
{
1255+
const struct core_vma_metadata *vma_meta_lhs = vma_meta_lhs_ptr;
1256+
const struct core_vma_metadata *vma_meta_rhs = vma_meta_rhs_ptr;
1257+
1258+
if (vma_meta_lhs->dump_size < vma_meta_rhs->dump_size)
1259+
return -1;
1260+
if (vma_meta_lhs->dump_size > vma_meta_rhs->dump_size)
1261+
return 1;
1262+
return 0;
1263+
}
1264+
12521265
/*
12531266
* Under the mmap_lock, take a snapshot of relevant information about the task's
12541267
* VMAs.
@@ -1311,5 +1324,8 @@ static bool dump_vma_snapshot(struct coredump_params *cprm)
13111324
cprm->vma_data_size += m->dump_size;
13121325
}
13131326

1327+
sort(cprm->vma_meta, cprm->vma_count, sizeof(*cprm->vma_meta),
1328+
cmp_vma_size, NULL);
1329+
13141330
return true;
13151331
}

0 commit comments

Comments
 (0)