
From: David Howells <dhowells@redhat.com>

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: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/fs/binfmt_elf_fdpic.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff -puN fs/binfmt_elf_fdpic.c~fix-some-elf-fdpic-binfmt-problems fs/binfmt_elf_fdpic.c
--- 25/fs/binfmt_elf_fdpic.c~fix-some-elf-fdpic-binfmt-problems	Thu Dec  9 14:09:16 2004
+++ 25-akpm/fs/binfmt_elf_fdpic.c	Thu Dec  9 14:09:16 2004
@@ -315,7 +315,8 @@ static int load_elf_fdpic_binary(struct 
 		goto error_kill;
 
 	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) {
 			printk(KERN_ERR "Unable to load interpreter\n");
 			goto error_kill;
@@ -341,6 +342,7 @@ static int load_elf_fdpic_binary(struct 
 	if (stack_size < PAGE_SIZE * 2)
 		stack_size = PAGE_SIZE * 2;
 
+	down_write(&current->mm->mmap_sem);
 	current->mm->start_brk = do_mmap(NULL,
 					 0,
 					 stack_size,
@@ -349,12 +351,12 @@ static int load_elf_fdpic_binary(struct 
 					 0);
 
 	if (IS_ERR((void *) current->mm->start_brk)) {
+		up_write(&current->mm->mmap_sem);
 		retval = current->mm->start_brk;
 		current->mm->start_brk = 0;
 		goto error_kill;
 	}
 
-	down_write(&current->mm->mmap_sem);
 	if (do_mremap(current->mm->start_brk,
 		      stack_size,
 		      ksize((char *) current->mm->start_brk),
@@ -381,9 +383,6 @@ static int load_elf_fdpic_binary(struct 
 	kdebug("- end_data    %lx",	(long) current->mm->end_data);
 	kdebug("- start_brk   %lx",	(long) current->mm->start_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);
 
 #ifdef ELF_FDPIC_PLAT_INIT
@@ -870,8 +869,10 @@ static int elf_fdpic_map_file_constdisp_
 	if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE)
 		mflags |= MAP_EXECUTABLE;
 
+	down_write(&mm->mmap_sem);
 	maddr = do_mmap(NULL, load_addr, top - base,
 			PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0);
+	up_write(&mm->mmap_sem);
 	if (IS_ERR((void *) maddr))
 		return (int) maddr;
 
@@ -957,7 +958,10 @@ static int elf_fdpic_map_file_by_direct_
 			continue;
 
 		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 */
 		if (phdr->p_flags & PF_R) prot |= PROT_READ;
@@ -1008,8 +1012,10 @@ static int elf_fdpic_map_file_by_direct_
 
 		/* create the mapping */
 		disp = phdr->p_vaddr & ~PAGE_MASK;
+		down_write(&mm->mmap_sem);
 		maddr = do_mmap(file, maddr, phdr->p_memsz + disp, prot, flags,
 				phdr->p_offset - disp);
+		up_write(&mm->mmap_sem);
 
 		kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx",
 		       loop, phdr->p_memsz + disp, prot, flags, phdr->p_offset - disp,
@@ -1051,7 +1057,9 @@ static int elf_fdpic_map_file_by_direct_
 			unsigned long xmaddr;
 
 			flags |= MAP_FIXED | MAP_ANONYMOUS;
+			down_write(&mm->mmap_sem);
 			xmaddr = do_mmap(NULL, xaddr, excess - excess1, prot, flags, 0);
+			up_write(&mm->mmap_sem);
 
 			kdebug("mmap[%d] <anon>"
 			       " ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx",
_
