diff -urNp --exclude CVS --exclude BitKeeper x-ref/fs/binfmt_elf.c x/fs/binfmt_elf.c --- x-ref/fs/binfmt_elf.c 2003-07-15 02:05:51.000000000 +0200 +++ x/fs/binfmt_elf.c 2003-07-17 01:19:57.000000000 +0200 @@ -79,13 +79,13 @@ static struct linux_binfmt elf_format = #define BAD_ADDR(x) ((unsigned long)(x) > TASK_SIZE) -static void set_brk(unsigned long start, unsigned long end) +static unsigned long set_brk(unsigned long start, unsigned long end) { start = ELF_PAGEALIGN(start); end = ELF_PAGEALIGN(end); if (end <= start) - return; - do_brk(start, end - start); + return 0; + return do_brk(start, end - start); } @@ -319,6 +319,7 @@ static unsigned long load_elf_interp(str elf_type |= MAP_FIXED; map_addr = elf_map(interpreter, load_addr + vaddr, eppnt, elf_prot, elf_type); + error = map_addr; if (BAD_ADDR(map_addr)) goto out_close; @@ -357,8 +358,11 @@ static unsigned long load_elf_interp(str elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1); /* What we have mapped so far */ /* Map the last of the bss segment */ - if (last_bss > elf_bss) - do_brk(elf_bss, last_bss - elf_bss); + if (last_bss > elf_bss) { + error = do_brk(elf_bss, last_bss - elf_bss); + if (BAD_ADDR(error)) + goto out_close; + } *interp_load_addr = load_addr; error = ((unsigned long) interp_elf_ex->e_entry) + load_addr; @@ -641,7 +645,11 @@ static int load_elf_binary(struct linux_ /* There was a PT_LOAD segment with p_memsz > p_filesz before this one. Map anonymous pages, if needed, and clear the area. */ - set_brk (elf_bss + load_bias, elf_brk + load_bias); + error = set_brk (elf_bss + load_bias, elf_brk + load_bias); + /* here retval is zero */ + if (BAD_ADDR(error)) + goto out_free_dentry; + nbyte = ELF_PAGEOFFSET(elf_bss); if (nbyte) { nbyte = ELF_MIN_ALIGN - nbyte; @@ -668,8 +676,9 @@ static int load_elf_binary(struct linux_ } error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags); + /* here retval is zero */ if (BAD_ADDR(error)) - continue; + goto out_free_dentry; if (!load_addr_set) { load_addr_set = 1; @@ -718,12 +727,11 @@ static int load_elf_binary(struct linux_ fput(interpreter); kfree(elf_interpreter); + /* here retval is zero */ if (BAD_ADDR(elf_entry)) { - printk(KERN_ERR "Unable to load interpreter\n"); - kfree(elf_phdata); - send_sig(SIGSEGV, current, 0); + printk(KERN_WARNING "Unable to load interpreter\n"); retval = -ENOEXEC; /* Nobody gets to see this, but.. */ - goto out; + goto out_free_ph; } } @@ -757,7 +765,10 @@ static int load_elf_binary(struct linux_ /* Calling set_brk effectively mmaps the pages that we need * for the bss and break sections */ - set_brk(elf_bss, elf_brk); + error = set_brk(elf_bss, elf_brk); + /* here retval is zero */ + if (BAD_ADDR(error)) + goto out; padzero(elf_bss); @@ -796,14 +807,15 @@ static int load_elf_binary(struct linux_ start_thread(regs, elf_entry, bprm->p); if (current->ptrace & PT_PTRACED) send_sig(SIGTRAP, current, 0); - retval = 0; + /* here retval is zero */ out: return retval; /* error cleanup */ out_free_dentry: allow_write_access(interpreter); - fput(interpreter); + if (interpreter) + fput(interpreter); out_free_interp: if (elf_interpreter) kfree(elf_interpreter); @@ -882,8 +894,11 @@ static int load_elf_library(struct file len = ELF_PAGESTART(elf_phdata->p_filesz + elf_phdata->p_vaddr + ELF_MIN_ALIGN - 1); bss = elf_phdata->p_memsz + elf_phdata->p_vaddr; - if (bss > len) - do_brk(len, bss - len); + if (bss > len) { + error = do_brk(len, bss - len); + if (BAD_ADDR(error)) + goto out_free_ph; + } error = 0; out_free_ph: