aboutsummaryrefslogtreecommitdiffstats
path: root/fs/binfmt_elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/binfmt_elf.c')
-rw-r--r--fs/binfmt_elf.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index cc72bb43061d..be5869d34999 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -47,10 +47,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
47static int load_elf_library(struct file *); 47static int load_elf_library(struct file *);
48static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int); 48static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int);
49 49
50#ifndef elf_addr_t
51#define elf_addr_t unsigned long
52#endif
53
54/* 50/*
55 * If we don't support core dumping, then supply a NULL so we 51 * If we don't support core dumping, then supply a NULL so we
56 * don't even try. 52 * don't even try.
@@ -243,8 +239,9 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
243 if (interp_aout) { 239 if (interp_aout) {
244 argv = sp + 2; 240 argv = sp + 2;
245 envp = argv + argc + 1; 241 envp = argv + argc + 1;
246 __put_user((elf_addr_t)(unsigned long)argv, sp++); 242 if (__put_user((elf_addr_t)(unsigned long)argv, sp++) ||
247 __put_user((elf_addr_t)(unsigned long)envp, sp++); 243 __put_user((elf_addr_t)(unsigned long)envp, sp++))
244 return -EFAULT;
248 } else { 245 } else {
249 argv = sp; 246 argv = sp;
250 envp = argv + argc + 1; 247 envp = argv + argc + 1;
@@ -254,7 +251,8 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
254 p = current->mm->arg_end = current->mm->arg_start; 251 p = current->mm->arg_end = current->mm->arg_start;
255 while (argc-- > 0) { 252 while (argc-- > 0) {
256 size_t len; 253 size_t len;
257 __put_user((elf_addr_t)p, argv++); 254 if (__put_user((elf_addr_t)p, argv++))
255 return -EFAULT;
258 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES); 256 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
259 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES) 257 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
260 return 0; 258 return 0;
@@ -265,7 +263,8 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
265 current->mm->arg_end = current->mm->env_start = p; 263 current->mm->arg_end = current->mm->env_start = p;
266 while (envc-- > 0) { 264 while (envc-- > 0) {
267 size_t len; 265 size_t len;
268 __put_user((elf_addr_t)p, envp++); 266 if (__put_user((elf_addr_t)p, envp++))
267 return -EFAULT;
269 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES); 268 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
270 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES) 269 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
271 return 0; 270 return 0;
@@ -545,7 +544,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
545 unsigned long reloc_func_desc = 0; 544 unsigned long reloc_func_desc = 0;
546 char passed_fileno[6]; 545 char passed_fileno[6];
547 struct files_struct *files; 546 struct files_struct *files;
548 int have_pt_gnu_stack, executable_stack = EXSTACK_DEFAULT; 547 int executable_stack = EXSTACK_DEFAULT;
549 unsigned long def_flags = 0; 548 unsigned long def_flags = 0;
550 struct { 549 struct {
551 struct elfhdr elf_ex; 550 struct elfhdr elf_ex;
@@ -708,7 +707,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
708 executable_stack = EXSTACK_DISABLE_X; 707 executable_stack = EXSTACK_DISABLE_X;
709 break; 708 break;
710 } 709 }
711 have_pt_gnu_stack = (i < loc->elf_ex.e_phnum);
712 710
713 /* Some simple consistency checks for the interpreter */ 711 /* Some simple consistency checks for the interpreter */
714 if (elf_interpreter) { 712 if (elf_interpreter) {
@@ -856,7 +854,13 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
856 * default mmap base, as well as whatever program they 854 * default mmap base, as well as whatever program they
857 * might try to exec. This is because the brk will 855 * might try to exec. This is because the brk will
858 * follow the loader, and is not movable. */ 856 * follow the loader, and is not movable. */
859 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr); 857 if (current->flags & PF_RANDOMIZE)
858 load_bias = randomize_range(0x10000,
859 ELF_ET_DYN_BASE,
860 0);
861 else
862 load_bias = ELF_ET_DYN_BASE;
863 load_bias = ELF_PAGESTART(load_bias - vaddr);
860 } 864 }
861 865
862 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, 866 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,