aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>2009-06-30 14:41:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-30 21:55:59 -0400
commit341c87bf346f57748230628c5ad6ee69219250e8 (patch)
tree93937b91c3680127e38a310d5679b9ca84067b04
parentb1cfebc9231a69d46d66982a2c856ba41ef6d6b9 (diff)
elf: limit max map count to safe value
With ELF, at generating coredump, some more headers other than used vmas are added. When max_map_count == 65536, a core generated by following kinds of code can be unreadable because the number of ELF's program header is written in 16bit in Ehdr (please see elf.h) and the number overflows. == ... = mmap(); (munmap, mprotect, etc...) if (failed) abort(); == This can happen in mmap/munmap/mprotect/etc...which calls split_vma(). I think 65536 is not safe as _default_ and reduce it to 65530 is good for avoiding unexpected corrupted core. Anyway, max_map_count can be enlarged by sysctl if a user is brave.. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk> Cc: Jakub Jelinek <jakub@redhat.com> Acked-by: Roland McGrath <roland@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/binfmt_elf.c5
-rw-r--r--include/linux/sched.h16
2 files changed, 18 insertions, 3 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 9fa212b014a5..f1867900e459 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1929,7 +1929,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
1929 elf = kmalloc(sizeof(*elf), GFP_KERNEL); 1929 elf = kmalloc(sizeof(*elf), GFP_KERNEL);
1930 if (!elf) 1930 if (!elf)
1931 goto out; 1931 goto out;
1932 1932 /*
1933 * The number of segs are recored into ELF header as 16bit value.
1934 * Please check DEFAULT_MAX_MAP_COUNT definition when you modify here.
1935 */
1933 segs = current->mm->map_count; 1936 segs = current->mm->map_count;
1934#ifdef ELF_CORE_EXTRA_PHDRS 1937#ifdef ELF_CORE_EXTRA_PHDRS
1935 segs += ELF_CORE_EXTRA_PHDRS; 1938 segs += ELF_CORE_EXTRA_PHDRS;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4d0754269884..0085d758d645 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -349,8 +349,20 @@ extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
349struct nsproxy; 349struct nsproxy;
350struct user_namespace; 350struct user_namespace;
351 351
352/* Maximum number of active map areas.. This is a random (large) number */ 352/*
353#define DEFAULT_MAX_MAP_COUNT 65536 353 * Default maximum number of active map areas, this limits the number of vmas
354 * per mm struct. Users can overwrite this number by sysctl but there is a
355 * problem.
356 *
357 * When a program's coredump is generated as ELF format, a section is created
358 * per a vma. In ELF, the number of sections is represented in unsigned short.
359 * This means the number of sections should be smaller than 65535 at coredump.
360 * Because the kernel adds some informative sections to a image of program at
361 * generating coredump, we need some margin. The number of extra sections is
362 * 1-3 now and depends on arch. We use "5" as safe margin, here.
363 */
364#define MAPCOUNT_ELF_CORE_MARGIN (5)
365#define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
354 366
355extern int sysctl_max_map_count; 367extern int sysctl_max_map_count;
356 368