patch-2.0.34 linux/fs/binfmt_elf.c

Next file: linux/fs/binfmt_em86.c
Previous file: linux/fs/Makefile
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.33/linux/fs/binfmt_elf.c linux/fs/binfmt_elf.c
@@ -37,9 +37,9 @@
 
 #include <linux/elf.h>
 
-static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs);
+static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
 static int load_elf_library(int fd);
-extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
+extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
 extern void dump_thread(struct pt_regs *, struct user *);
 
 /*
@@ -47,7 +47,7 @@
  * don't even try.
  */
 #ifdef USE_ELF_CORE_DUMP
-static int elf_core_dump(long signr, struct pt_regs * regs);
+static int elf_core_dump(long signr, struct pt_regs *regs);
 #else
 #define elf_core_dump	NULL
 #endif
@@ -55,11 +55,12 @@
 #define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_EXEC_PAGESIZE-1))
 #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_EXEC_PAGESIZE-1))
 
-static struct linux_binfmt elf_format = {
+static struct linux_binfmt elf_format =
+{
 #ifndef MODULE
 	NULL, NULL, load_elf_binary, load_elf_library, elf_core_dump
 #else
-	NULL, &mod_use_count_, load_elf_binary, load_elf_library, elf_core_dump
+  NULL, &mod_use_count_, load_elf_binary, load_elf_library, elf_core_dump
 #endif
 };
 
@@ -67,7 +68,7 @@
 {
 	start = PAGE_ALIGN(start);
 	end = PAGE_ALIGN(end);
-	if (end <= start) 
+	if (end <= start)
 		return;
 	do_mmap(NULL, start, end - start,
 		PROT_READ | PROT_WRITE | PROT_EXEC,
@@ -84,9 +85,9 @@
 static void padzero(unsigned long elf_bss)
 {
 	unsigned long nbyte;
-	char * fpnt;
-  
-	nbyte = elf_bss & (PAGE_SIZE-1);
+	char *fpnt;
+
+	nbyte = elf_bss & (PAGE_SIZE - 1);
 	if (nbyte) {
 		nbyte = PAGE_SIZE - nbyte;
 		/* FIXME: someone should investigate, why a bad binary
@@ -103,10 +104,10 @@
 	}
 }
 
-unsigned long * create_elf_tables(char *p, int argc, int envc, 
-				  struct elfhdr * exec,
-				  unsigned long load_addr,
-				  unsigned long interp_load_addr, int ibcs)
+unsigned long *create_elf_tables(char *p, int argc, int envc,
+				 struct elfhdr *exec,
+				 unsigned long load_addr,
+				 unsigned long interp_load_addr, int ibcs)
 {
 	unsigned long *argv, *envp, *dlinfo;
 	unsigned long *sp;
@@ -115,52 +116,53 @@
 	 * Force 16 byte alignment here for generality.
 	 */
 	sp = (unsigned long *) (~15UL & (unsigned long) p);
-	sp -= exec ? DLINFO_ITEMS*2 : 2;
+	sp -= exec ? DLINFO_ITEMS * 2 : 2;
 	dlinfo = sp;
-	sp -= envc+1;
+	sp -= envc + 1;
 	envp = sp;
-	sp -= argc+1;
+	sp -= argc + 1;
 	argv = sp;
 	if (!ibcs) {
-		put_user(envp,--sp);
-		put_user(argv,--sp);
+		put_user(envp, --sp);
+		put_user(argv, --sp);
 	}
-
 #define NEW_AUX_ENT(id, val) \
 	  put_user ((id), dlinfo++); \
 	  put_user ((val), dlinfo++)
 
-	if (exec) { /* Put this here for an ELF program interpreter */
-	  struct elf_phdr * eppnt;
-	  eppnt = (struct elf_phdr *) exec->e_phoff;
-
-	  NEW_AUX_ENT (AT_PHDR, load_addr + exec->e_phoff);
-	  NEW_AUX_ENT (AT_PHENT, sizeof (struct elf_phdr));
-	  NEW_AUX_ENT (AT_PHNUM, exec->e_phnum);
-	  NEW_AUX_ENT (AT_PAGESZ, PAGE_SIZE);
-	  NEW_AUX_ENT (AT_BASE, interp_load_addr);
-	  NEW_AUX_ENT (AT_FLAGS, 0);
-	  NEW_AUX_ENT (AT_ENTRY, (unsigned long) exec->e_entry);
-	  NEW_AUX_ENT (AT_UID, (unsigned long) current->uid);
-	  NEW_AUX_ENT (AT_EUID, (unsigned long) current->euid);
-	  NEW_AUX_ENT (AT_GID, (unsigned long) current->gid);
-	  NEW_AUX_ENT (AT_EGID, (unsigned long) current->egid);
+	if (exec) {		/* Put this here for an ELF program interpreter */
+		struct elf_phdr *eppnt;
+		eppnt = (struct elf_phdr *) exec->e_phoff;
+
+		NEW_AUX_ENT(AT_PHDR, load_addr + exec->e_phoff);
+		NEW_AUX_ENT(AT_PHENT, sizeof(struct elf_phdr));
+		NEW_AUX_ENT(AT_PHNUM, exec->e_phnum);
+		NEW_AUX_ENT(AT_PAGESZ, PAGE_SIZE);
+		NEW_AUX_ENT(AT_BASE, interp_load_addr);
+		NEW_AUX_ENT(AT_FLAGS, 0);
+		NEW_AUX_ENT(AT_ENTRY, (unsigned long) exec->e_entry);
+		NEW_AUX_ENT(AT_UID, (unsigned long) current->uid);
+		NEW_AUX_ENT(AT_EUID, (unsigned long) current->euid);
+		NEW_AUX_ENT(AT_GID, (unsigned long) current->gid);
+		NEW_AUX_ENT(AT_EGID, (unsigned long) current->egid);
 	}
-	NEW_AUX_ENT (AT_NULL, 0);
+	NEW_AUX_ENT(AT_NULL, 0);
 #undef NEW_AUX_ENT
-	put_user((unsigned long)argc,--sp);
+	put_user((unsigned long) argc, --sp);
 	current->mm->arg_start = (unsigned long) p;
-	while (argc-->0) {
-		put_user(p,argv++);
-		while (get_user(p++)) /* nothing */ ;
+	while (argc-- > 0) {
+		put_user(p, argv++);
+		while (get_user(p++))	/* nothing */
+			;
 	}
-	put_user(0,argv);
+	put_user(0, argv);
 	current->mm->arg_end = current->mm->env_start = (unsigned long) p;
-	while (envc-->0) {
-		put_user(p,envp++);
-		while (get_user(p++)) /* nothing */ ;
+	while (envc-- > 0) {
+		put_user(p, envp++);
+		while (get_user(p++))	/* nothing */
+			;
 	}
-	put_user(0,envp);
+	put_user(0, envp);
 	current->mm->env_end = (unsigned long) p;
 	return sp;
 }
@@ -171,12 +173,12 @@
    is only provided so that we can read a.out libraries that have
    an ELF header */
 
-static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex,
-				     struct inode * interpreter_inode, 
+static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
+				     struct inode *interpreter_inode,
 				     unsigned long *interp_load_addr)
 {
-	struct file * file;
-	struct elf_phdr *elf_phdata  =  NULL;
+	struct file *file;
+	struct elf_phdr *elf_phdata = NULL;
 	struct elf_phdr *eppnt;
 	unsigned long load_addr;
 	int load_addr_set = 0;
@@ -185,108 +187,104 @@
 	unsigned long last_bss, elf_bss;
 	unsigned long error;
 	int i;
-	
+
 	elf_bss = 0;
 	last_bss = 0;
 	error = load_addr = 0;
-	
+
 	/* First of all, some simple consistency checks */
-	if ((interp_elf_ex->e_type != ET_EXEC && 
-	    interp_elf_ex->e_type != ET_DYN) || 
-	   !elf_check_arch(interp_elf_ex->e_machine) ||
-	   (!interpreter_inode->i_op ||
-	    !interpreter_inode->i_op->default_file_ops->mmap)){
+	if ((interp_elf_ex->e_type != ET_EXEC &&
+	     interp_elf_ex->e_type != ET_DYN) ||
+	    !elf_check_arch(interp_elf_ex->e_machine) ||
+	    (!interpreter_inode->i_op ||
+	     !interpreter_inode->i_op->default_file_ops->mmap)) {
 		return ~0UL;
 	}
-	
 	/* Now read in all of the header information */
-	
+
 	if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > PAGE_SIZE)
-	    return ~0UL;
-	
-	elf_phdata =  (struct elf_phdr *) 
-		kmalloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum, 
-			GFP_KERNEL);
+		 return ~0UL;
+
+	elf_phdata = (struct elf_phdr *)
+	    kmalloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum,
+		    GFP_KERNEL);
 	if (!elf_phdata)
-	  return ~0UL;
-	
+		return ~0UL;
+
 	/*
 	 * If the size of this structure has changed, then punt, since
 	 * we will be doing the wrong thing.
 	 */
-	if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr))
-	  {
-	    kfree(elf_phdata);
-	    return ~0UL;
-	  }
-
-	retval = read_exec(interpreter_inode, interp_elf_ex->e_phoff, 
+	if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
+		kfree(elf_phdata);
+		return ~0UL;
+	}
+	retval = read_exec(interpreter_inode, interp_elf_ex->e_phoff,
 			   (char *) elf_phdata,
-			   sizeof(struct elf_phdr) * interp_elf_ex->e_phnum, 1);
-	
+		    sizeof(struct elf_phdr) * interp_elf_ex->e_phnum, 1);
+
 	if (retval < 0) {
-		kfree (elf_phdata);
+		kfree(elf_phdata);
 		return retval;
- 	}
-
+	}
 	elf_exec_fileno = open_inode(interpreter_inode, O_RDONLY);
 	if (elf_exec_fileno < 0) {
-	  kfree(elf_phdata);
-	  return ~0UL;
+		kfree(elf_phdata);
+		return ~0UL;
 	}
-
 	file = current->files->fd[elf_exec_fileno];
 
 	eppnt = elf_phdata;
-	for(i=0; i<interp_elf_ex->e_phnum; i++, eppnt++)
-	  if (eppnt->p_type == PT_LOAD) {
-	    int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
-	    int elf_prot = 0;
-	    unsigned long vaddr = 0;
-	    unsigned long k;
-
-	    if (eppnt->p_flags & PF_R) elf_prot =  PROT_READ;
-	    if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
-	    if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
-	    if (interp_elf_ex->e_type == ET_EXEC || load_addr_set) {
-	    	elf_type |= MAP_FIXED;
-	    	vaddr = eppnt->p_vaddr;
-	    }
-	    
-	    error = do_mmap(file, 
-			    load_addr + ELF_PAGESTART(vaddr),
-			    eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr),
-			    elf_prot,
-			    elf_type,
-			    eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
-	    
-	    if (error > -1024UL) {
-	      /* Real error */
-	      sys_close(elf_exec_fileno);
-	      kfree(elf_phdata);
-	      return ~0UL;
-	    }
-
-	    if (!load_addr_set && interp_elf_ex->e_type == ET_DYN) {
-	      load_addr = error;
-	      load_addr_set = 1;
-	    }
-
-	    /*
-	     * Find the end of the file  mapping for this phdr, and keep
-	     * track of the largest address we see for this.
-	     */
-	    k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
-	    if (k > elf_bss) elf_bss = k;
-
-	    /*
-	     * Do the same thing for the memory mapping - between
-	     * elf_bss and last_bss is the bss section.
-	     */
-	    k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
-	    if (k > last_bss) last_bss = k;
-	  }
-	
+	for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++)
+		if (eppnt->p_type == PT_LOAD) {
+			int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
+			int elf_prot = 0;
+			unsigned long vaddr = 0;
+			unsigned long k;
+
+			if (eppnt->p_flags & PF_R)
+				elf_prot = PROT_READ;
+			if (eppnt->p_flags & PF_W)
+				elf_prot |= PROT_WRITE;
+			if (eppnt->p_flags & PF_X)
+				elf_prot |= PROT_EXEC;
+			if (interp_elf_ex->e_type == ET_EXEC || load_addr_set) {
+				elf_type |= MAP_FIXED;
+				vaddr = eppnt->p_vaddr;
+			}
+			error = do_mmap(file,
+					load_addr + ELF_PAGESTART(vaddr),
+			eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr),
+					elf_prot,
+					elf_type,
+			eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
+
+			if (error > -1024UL) {
+				/* Real error */
+				sys_close(elf_exec_fileno);
+				kfree(elf_phdata);
+				return ~0UL;
+			}
+			if (!load_addr_set && interp_elf_ex->e_type == ET_DYN) {
+				load_addr = error;
+				load_addr_set = 1;
+			}
+			/*
+			 * Find the end of the file  mapping for this phdr, and keep
+			 * track of the largest address we see for this.
+			 */
+			k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
+			if (k > elf_bss)
+				elf_bss = k;
+
+			/*
+			 * Do the same thing for the memory mapping - between
+			 * elf_bss and last_bss is the bss section.
+			 */
+			k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
+			if (k > last_bss)
+				last_bss = k;
+		}
 	/* Now use mmap to map the library into memory. */
 
 	sys_close(elf_exec_fileno);
@@ -298,55 +296,56 @@
 	 * bss page.
 	 */
 	padzero(elf_bss);
-	elf_bss = ELF_PAGESTART(elf_bss + ELF_EXEC_PAGESIZE - 1); /* What we have mapped so far */
+	elf_bss = ELF_PAGESTART(elf_bss + ELF_EXEC_PAGESIZE - 1);	/* What we have mapped so far */
 
 	/* Map the last of the bss segment */
 	if (last_bss > elf_bss)
-	  do_mmap(NULL, elf_bss, last_bss-elf_bss,
-		  PROT_READ|PROT_WRITE|PROT_EXEC,
-		  MAP_FIXED|MAP_PRIVATE, 0);
+		do_mmap(NULL, elf_bss, last_bss - elf_bss,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE, 0);
 	kfree(elf_phdata);
 
 	*interp_load_addr = load_addr;
 	return ((unsigned long) interp_elf_ex->e_entry) + load_addr;
 }
 
-static unsigned long load_aout_interp(struct exec * interp_ex,
-			     struct inode * interpreter_inode)
+static unsigned long load_aout_interp(struct exec *interp_ex,
+				      struct inode *interpreter_inode)
 {
-  int retval;
-  unsigned long elf_entry;
-  
-  current->mm->brk = interp_ex->a_bss +
-    (current->mm->end_data = interp_ex->a_data +
-     (current->mm->end_code = interp_ex->a_text));
-  elf_entry = interp_ex->a_entry;
-  
-  
-  if (N_MAGIC(*interp_ex) == OMAGIC) {
-    do_mmap(NULL, 0, interp_ex->a_text+interp_ex->a_data,
-	    PROT_READ|PROT_WRITE|PROT_EXEC,
-	    MAP_FIXED|MAP_PRIVATE, 0);
-    retval = read_exec(interpreter_inode, 32, (char *) 0, 
-		       interp_ex->a_text+interp_ex->a_data, 0);
-  } else if (N_MAGIC(*interp_ex) == ZMAGIC || N_MAGIC(*interp_ex) == QMAGIC) {
-    do_mmap(NULL, 0, interp_ex->a_text+interp_ex->a_data,
-	    PROT_READ|PROT_WRITE|PROT_EXEC,
-	    MAP_FIXED|MAP_PRIVATE, 0);
-    retval = read_exec(interpreter_inode,
-		       N_TXTOFF(*interp_ex) ,
-		       (char *) N_TXTADDR(*interp_ex),
-		       interp_ex->a_text+interp_ex->a_data, 0);
-  } else
-    retval = -1;
-  
-  if (retval >= 0)
-    do_mmap(NULL, ELF_PAGESTART(interp_ex->a_text + interp_ex->a_data + ELF_EXEC_PAGESIZE - 1),
-	    interp_ex->a_bss,
-	    PROT_READ|PROT_WRITE|PROT_EXEC,
-	    MAP_FIXED|MAP_PRIVATE, 0);
-  if (retval < 0) return ~0UL;
-  return elf_entry;
+	int retval;
+	unsigned long elf_entry;
+
+	current->mm->brk = interp_ex->a_bss +
+	    (current->mm->end_data = interp_ex->a_data +
+	     (current->mm->end_code = interp_ex->a_text));
+	elf_entry = interp_ex->a_entry;
+
+
+	if (N_MAGIC(*interp_ex) == OMAGIC) {
+		do_mmap(NULL, 0, interp_ex->a_text + interp_ex->a_data,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE, 0);
+		retval = read_exec(interpreter_inode, 32, (char *) 0,
+			       interp_ex->a_text + interp_ex->a_data, 0);
+	} else if (N_MAGIC(*interp_ex) == ZMAGIC || N_MAGIC(*interp_ex) == QMAGIC) {
+		do_mmap(NULL, 0, interp_ex->a_text + interp_ex->a_data,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE, 0);
+		retval = read_exec(interpreter_inode,
+				   N_TXTOFF(*interp_ex),
+				   (char *) N_TXTADDR(*interp_ex),
+			       interp_ex->a_text + interp_ex->a_data, 0);
+	} else
+		retval = -1;
+
+	if (retval >= 0)
+		do_mmap(NULL, ELF_PAGESTART(interp_ex->a_text + interp_ex->a_data + ELF_EXEC_PAGESIZE - 1),
+			interp_ex->a_bss,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE, 0);
+	if (retval < 0)
+		return ~0UL;
+	return elf_entry;
 }
 
 /*
@@ -359,13 +358,12 @@
 #define INTERPRETER_ELF 2
 
 
-static inline int
-do_load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
+static inline int do_load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 {
 	struct elfhdr elf_ex;
 	struct elfhdr interp_elf_ex;
-	struct file * file;
-  	struct exec interp_ex;
+	struct file *file;
+	struct exec interp_ex;
 	struct inode *interpreter_inode;
 	unsigned long load_addr;
 	int load_addr_set = 0;
@@ -374,125 +372,123 @@
 	int i;
 	int old_fs;
 	int error;
-	struct elf_phdr * elf_ppnt, *elf_phdata;
+	struct elf_phdr *elf_ppnt, *elf_phdata;
 	int elf_exec_fileno;
 	unsigned long elf_bss, k, elf_brk;
-	int retval;
-	char * elf_interpreter;
+	int retval, ret_namei = -1;
+	char *elf_interpreter;
 	unsigned long elf_entry, interp_load_addr = 0;
 	int status;
 	unsigned long start_code, end_code, end_data;
 	unsigned long elf_stack;
 	char passed_fileno[6];
-	
+
 	ibcs2_interpreter = 0;
 	status = 0;
 	load_addr = 0;
-	elf_ex = *((struct elfhdr *) bprm->buf);	  /* exec-header */
-	
+	elf_ex = *((struct elfhdr *) bprm->buf);	/* exec-header */
+
 	if (elf_ex.e_ident[0] != 0x7f ||
-	    strncmp(&elf_ex.e_ident[1], "ELF",3) != 0) {
-		return  -ENOEXEC;
+	    strncmp(&elf_ex.e_ident[1], "ELF", 3) != 0) {
+		return -ENOEXEC;
 	}
-	
-	
 	/* First of all, some simple consistency checks */
 	if ((elf_ex.e_type != ET_EXEC &&
-	    elf_ex.e_type != ET_DYN) || 
-	   (! elf_check_arch(elf_ex.e_machine)) ||
-	   (!bprm->inode->i_op || !bprm->inode->i_op->default_file_ops ||
-	    !bprm->inode->i_op->default_file_ops->mmap)){
+	     elf_ex.e_type != ET_DYN) ||
+	    (!elf_check_arch(elf_ex.e_machine)) ||
+	    (!bprm->inode->i_op || !bprm->inode->i_op->default_file_ops ||
+	     !bprm->inode->i_op->default_file_ops->mmap)) {
 		return -ENOEXEC;
 	}
-	
 	/* Now read in all of the header information */
-	
-	elf_phdata = (struct elf_phdr *) kmalloc(elf_ex.e_phentsize * 
-						 elf_ex.e_phnum, GFP_KERNEL);
+
+	elf_phdata = (struct elf_phdr *) kmalloc(elf_ex.e_phentsize *
+					     elf_ex.e_phnum, GFP_KERNEL);
 	if (elf_phdata == NULL) {
 		return -ENOMEM;
 	}
-	
 	retval = read_exec(bprm->inode, elf_ex.e_phoff, (char *) elf_phdata,
 			   elf_ex.e_phentsize * elf_ex.e_phnum, 1);
 	if (retval < 0) {
-		kfree (elf_phdata);
+		kfree(elf_phdata);
 		return retval;
 	}
-	
 	elf_ppnt = elf_phdata;
-	
+
 	elf_bss = 0;
 	elf_brk = 0;
-	
+
 	elf_exec_fileno = open_inode(bprm->inode, O_RDONLY);
 
 	if (elf_exec_fileno < 0) {
-		kfree (elf_phdata);
+		kfree(elf_phdata);
 		return elf_exec_fileno;
 	}
-	
 	file = current->files->fd[elf_exec_fileno];
-	
+
 	elf_stack = ~0UL;
 	elf_interpreter = NULL;
 	start_code = ~0UL;
 	end_code = 0;
 	end_data = 0;
-	
-	for(i=0;i < elf_ex.e_phnum; i++){
+
+	for (i = 0; i < elf_ex.e_phnum; i++) {
 		if (elf_ppnt->p_type == PT_INTERP) {
-		  	if ( elf_interpreter != NULL )
-			{
-				kfree (elf_phdata);
+			if (elf_interpreter != NULL) {
+				iput(interpreter_inode);
+				kfree(elf_phdata);
 				kfree(elf_interpreter);
 				sys_close(elf_exec_fileno);
 				return -EINVAL;
 			}
-
 			/* This is the program interpreter used for
 			 * shared libraries - for now assume that this
 			 * is an a.out format binary 
 			 */
-			
-			elf_interpreter = (char *) kmalloc(elf_ppnt->p_filesz, 
+
+			elf_interpreter = (char *) kmalloc(elf_ppnt->p_filesz,
 							   GFP_KERNEL);
 			if (elf_interpreter == NULL) {
-				kfree (elf_phdata);
+				kfree(elf_phdata);
 				sys_close(elf_exec_fileno);
 				return -ENOMEM;
 			}
-			
-			retval = read_exec(bprm->inode,elf_ppnt->p_offset,
+			retval = read_exec(bprm->inode, elf_ppnt->p_offset,
 					   elf_interpreter,
 					   elf_ppnt->p_filesz, 1);
 			/* If the program interpreter is one of these two,
 			   then assume an iBCS2 image. Otherwise assume
 			   a native linux image. */
-			if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 ||
-			    strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0)
-			  ibcs2_interpreter = 1;
+			if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
+			strcmp(elf_interpreter, "/usr/lib/ld.so.1") == 0)
+				ibcs2_interpreter = 1;
 #if 0
 			printk("Using ELF interpreter %s\n", elf_interpreter);
 #endif
 			if (retval >= 0) {
-				old_fs = get_fs(); /* This could probably be optimized */
+				old_fs = get_fs();	/* This could probably be optimized */
 				set_fs(get_ds());
-				retval = open_namei(elf_interpreter, 0, 0,
-						    &interpreter_inode, NULL);
+				retval = ret_namei = open_namei(elf_interpreter, 0, 0,
+					       &interpreter_inode, NULL);
 				set_fs(old_fs);
 			}
+			if (retval >= 0)
+				retval = permission(interpreter_inode, MAY_EXEC);
+			if (retval >= 0)
+				retval = S_ISREG(interpreter_inode->i_mode) ? 0 : -EACCES;
 
 			if (retval >= 0)
-				retval = read_exec(interpreter_inode,0,bprm->buf,128, 1);
-			
+				retval = read_exec(interpreter_inode, 0, bprm->buf, 128, 1);
+
 			if (retval >= 0) {
-				interp_ex = *((struct exec *) bprm->buf);		/* exec-header */
-				interp_elf_ex = *((struct elfhdr *) bprm->buf);	  /* exec-header */
-				
+				interp_ex = *((struct exec *) bprm->buf);	/* exec-header */
+				interp_elf_ex = *((struct elfhdr *) bprm->buf);		/* exec-header */
+
 			}
 			if (retval < 0) {
-				kfree (elf_phdata);
+				if (ret_namei >= 0)
+					iput(interpreter_inode);
+				kfree(elf_phdata);
 				kfree(elf_interpreter);
 				sys_close(elf_exec_fileno);
 				return retval;
@@ -502,56 +498,56 @@
 	}
 
 	/* Some simple consistency checks for the interpreter */
-	if (elf_interpreter){
+	if (elf_interpreter) {
 		interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
 
 		/* Now figure out which format our binary is */
-		if ((N_MAGIC(interp_ex) != OMAGIC) && 
+		if ((N_MAGIC(interp_ex) != OMAGIC) &&
 		    (N_MAGIC(interp_ex) != ZMAGIC) &&
-		    (N_MAGIC(interp_ex) != QMAGIC)) 
-		  interpreter_type = INTERPRETER_ELF;
+		    (N_MAGIC(interp_ex) != QMAGIC))
+			interpreter_type = INTERPRETER_ELF;
 
 		if (interp_elf_ex.e_ident[0] != 0x7f ||
-		    strncmp(&interp_elf_ex.e_ident[1], "ELF",3) != 0)
-		  interpreter_type &= ~INTERPRETER_ELF;
+		    strncmp(&interp_elf_ex.e_ident[1], "ELF", 3) != 0)
+			interpreter_type &= ~INTERPRETER_ELF;
 
-		if (!interpreter_type)
-		  {
-		    kfree(elf_interpreter);
-		    kfree(elf_phdata);
-		    sys_close(elf_exec_fileno);
-		    return -ELIBBAD;
-		  }
+		if (!interpreter_type) {
+			iput(interpreter_inode);
+			kfree(elf_interpreter);
+			kfree(elf_phdata);
+			sys_close(elf_exec_fileno);
+			return -ELIBBAD;
+		}
 	}
-	
 	/* OK, we are done with that, now set up the arg stuff,
 	   and then start this sucker up */
-	
+
 	if (!bprm->sh_bang) {
-		char * passed_p;
-		
+		char *passed_p;
+
 		if (interpreter_type == INTERPRETER_AOUT) {
-		  sprintf(passed_fileno, "%d", elf_exec_fileno);
-		  passed_p = passed_fileno;
-		
-		  if (elf_interpreter) {
-		    bprm->p = copy_strings(1,&passed_p,bprm->page,bprm->p,2);
-		    bprm->argc++;
-		  }
+			sprintf(passed_fileno, "%d", elf_exec_fileno);
+			passed_p = passed_fileno;
+
+			if (elf_interpreter) {
+				bprm->p = copy_strings(1, &passed_p, bprm->page, bprm->p, 2);
+				bprm->argc++;
+			}
 		}
 		if (!bprm->p) {
 			if (elf_interpreter) {
-			      kfree(elf_interpreter);
+				kfree(elf_interpreter);
 			}
-			kfree (elf_phdata);
+			iput(interpreter_inode);
+			kfree(elf_phdata);
 			sys_close(elf_exec_fileno);
 			return -E2BIG;
 		}
 	}
-	
-	if (flush_old_exec(bprm))
+	if (flush_old_exec(bprm)) {
+		iput(interpreter_inode);
 		return -ENOMEM;
-
+	}
 	/* OK, This is the point of no return */
 
 	current->mm->end_data = 0;
@@ -559,86 +555,93 @@
 	current->mm->start_mmap = ELF_START_MMAP;
 	current->mm->mmap = NULL;
 	elf_entry = (unsigned long) elf_ex.e_entry;
-	
+
 	/* Do this so that we can load the interpreter, if need be.  We will
 	   change some of these later */
 	current->mm->rss = 0;
 	bprm->p = setup_arg_pages(bprm->p, bprm);
 	current->mm->start_stack = bprm->p;
-	
+
 	/* Now we do a little grungy work by mmaping the ELF image into
 	   the correct location in memory.  At this point, we assume that
 	   the image should be loaded at fixed address, not at a variable
 	   address. */
-	
+
 	old_fs = get_fs();
 	set_fs(get_ds());
-	for(i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) {
+	for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) {
 		if (elf_ppnt->p_type == PT_LOAD) {
 			int elf_prot = 0;
-			if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ;
-			if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
-			if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
+			if (elf_ppnt->p_flags & PF_R)
+				elf_prot |= PROT_READ;
+			if (elf_ppnt->p_flags & PF_W)
+				elf_prot |= PROT_WRITE;
+			if (elf_ppnt->p_flags & PF_X)
+				elf_prot |= PROT_EXEC;
 
 			error = do_mmap(file,
 					ELF_PAGESTART(elf_ppnt->p_vaddr),
 					(elf_ppnt->p_filesz +
-					 ELF_PAGEOFFSET(elf_ppnt->p_vaddr)),
+				      ELF_PAGEOFFSET(elf_ppnt->p_vaddr)),
 					elf_prot,
 					(MAP_FIXED | MAP_PRIVATE |
 					 MAP_DENYWRITE | MAP_EXECUTABLE),
 					(elf_ppnt->p_offset -
-					 ELF_PAGEOFFSET(elf_ppnt->p_vaddr)));
-			
+				     ELF_PAGEOFFSET(elf_ppnt->p_vaddr)));
+
 #ifdef LOW_ELF_STACK
-			if (ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) 
+			if (ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack)
 				elf_stack = ELF_PAGESTART(elf_ppnt->p_vaddr);
 #endif
-			
-			if (!load_addr_set) { 
-			  load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset;
-			  load_addr_set = 1;
+
+			if (!load_addr_set) {
+				load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset;
+				load_addr_set = 1;
 			}
 			k = elf_ppnt->p_vaddr;
-			if (k < start_code) start_code = k;
+			if (k < start_code)
+				start_code = k;
 			k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
-			if (k > elf_bss) elf_bss = k;
+			if (k > elf_bss)
+				elf_bss = k;
 #if 1
-			if ((elf_ppnt->p_flags & PF_X) && end_code <  k)
+			if ((elf_ppnt->p_flags & PF_X) && end_code < k)
 #else
-			if ( !(elf_ppnt->p_flags & PF_W) && end_code <  k)
+			if (!(elf_ppnt->p_flags & PF_W) && end_code < k)
 #endif
-				end_code = k; 
-			if (end_data < k) end_data = k; 
+				end_code = k;
+			if (end_data < k)
+				end_data = k;
 			k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
-			if (k > elf_brk) elf_brk = k;		     
+			if (k > elf_brk)
+				elf_brk = k;
 		}
 	}
 	set_fs(old_fs);
 
 	if (elf_interpreter) {
-		if (interpreter_type & 1) 
+		if (interpreter_type & 1)
 			elf_entry = load_aout_interp(&interp_ex,
 						     interpreter_inode);
-		else if (interpreter_type & 2) 
-			elf_entry = load_elf_interp(&interp_elf_ex, 
-						    interpreter_inode, 
+		else if (interpreter_type & 2)
+			elf_entry = load_elf_interp(&interp_elf_ex,
+						    interpreter_inode,
 						    &interp_load_addr);
 
 		iput(interpreter_inode);
 		kfree(elf_interpreter);
-			
-		if (elf_entry == ~0UL) { 
+
+		if (elf_entry == ~0UL) {
 			printk("Unable to load interpreter\n");
 			kfree(elf_phdata);
 			send_sig(SIGSEGV, current, 0);
 			return 0;
 		}
 	}
-
 	kfree(elf_phdata);
-	
-	if (interpreter_type != INTERPRETER_AOUT) sys_close(elf_exec_fileno);
+
+	if (interpreter_type != INTERPRETER_AOUT)
+		sys_close(elf_exec_fileno);
 	current->personality = (ibcs2_interpreter ? PER_SVR4 : PER_LINUX);
 
 	if (current->exec_domain && current->exec_domain->use_count)
@@ -662,16 +665,16 @@
 	current->suid = current->euid = current->fsuid = bprm->e_uid;
 	current->sgid = current->egid = current->fsgid = bprm->e_gid;
 	current->flags &= ~PF_FORKNOEXEC;
-	bprm->p = (unsigned long) 
-	  create_elf_tables((char *)bprm->p,
-			bprm->argc,
-			bprm->envc,
-			(interpreter_type == INTERPRETER_ELF ? &elf_ex : NULL),
-			load_addr,
-			interp_load_addr,
-			(interpreter_type == INTERPRETER_AOUT ? 0 : 1));
+	bprm->p = (unsigned long)
+	    create_elf_tables((char *) bprm->p,
+			      bprm->argc,
+			      bprm->envc,
+		  (interpreter_type == INTERPRETER_ELF ? &elf_ex : NULL),
+			      load_addr,
+			      interp_load_addr,
+			 (interpreter_type == INTERPRETER_AOUT ? 0 : 1));
 	if (interpreter_type == INTERPRETER_AOUT)
-	  current->mm->arg_start += strlen(passed_fileno) + 1;
+		current->mm->arg_start += strlen(passed_fileno) + 1;
 	current->mm->start_brk = current->mm->brk = elf_brk;
 	current->mm->end_code = end_code;
 	current->mm->start_code = start_code;
@@ -685,16 +688,15 @@
 	padzero(elf_bss);
 
 #if 0
-	printk("(start_brk) %x\n" , current->mm->start_brk);
-	printk("(end_code) %x\n" , current->mm->end_code);
-	printk("(start_code) %x\n" , current->mm->start_code);
-	printk("(end_data) %x\n" , current->mm->end_data);
-	printk("(start_stack) %x\n" , current->mm->start_stack);
-	printk("(brk) %x\n" , current->mm->brk);
+	printk("(start_brk) %x\n", current->mm->start_brk);
+	printk("(end_code) %x\n", current->mm->end_code);
+	printk("(start_code) %x\n", current->mm->start_code);
+	printk("(end_data) %x\n", current->mm->end_data);
+	printk("(start_stack) %x\n", current->mm->start_stack);
+	printk("(brk) %x\n", current->mm->brk);
 #endif
 
-	if ( current->personality == PER_SVR4 )
-	{
+	if (current->personality == PER_SVR4) {
 		/* Why this, you ask???  Well SVr4 maps page 0 as read-only,
 		   and some applications "depend" upon this behavior.
 		   Since we do not have the power to recompile these, we
@@ -702,7 +704,6 @@
 		error = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE, 0);
 	}
-
 #ifdef ELF_PLAT_INIT
 	/*
 	 * The ABI may specify that certain registers be set up in special
@@ -720,8 +721,7 @@
 	return 0;
 }
 
-static int
-load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
+static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 {
 	int retval;
 
@@ -734,24 +734,24 @@
 /* This is really simpleminded and specialized - we are loading an
    a.out library that is given an ELF header. */
 
-static inline int
-do_load_elf_library(int fd){
-	struct file * file;
+static inline int do_load_elf_library(int fd)
+{
+	struct file *file;
 	struct elfhdr elf_ex;
-	struct elf_phdr *elf_phdata  =  NULL;
-	struct  inode * inode;
+	struct elf_phdr *elf_phdata = NULL;
+	struct inode *inode;
 	unsigned long len;
 	int elf_bss;
 	int retval;
 	unsigned long bss;
 	int error;
-	int i,j, k;
+	int i, j, k;
 
 	len = 0;
 	file = current->files->fd[fd];
 	inode = file->f_inode;
 	elf_bss = 0;
-	
+
 	if (!file || !file->f_op)
 		return -EACCES;
 
@@ -769,39 +769,40 @@
 		return -ENOEXEC;
 
 	if (elf_ex.e_ident[0] != 0x7f ||
-	    strncmp(&elf_ex.e_ident[1], "ELF",3) != 0)
+	    strncmp(&elf_ex.e_ident[1], "ELF", 3) != 0)
 		return -ENOEXEC;
 
 	/* First of all, some simple consistency checks */
 	if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
-	   !elf_check_arch(elf_ex.e_machine) ||
-	   (!inode->i_op || !inode->i_op->default_file_ops->mmap))
+	    !elf_check_arch(elf_ex.e_machine) ||
+	    (!inode->i_op || !inode->i_op->default_file_ops->mmap))
 		return -ENOEXEC;
-	
+
 	/* Now read in all of the header information */
-	
+
 	if (sizeof(struct elf_phdr) * elf_ex.e_phnum > PAGE_SIZE)
-		return -ENOEXEC;
-	
-	elf_phdata =  (struct elf_phdr *) 
-		kmalloc(sizeof(struct elf_phdr) * elf_ex.e_phnum, GFP_KERNEL);
+		 return -ENOEXEC;
+
+	elf_phdata = (struct elf_phdr *)
+	    kmalloc(sizeof(struct elf_phdr) * elf_ex.e_phnum, GFP_KERNEL);
 	if (elf_phdata == NULL)
 		return -ENOMEM;
-	
+
 	retval = read_exec(inode, elf_ex.e_phoff, (char *) elf_phdata,
 			   sizeof(struct elf_phdr) * elf_ex.e_phnum, 1);
-	
+
 	j = 0;
-	for(i=0; i<elf_ex.e_phnum; i++)
-		if ((elf_phdata + i)->p_type == PT_LOAD) j++;
-	
-	if (j != 1)  {
+	for (i = 0; i < elf_ex.e_phnum; i++)
+		if ((elf_phdata + i)->p_type == PT_LOAD)
+			j++;
+
+	if (j != 1) {
 		kfree(elf_phdata);
 		return -ENOEXEC;
 	}
-	
-	while(elf_phdata->p_type != PT_LOAD) elf_phdata++;
-	
+	while (elf_phdata->p_type != PT_LOAD)
+		elf_phdata++;
+
 	/* Now use mmap to map the library into memory. */
 	error = do_mmap(file,
 			ELF_PAGESTART(elf_phdata->p_vaddr),
@@ -813,21 +814,21 @@
 			 ELF_PAGEOFFSET(elf_phdata->p_vaddr)));
 
 	k = elf_phdata->p_vaddr + elf_phdata->p_filesz;
-	if (k > elf_bss) elf_bss = k;
-	
+	if (k > elf_bss)
+		elf_bss = k;
+
 	if (error != ELF_PAGESTART(elf_phdata->p_vaddr)) {
 		kfree(elf_phdata);
 		return error;
 	}
-
 	padzero(elf_bss);
 
-	len = ELF_PAGESTART(elf_phdata->p_filesz + elf_phdata->p_vaddr+ ELF_EXEC_PAGESIZE - 1);
+	len = ELF_PAGESTART(elf_phdata->p_filesz + elf_phdata->p_vaddr + ELF_EXEC_PAGESIZE - 1);
 	bss = elf_phdata->p_memsz + elf_phdata->p_vaddr;
 	if (bss > len)
-	  do_mmap(NULL, len, bss-len,
-		  PROT_READ|PROT_WRITE|PROT_EXEC,
-		  MAP_FIXED|MAP_PRIVATE, 0);
+		do_mmap(NULL, len, bss - len,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE, 0);
 	kfree(elf_phdata);
 	return 0;
 }
@@ -882,12 +883,12 @@
  */
 static inline int maydump(struct vm_area_struct *vma)
 {
-	if (!(vma->vm_flags & (VM_READ|VM_EXEC)))
+	if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
 		return 0;
 #if 1
-	if (vma->vm_flags & (VM_WRITE|VM_GROWSUP|VM_GROWSDOWN))
+	if (vma->vm_flags & (VM_WRITE | VM_GROWSUP | VM_GROWSDOWN))
 		return 1;
-	if (vma->vm_flags & (VM_READ|VM_EXEC|VM_EXECUTABLE|VM_SHARED))
+	if (vma->vm_flags & (VM_READ | VM_EXEC | VM_EXECUTABLE | VM_SHARED))
 		return 0;
 #endif
 	return 1;
@@ -896,8 +897,7 @@
 #define roundup(x, y)  ((((x)+((y)-1))/(y))*(y))
 
 /* An ELF note in memory */
-struct memelfnote
-{
+struct memelfnote {
 	const char *name;
 	int type;
 	unsigned int datasz;
@@ -907,32 +907,33 @@
 static int notesize(struct memelfnote *en)
 {
 	int sz;
-	
+
 	sz = sizeof(struct elf_note);
 	sz += roundup(strlen(en->name), 4);
 	sz += roundup(en->datasz, 4);
-	
+
 	return sz;
 }
 
 /* #define DEBUG */
 
 #ifdef DEBUG
-static void dump_regs(const char *str, elf_greg_t *r)
+static void dump_regs(const char *str, elf_greg_t * r)
 {
 	int i;
-	static const char *regs[] = { "ebx", "ecx", "edx", "esi", "edi", "ebp",
-					      "eax", "ds", "es", "fs", "gs",
-					      "orig_eax", "eip", "cs",
-					      "efl", "uesp", "ss"};
+	static const char *regs[] =
+	{"ebx", "ecx", "edx", "esi", "edi", "ebp",
+	 "eax", "ds", "es", "fs", "gs",
+	 "orig_eax", "eip", "cs",
+	 "efl", "uesp", "ss"};
 	printk("Registers: %s\n", str);
 
-	for(i = 0; i < ELF_NGREG; i++)
-	{
+	for (i = 0; i < ELF_NGREG; i++) {
 		unsigned long val = r[i];
 		printk("   %-2d %-5s=%08lx %lu\n", i, regs[i], val, val);
 	}
 }
+
 #endif
 
 #define DUMP_WRITE(addr, nr)	\
@@ -951,10 +952,10 @@
 	DUMP_WRITE(&en, sizeof(en));
 	DUMP_WRITE(men->name, en.n_namesz);
 	/* XXX - cast from long long to long to avoid need for libgcc.a */
-	DUMP_SEEK(roundup((unsigned long)file->f_pos, 4));	/* XXX */
+	DUMP_SEEK(roundup((unsigned long) file->f_pos, 4));	/* XXX */
 	DUMP_WRITE(men->data, men->datasz);
-	DUMP_SEEK(roundup((unsigned long)file->f_pos, 4));	/* XXX */
-	
+	DUMP_SEEK(roundup((unsigned long) file->f_pos, 4));	/* XXX */
+
 	return 1;
 }
 #undef DUMP_WRITE
@@ -973,13 +974,13 @@
  * and then they are actually written out.  If we run out of core limit
  * we just truncate.
  */
-static int elf_core_dump(long signr, struct pt_regs * regs)
+static int elf_core_dump(long signr, struct pt_regs *regs)
 {
 	int has_dumped = 0;
 	struct file file;
 	struct inode *inode;
 	unsigned short fs;
-	char corefile[6+sizeof(current->comm)];
+	char corefile[6 + sizeof(current->comm)];
 	int segs;
 	int i;
 	size_t size;
@@ -990,9 +991,9 @@
 	int numnote = 4;
 	struct memelfnote notes[4];
 	struct elf_prstatus prstatus;	/* NT_PRSTATUS */
-	elf_fpregset_t fpu;		/* NT_PRFPREG */
+	elf_fpregset_t fpu;	/* NT_PRFPREG */
 	struct elf_prpsinfo psinfo;	/* NT_PRPSINFO */
-	
+
 	if (!current->dumpable || limit < PAGE_SIZE || current->mm->count != 1)
 		return 0;
 	current->dumpable = 0;
@@ -1004,17 +1005,15 @@
 	/* Count what's needed to dump, up to the limit of coredump size */
 	segs = 0;
 	size = 0;
-	for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
-		if (maydump(vma))
-		{
-			int sz = vma->vm_end-vma->vm_start;
-		
-			if (size+sz >= limit)
+	for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
+		if (maydump(vma)) {
+			int sz = vma->vm_end - vma->vm_start;
+
+			if (size + sz >= limit)
 				break;
 			else
 				size += sz;
 		}
-		
 		segs++;
 	}
 #ifdef DEBUG
@@ -1026,8 +1025,8 @@
 	elf.e_ident[EI_CLASS] = ELF_CLASS;
 	elf.e_ident[EI_DATA] = ELF_DATA;
 	elf.e_ident[EI_VERSION] = EV_CURRENT;
-	memset(elf.e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
-	
+	memset(elf.e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
+
 	elf.e_type = ET_CORE;
 	elf.e_machine = ELF_ARCH;
 	elf.e_version = EV_CURRENT;
@@ -1037,20 +1036,20 @@
 	elf.e_flags = 0;
 	elf.e_ehsize = sizeof(elf);
 	elf.e_phentsize = sizeof(struct elf_phdr);
-	elf.e_phnum = segs+1;		/* Include notes */
+	elf.e_phnum = segs + 1;	/* Include notes */
 	elf.e_shentsize = 0;
 	elf.e_shnum = 0;
 	elf.e_shstrndx = 0;
-	
+
 	fs = get_fs();
 	set_fs(KERNEL_DS);
-	memcpy(corefile,"core.",5);
+	memcpy(corefile, "core.", 5);
 #if 0
-	memcpy(corefile+5,current->comm,sizeof(current->comm));
+	memcpy(corefile + 5, current->comm, sizeof(current->comm));
 #else
 	corefile[4] = '\0';
 #endif
-	if (open_namei(corefile,O_CREAT | 2 | O_TRUNC,0600,&inode,NULL)) {
+	if (open_namei(corefile, O_CREAT | 2 | O_TRUNC, 0600, &inode, NULL)) {
 		inode = NULL;
 		goto end_coredump;
 	}
@@ -1066,7 +1065,7 @@
 	file.f_reada = 0;
 	file.f_op = inode->i_op->default_file_ops;
 	if (file.f_op->open)
-		if (file.f_op->open(inode,&file))
+		if (file.f_op->open(inode, &file))
 			goto end_coredump;
 	if (!file.f_op->write)
 		goto close_coredump;
@@ -1074,8 +1073,8 @@
 	current->flags |= PF_DUMPCORE;
 
 	DUMP_WRITE(&elf, sizeof(elf));
-	offset += sizeof(elf);				/* Elf header */
-	offset += (segs+1) * sizeof(struct elf_phdr);	/* Program headers */
+	offset += sizeof(elf);	/* Elf header */
+	offset += (segs + 1) * sizeof(struct elf_phdr);		/* Program headers */
 
 	/*
 	 * Set up the notes in similar form to SVR4 core dumps made
@@ -1111,18 +1110,16 @@
 #ifdef ELF_CORE_COPY_REGS
 	ELF_CORE_COPY_REGS(prstatus.pr_reg, regs)
 #else
-	if (sizeof(elf_gregset_t) != sizeof(struct pt_regs))
-	{
+	if (sizeof(elf_gregset_t) != sizeof(struct pt_regs)) {
 		printk("sizeof(elf_gregset_t) (%d) != sizeof(struct pt_regs) (%d)\n",
-			sizeof(elf_gregset_t), sizeof(struct pt_regs));
-	}
-	else
-		*(struct pt_regs *)&prstatus.pr_reg = *regs;
+		       sizeof(elf_gregset_t), sizeof(struct pt_regs));
+	} else
+		*(struct pt_regs *) &prstatus.pr_reg = *regs;
 #endif
-	
+
 #ifdef DEBUG
-	dump_regs("Passed in regs", (elf_greg_t *)regs);
-	dump_regs("prstatus regs", (elf_greg_t *)&prstatus.pr_reg);
+	dump_regs("Passed in regs", (elf_greg_t *) regs);
+	dump_regs("prstatus regs", (elf_greg_t *) & prstatus.pr_reg);
 #endif
 
 	notes[1].name = "CORE";
@@ -1132,7 +1129,7 @@
 	psinfo.pr_state = current->state;
 	psinfo.pr_sname = (current->state < 0 || current->state > 5) ? '.' : "RSDZTD"[current->state];
 	psinfo.pr_zomb = psinfo.pr_sname == 'Z';
-	psinfo.pr_nice = current->priority-15;
+	psinfo.pr_nice = current->priority - 15;
 	psinfo.pr_flag = current->flags;
 	psinfo.pr_uid = current->uid;
 	psinfo.pr_gid = current->gid;
@@ -1140,12 +1137,12 @@
 		int i, len;
 
 		set_fs(fs);
-		
+
 		len = current->mm->arg_end - current->mm->arg_start;
-		len = (len >= ELF_PRARGSZ-1) ? ELF_PRARGSZ-1 : len;
+		len = (len >= ELF_PRARGSZ - 1) ? ELF_PRARGSZ - 1 : len;
 		memcpy_fromfs(&psinfo.pr_psargs,
-			      (const char *)current->mm->arg_start, len);
-		for(i = 0; i < len; i++)
+			      (const char *) current->mm->arg_start, len);
+		for (i = 0; i < len; i++)
 			if (psinfo.pr_psargs[i] == 0)
 				psinfo.pr_psargs[i] = ' ';
 		psinfo.pr_psargs[len] = 0;
@@ -1158,29 +1155,26 @@
 	notes[2].type = NT_TASKSTRUCT;
 	notes[2].datasz = sizeof(*current);
 	notes[2].data = current;
-	
+
 	/* Try to dump the fpu. */
-	prstatus.pr_fpvalid = dump_fpu (regs, &fpu);
-	if (!prstatus.pr_fpvalid)
-	{
+	prstatus.pr_fpvalid = dump_fpu(regs, &fpu);
+	if (!prstatus.pr_fpvalid) {
 		numnote--;
-	}
-	else
-	{
+	} else {
 		notes[3].name = "CORE";
 		notes[3].type = NT_PRFPREG;
 		notes[3].datasz = sizeof(fpu);
 		notes[3].data = &fpu;
 	}
-	
+
 	/* Write notes phdr entry */
 	{
 		struct elf_phdr phdr;
 		int sz = 0;
 
-		for(i = 0; i < numnote; i++)
+		for (i = 0; i < numnote; i++)
 			sz += notesize(&notes[i]);
-		
+
 		phdr.p_type = PT_NOTE;
 		phdr.p_offset = offset;
 		phdr.p_vaddr = 0;
@@ -1196,17 +1190,17 @@
 
 	/* Page-align dumped data */
 	dataoff = offset = roundup(offset, PAGE_SIZE);
-	
+
 	/* Write program headers for segments dump */
-	for(vma = current->mm->mmap, i = 0;
-		i < segs && vma != NULL; vma = vma->vm_next) {
+	for (vma = current->mm->mmap, i = 0;
+	     i < segs && vma != NULL; vma = vma->vm_next) {
 		struct elf_phdr phdr;
 		size_t sz;
 
 		i++;
 
 		sz = vma->vm_end - vma->vm_start;
-		
+
 		phdr.p_type = PT_LOAD;
 		phdr.p_offset = offset;
 		phdr.p_vaddr = vma->vm_start;
@@ -1215,34 +1209,36 @@
 		phdr.p_memsz = sz;
 		offset += phdr.p_filesz;
 		phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
-		if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W;
-		if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X;
+		if (vma->vm_flags & VM_WRITE)
+			phdr.p_flags |= PF_W;
+		if (vma->vm_flags & VM_EXEC)
+			phdr.p_flags |= PF_X;
 		phdr.p_align = PAGE_SIZE;
 
 		DUMP_WRITE(&phdr, sizeof(phdr));
 	}
 
-	for(i = 0; i < numnote; i++)
+	for (i = 0; i < numnote; i++)
 		if (!writenote(&notes[i], &file))
 			goto close_coredump;
-	
+
 	set_fs(fs);
 
 	DUMP_SEEK(dataoff);
-	
-	for(i = 0, vma = current->mm->mmap;
-	    i < segs && vma != NULL;
-	    vma = vma->vm_next) {
+
+	for (i = 0, vma = current->mm->mmap;
+	     i < segs && vma != NULL;
+	     vma = vma->vm_next) {
 		unsigned long addr = vma->vm_start;
 		unsigned long len = vma->vm_end - vma->vm_start;
-		
+
 		i++;
 		if (!maydump(vma))
 			continue;
 #ifdef DEBUG
 		printk("elf_core_dump: writing %08lx %lx\n", addr, len);
 #endif
-		DUMP_WRITE((void *)addr, len);
+		DUMP_WRITE((void *) addr, len);
 	}
 
 	if ((off_t) file.f_pos != offset) {
@@ -1250,12 +1246,11 @@
 		printk("elf_core_dump: file.f_pos (%ld) != offset (%ld)\n",
 		       (off_t) file.f_pos, offset);
 	}
-
- close_coredump:
+      close_coredump:
 	if (file.f_op->release)
-		file.f_op->release(inode,&file);
+		file.f_op->release(inode, &file);
 
- end_coredump:
+      end_coredump:
 	set_fs(fs);
 	iput(inode);
 #ifndef CONFIG_BINFMT_ELF
@@ -1263,16 +1258,16 @@
 #endif
 	return has_dumped;
 }
-#endif		/* USE_ELF_CORE_DUMP */
+#endif				/* USE_ELF_CORE_DUMP */
 
-int init_elf_binfmt(void) 
+int init_elf_binfmt(void)
 {
 	return register_binfmt(&elf_format);
 }
 
 #ifdef MODULE
 
-int init_module(void) 
+int init_module(void)
 {
 	/* Install the COFF, ELF and XOUT loaders.
 	 * N.B. We *rely* on the table being the right size with the
@@ -1282,9 +1277,10 @@
 }
 
 
-void cleanup_module( void) 
+void cleanup_module(void)
 {
 	/* Remove the COFF and ELF loaders. */
 	unregister_binfmt(&elf_format);
 }
+
 #endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov