Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30f74aa0 authored by Jason Baron's avatar Jason Baron Committed by Linus Torvalds
Browse files

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: default avatarJason Baron <jbaron@akamai.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a82603a8
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -2204,7 +2204,9 @@ static int elf_core_dump(struct coredump_params *cprm)


	dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
	dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);


	vma_filesz = kmalloc_array(segs - 1, sizeof(*vma_filesz), GFP_KERNEL);
	if (segs - 1 > ULONG_MAX / sizeof(*vma_filesz))
		goto end_coredump;
	vma_filesz = vmalloc((segs - 1) * sizeof(*vma_filesz));
	if (!vma_filesz)
	if (!vma_filesz)
		goto end_coredump;
		goto end_coredump;


@@ -2311,7 +2313,7 @@ static int elf_core_dump(struct coredump_params *cprm)
cleanup:
cleanup:
	free_note_info(&info);
	free_note_info(&info);
	kfree(shdr4extnum);
	kfree(shdr4extnum);
	kfree(vma_filesz);
	vfree(vma_filesz);
	kfree(phdr4note);
	kfree(phdr4note);
	kfree(elf);
	kfree(elf);
out:
out: