Commit 17c9f1a2 authored by David Howells's avatar David Howells Committed by Linus Torvalds

[PATCH] Fix some ELF-FDPIC binfmt problems

The attached patch fixes the following problems in the ELF-FDPIC binfmt
driver:

 (1) elf_fdpic_map_file() should be passed an mm_struct pointer, not NULL.

 (2) do_mmap() should be called with the mmap_sem held.

 (3) mm_struct::end_brk doesn't exist in 2.6 (debugging only).

 (4) Avoid debugging warnings by casting certain values to unsigned long
     before printing them.
Signed-Off-By: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 91808d6e
...@@ -315,7 +315,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs ...@@ -315,7 +315,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs
goto error_kill; goto error_kill;
if (interpreter_name) { if (interpreter_name) {
retval = elf_fdpic_map_file(&interp_params, interpreter, NULL, "interpreter"); retval = elf_fdpic_map_file(&interp_params, interpreter,
current->mm, "interpreter");
if (retval < 0) { if (retval < 0) {
printk(KERN_ERR "Unable to load interpreter\n"); printk(KERN_ERR "Unable to load interpreter\n");
goto error_kill; goto error_kill;
...@@ -341,6 +342,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs ...@@ -341,6 +342,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs
if (stack_size < PAGE_SIZE * 2) if (stack_size < PAGE_SIZE * 2)
stack_size = PAGE_SIZE * 2; stack_size = PAGE_SIZE * 2;
down_write(&current->mm->mmap_sem);
current->mm->start_brk = do_mmap(NULL, current->mm->start_brk = do_mmap(NULL,
0, 0,
stack_size, stack_size,
...@@ -349,12 +351,12 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs ...@@ -349,12 +351,12 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs
0); 0);
if (IS_ERR((void *) current->mm->start_brk)) { if (IS_ERR((void *) current->mm->start_brk)) {
up_write(&current->mm->mmap_sem);
retval = current->mm->start_brk; retval = current->mm->start_brk;
current->mm->start_brk = 0; current->mm->start_brk = 0;
goto error_kill; goto error_kill;
} }
down_write(&current->mm->mmap_sem);
if (do_mremap(current->mm->start_brk, if (do_mremap(current->mm->start_brk,
stack_size, stack_size,
ksize((char *) current->mm->start_brk), ksize((char *) current->mm->start_brk),
...@@ -381,9 +383,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs ...@@ -381,9 +383,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, struct pt_regs *regs
kdebug("- end_data %lx", (long) current->mm->end_data); kdebug("- end_data %lx", (long) current->mm->end_data);
kdebug("- start_brk %lx", (long) current->mm->start_brk); kdebug("- start_brk %lx", (long) current->mm->start_brk);
kdebug("- brk %lx", (long) current->mm->brk); kdebug("- brk %lx", (long) current->mm->brk);
#ifndef CONFIG_MMU
kdebug("- end_brk %lx", (long) current->mm->end_brk);
#endif
kdebug("- start_stack %lx", (long) current->mm->start_stack); kdebug("- start_stack %lx", (long) current->mm->start_stack);
#ifdef ELF_FDPIC_PLAT_INIT #ifdef ELF_FDPIC_PLAT_INIT
...@@ -870,8 +869,10 @@ static int elf_fdpic_map_file_constdisp_on_uclinux(struct elf_fdpic_params *para ...@@ -870,8 +869,10 @@ static int elf_fdpic_map_file_constdisp_on_uclinux(struct elf_fdpic_params *para
if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE) if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE)
mflags |= MAP_EXECUTABLE; mflags |= MAP_EXECUTABLE;
down_write(&mm->mmap_sem);
maddr = do_mmap(NULL, load_addr, top - base, maddr = do_mmap(NULL, load_addr, top - base,
PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0); PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0);
up_write(&mm->mmap_sem);
if (IS_ERR((void *) maddr)) if (IS_ERR((void *) maddr))
return (int) maddr; return (int) maddr;
...@@ -957,7 +958,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, ...@@ -957,7 +958,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
continue; continue;
kdebug("[LOAD] va=%lx of=%lx fs=%lx ms=%lx", kdebug("[LOAD] va=%lx of=%lx fs=%lx ms=%lx",
phdr->p_vaddr, phdr->p_offset, phdr->p_filesz, phdr->p_memsz); (unsigned long) phdr->p_vaddr,
(unsigned long) phdr->p_offset,
(unsigned long) phdr->p_filesz,
(unsigned long) phdr->p_memsz);
/* determine the mapping parameters */ /* determine the mapping parameters */
if (phdr->p_flags & PF_R) prot |= PROT_READ; if (phdr->p_flags & PF_R) prot |= PROT_READ;
...@@ -1008,8 +1012,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, ...@@ -1008,8 +1012,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
/* create the mapping */ /* create the mapping */
disp = phdr->p_vaddr & ~PAGE_MASK; disp = phdr->p_vaddr & ~PAGE_MASK;
down_write(&mm->mmap_sem);
maddr = do_mmap(file, maddr, phdr->p_memsz + disp, prot, flags, maddr = do_mmap(file, maddr, phdr->p_memsz + disp, prot, flags,
phdr->p_offset - disp); phdr->p_offset - disp);
up_write(&mm->mmap_sem);
kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx",
loop, phdr->p_memsz + disp, prot, flags, phdr->p_offset - disp, loop, phdr->p_memsz + disp, prot, flags, phdr->p_offset - disp,
...@@ -1051,7 +1057,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, ...@@ -1051,7 +1057,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
unsigned long xmaddr; unsigned long xmaddr;
flags |= MAP_FIXED | MAP_ANONYMOUS; flags |= MAP_FIXED | MAP_ANONYMOUS;
down_write(&mm->mmap_sem);
xmaddr = do_mmap(NULL, xaddr, excess - excess1, prot, flags, 0); xmaddr = do_mmap(NULL, xaddr, excess - excess1, prot, flags, 0);
up_write(&mm->mmap_sem);
kdebug("mmap[%d] <anon>" kdebug("mmap[%d] <anon>"
" ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx", " ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment