forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coredump: rework elf/elf_fdpic vma_dump_size() into common helper
At the moment, the binfmt_elf and binfmt_elf_fdpic code have slightly different code to figure out which VMAs should be dumped, and if so, whether the dump should contain the entire VMA or just its first page. Eliminate duplicate code by reworking the binfmt_elf version into a generic core dumping helper in coredump.c. As part of that, change the heuristic for detecting executable/library header pages to check whether the inode is executable instead of looking at the file mode. This is less problematic in terms of locking because it lets us avoid get_user() under the mmap_sem. (And arguably it looks nicer and makes more sense in generic code.) Adjust a little bit based on the binfmt_elf_fdpic version: ->anon_vma is only meaningful under CONFIG_MMU, otherwise we have to assume that the VMA has been written to. Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Linus Torvalds <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Alexander Viro <[email protected]> Cc: "Eric W . Biederman" <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Hugh Dickins <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
4 changed files
with
106 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1414,126 +1414,6 @@ static int load_elf_library(struct file *file) | |
* Jeremy Fitzhardinge <[email protected]> | ||
*/ | ||
|
||
/* | ||
* The purpose of always_dump_vma() is to make sure that special kernel mappings | ||
* that are useful for post-mortem analysis are included in every core dump. | ||
* In that way we ensure that the core dump is fully interpretable later | ||
* without matching up the same kernel and hardware config to see what PC values | ||
* meant. These special mappings include - vDSO, vsyscall, and other | ||
* architecture specific mappings | ||
*/ | ||
static bool always_dump_vma(struct vm_area_struct *vma) | ||
{ | ||
/* Any vsyscall mappings? */ | ||
if (vma == get_gate_vma(vma->vm_mm)) | ||
return true; | ||
|
||
/* | ||
* Assume that all vmas with a .name op should always be dumped. | ||
* If this changes, a new vm_ops field can easily be added. | ||
*/ | ||
if (vma->vm_ops && vma->vm_ops->name && vma->vm_ops->name(vma)) | ||
return true; | ||
|
||
/* | ||
* arch_vma_name() returns non-NULL for special architecture mappings, | ||
* such as vDSO sections. | ||
*/ | ||
if (arch_vma_name(vma)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
/* | ||
* Decide what to dump of a segment, part, all or none. | ||
*/ | ||
static unsigned long vma_dump_size(struct vm_area_struct *vma, | ||
unsigned long mm_flags) | ||
{ | ||
#define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type)) | ||
|
||
/* always dump the vdso and vsyscall sections */ | ||
if (always_dump_vma(vma)) | ||
goto whole; | ||
|
||
if (vma->vm_flags & VM_DONTDUMP) | ||
return 0; | ||
|
||
/* support for DAX */ | ||
if (vma_is_dax(vma)) { | ||
if ((vma->vm_flags & VM_SHARED) && FILTER(DAX_SHARED)) | ||
goto whole; | ||
if (!(vma->vm_flags & VM_SHARED) && FILTER(DAX_PRIVATE)) | ||
goto whole; | ||
return 0; | ||
} | ||
|
||
/* Hugetlb memory check */ | ||
if (is_vm_hugetlb_page(vma)) { | ||
if ((vma->vm_flags & VM_SHARED) && FILTER(HUGETLB_SHARED)) | ||
goto whole; | ||
if (!(vma->vm_flags & VM_SHARED) && FILTER(HUGETLB_PRIVATE)) | ||
goto whole; | ||
return 0; | ||
} | ||
|
||
/* Do not dump I/O mapped devices or special mappings */ | ||
if (vma->vm_flags & VM_IO) | ||
return 0; | ||
|
||
/* By default, dump shared memory if mapped from an anonymous file. */ | ||
if (vma->vm_flags & VM_SHARED) { | ||
if (file_inode(vma->vm_file)->i_nlink == 0 ? | ||
FILTER(ANON_SHARED) : FILTER(MAPPED_SHARED)) | ||
goto whole; | ||
return 0; | ||
} | ||
|
||
/* Dump segments that have been written to. */ | ||
if (vma->anon_vma && FILTER(ANON_PRIVATE)) | ||
goto whole; | ||
if (vma->vm_file == NULL) | ||
return 0; | ||
|
||
if (FILTER(MAPPED_PRIVATE)) | ||
goto whole; | ||
|
||
/* | ||
* If this looks like the beginning of a DSO or executable mapping, | ||
* check for an ELF header. If we find one, dump the first page to | ||
* aid in determining what was mapped here. | ||
*/ | ||
if (FILTER(ELF_HEADERS) && | ||
vma->vm_pgoff == 0 && (vma->vm_flags & VM_READ)) { | ||
u32 __user *header = (u32 __user *) vma->vm_start; | ||
u32 word; | ||
/* | ||
* Doing it this way gets the constant folded by GCC. | ||
*/ | ||
union { | ||
u32 cmp; | ||
char elfmag[SELFMAG]; | ||
} magic; | ||
BUILD_BUG_ON(SELFMAG != sizeof word); | ||
magic.elfmag[EI_MAG0] = ELFMAG0; | ||
magic.elfmag[EI_MAG1] = ELFMAG1; | ||
magic.elfmag[EI_MAG2] = ELFMAG2; | ||
magic.elfmag[EI_MAG3] = ELFMAG3; | ||
if (unlikely(get_user(word, header))) | ||
word = 0; | ||
if (word == magic.cmp) | ||
return PAGE_SIZE; | ||
} | ||
|
||
#undef FILTER | ||
|
||
return 0; | ||
|
||
whole: | ||
return vma->vm_end - vma->vm_start; | ||
} | ||
|
||
/* An ELF note in memory */ | ||
struct memelfnote | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters