coredump: Snapshot the vmas in do_coredump
commit 95c5436a4883841588dae86fb0b9325f47ba5ad3 upstream. Move the call of dump_vma_snapshot and kvfree(vma_meta) out of the individual coredump routines into do_coredump itself. This makes the code less error prone and easier to maintain. Make the vma snapshot available to the coredump routines in struct coredump_params. This makes it easier to change and update what is captures in the vma snapshot and will be needed for fixing fill_file_notes. Reviewed-by: Jann Horn <jannh@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
5318cdf4fd
commit
936c8be4d1
@@ -2166,8 +2166,7 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
|
||||
static int elf_core_dump(struct coredump_params *cprm)
|
||||
{
|
||||
int has_dumped = 0;
|
||||
int vma_count, segs, i;
|
||||
size_t vma_data_size;
|
||||
int segs, i;
|
||||
struct elfhdr elf;
|
||||
loff_t offset = 0, dataoff;
|
||||
struct elf_note_info info = { };
|
||||
@@ -2175,16 +2174,12 @@ static int elf_core_dump(struct coredump_params *cprm)
|
||||
struct elf_shdr *shdr4extnum = NULL;
|
||||
Elf_Half e_phnum;
|
||||
elf_addr_t e_shoff;
|
||||
struct core_vma_metadata *vma_meta;
|
||||
|
||||
if (dump_vma_snapshot(cprm, &vma_count, &vma_meta, &vma_data_size))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* The number of segs are recored into ELF header as 16bit value.
|
||||
* Please check DEFAULT_MAX_MAP_COUNT definition when you modify here.
|
||||
*/
|
||||
segs = vma_count + elf_core_extra_phdrs();
|
||||
segs = cprm->vma_count + elf_core_extra_phdrs();
|
||||
|
||||
/* for notes section */
|
||||
segs++;
|
||||
@@ -2222,7 +2217,7 @@ static int elf_core_dump(struct coredump_params *cprm)
|
||||
|
||||
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
|
||||
|
||||
offset += vma_data_size;
|
||||
offset += cprm->vma_data_size;
|
||||
offset += elf_core_extra_data_size();
|
||||
e_shoff = offset;
|
||||
|
||||
@@ -2242,8 +2237,8 @@ static int elf_core_dump(struct coredump_params *cprm)
|
||||
goto end_coredump;
|
||||
|
||||
/* Write program headers for segments dump */
|
||||
for (i = 0; i < vma_count; i++) {
|
||||
struct core_vma_metadata *meta = vma_meta + i;
|
||||
for (i = 0; i < cprm->vma_count; i++) {
|
||||
struct core_vma_metadata *meta = cprm->vma_meta + i;
|
||||
struct elf_phdr phdr;
|
||||
|
||||
phdr.p_type = PT_LOAD;
|
||||
@@ -2280,8 +2275,8 @@ static int elf_core_dump(struct coredump_params *cprm)
|
||||
if (!dump_skip(cprm, dataoff - cprm->pos))
|
||||
goto end_coredump;
|
||||
|
||||
for (i = 0; i < vma_count; i++) {
|
||||
struct core_vma_metadata *meta = vma_meta + i;
|
||||
for (i = 0; i < cprm->vma_count; i++) {
|
||||
struct core_vma_metadata *meta = cprm->vma_meta + i;
|
||||
|
||||
if (!dump_user_range(cprm, meta->start, meta->dump_size))
|
||||
goto end_coredump;
|
||||
@@ -2299,7 +2294,6 @@ static int elf_core_dump(struct coredump_params *cprm)
|
||||
end_coredump:
|
||||
free_note_info(&info);
|
||||
kfree(shdr4extnum);
|
||||
kvfree(vma_meta);
|
||||
kfree(phdr4note);
|
||||
return has_dumped;
|
||||
}
|
||||
|
Reference in New Issue
Block a user