diff options
| author | Jason Baron <jbaron@akamai.com> | 2016-12-12 19:46:40 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-12 21:55:10 -0500 |
| commit | 30f74aa0854c2d5a331b507b14fe421ba4980511 (patch) | |
| tree | db150237a10336a84e822e626e275374a5485b67 | |
| parent | a82603a8325f89ec53d4c3e249a2e831b747a69d (diff) | |
binfmt_elf: use vmalloc() for allocation of vma_filesz
We have observed page allocations failures of order 4 during core dump
while trying to allocate vma_filesz. This results in a useless core
file of size 0. To improve reliability use vmalloc().
Note that the vmalloc() allocation is bounded by sysctl_max_map_count,
which is 65,530 by default. So with a 4k page size, and 8 bytes per
seg, this is a max of 128 pages or an order 7 allocation. Other parts
of the core dump path, such as fill_files_note() are already using
vmalloc() for presumably similar reasons.
Link: http://lkml.kernel.org/r/1479745791-17611-1-git-send-email-jbaron@akamai.com
Signed-off-by: Jason Baron <jbaron@akamai.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | fs/binfmt_elf.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 2472af2798c7..e6c1bd443806 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c | |||
| @@ -2204,7 +2204,9 @@ static int elf_core_dump(struct coredump_params *cprm) | |||
| 2204 | 2204 | ||
| 2205 | dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); | 2205 | dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); |
| 2206 | 2206 | ||
| 2207 | vma_filesz = kmalloc_array(segs - 1, sizeof(*vma_filesz), GFP_KERNEL); | 2207 | if (segs - 1 > ULONG_MAX / sizeof(*vma_filesz)) |
| 2208 | goto end_coredump; | ||
| 2209 | vma_filesz = vmalloc((segs - 1) * sizeof(*vma_filesz)); | ||
| 2208 | if (!vma_filesz) | 2210 | if (!vma_filesz) |
| 2209 | goto end_coredump; | 2211 | goto end_coredump; |
| 2210 | 2212 | ||
| @@ -2311,7 +2313,7 @@ end_coredump: | |||
| 2311 | cleanup: | 2313 | cleanup: |
| 2312 | free_note_info(&info); | 2314 | free_note_info(&info); |
| 2313 | kfree(shdr4extnum); | 2315 | kfree(shdr4extnum); |
| 2314 | kfree(vma_filesz); | 2316 | vfree(vma_filesz); |
| 2315 | kfree(phdr4note); | 2317 | kfree(phdr4note); |
| 2316 | kfree(elf); | 2318 | kfree(elf); |
| 2317 | out: | 2319 | out: |
