summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1999-06-27 08:45:08 +0000
committerRalf Baechle <ralf@linux-mips.org>1999-06-27 08:45:08 +0000
commitd9f906342c606d2633608c88781ee0f8ec2d0c0b (patch)
tree3f3ce2a49909927d603761e04c60cd1403787031 /arch
parentc8d701be3840f92e6459dabd99c9ca5d9b46a09f (diff)
Dito for mainstream.
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/kernel/irixelf.c94
1 files changed, 48 insertions, 46 deletions
diff --git a/arch/mips/kernel/irixelf.c b/arch/mips/kernel/irixelf.c
index 8c55d335e..0983a1b6a 100644
--- a/arch/mips/kernel/irixelf.c
+++ b/arch/mips/kernel/irixelf.c
@@ -1,4 +1,4 @@
-/* $Id: irixelf.c,v 1.16.2.2 1999/06/14 21:40:54 ralf Exp $
+/* $Id: irixelf.c,v 1.17 1999/06/17 13:25:45 ralf Exp $
*
* irixelf.c: Code to load IRIX ELF executables which conform to
* the MIPS ABI.
@@ -308,7 +308,7 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
return 0xffffffff;
}
- file = current->files->fd[elf_exec_fileno];
+ file = fget(elf_exec_fileno);
eppnt = elf_phdata;
for(i=0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
@@ -366,6 +366,7 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
}
/* Now use mmap to map the library into memory. */
+ fput(file);
sys_close(elf_exec_fileno);
if(error < 0 && error > -1024) {
#ifdef DEBUG_ELF
@@ -615,6 +616,7 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
unsigned int start_code, end_code, end_data, elf_stack;
int elf_exec_fileno, retval, has_interp, has_ephdr, size, i;
char *elf_interpreter;
+ struct file *file;
mm_segment_t old_fs;
load_addr = 0;
@@ -637,10 +639,8 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
retval = read_exec(bprm->dentry, elf_ex.e_phoff,
(char *) elf_phdata, size, 1);
- if (retval < 0) {
- kfree (elf_phdata);
- return retval;
- }
+ if (retval < 0)
+ goto out_phdata;
#ifdef DEBUG_ELF
dump_phdrs(elf_phdata, elf_ex.e_phnum);
@@ -665,12 +665,10 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
elf_bss = 0;
elf_brk = 0;
- elf_exec_fileno = open_dentry(bprm->dentry, O_RDONLY);
-
- if (elf_exec_fileno < 0) {
- kfree (elf_phdata);
- return elf_exec_fileno;
- }
+ retval = open_dentry(bprm->dentry, O_RDONLY);
+ if (retval < 0)
+ goto out_phdata;
+ file = fget(elf_exec_fileno = retval);
elf_stack = 0xffffffff;
elf_interpreter = NULL;
@@ -682,40 +680,26 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
&interpreter_dentry,
&interp_elf_ex, elf_phdata, bprm,
elf_ex.e_phnum);
- if(retval) {
- kfree(elf_phdata);
- sys_close(elf_exec_fileno);
- return retval;
- }
+ if(retval)
+ goto out_file;
if(elf_interpreter) {
retval = verify_irix_interpreter(&interp_elf_ex);
- if(retval) {
- kfree(elf_interpreter);
- kfree(elf_phdata);
- sys_close(elf_exec_fileno);
- return retval;
- }
+ if(retval)
+ goto out_interp;
}
/* OK, we are done with that, now set up the arg stuff,
* and then start this sucker up.
*/
- if (!bprm->sh_bang) {
- if (!bprm->p) {
- if(elf_interpreter) {
- kfree(elf_interpreter);
- }
- kfree (elf_phdata);
- sys_close(elf_exec_fileno);
- return -E2BIG;
- }
- }
+ retval = -E2BIG;
+ if (!bprm->sh_bang && !bprm->p)
+ goto out_interp;
/* Flush all traces of the currently running executable */
retval = flush_old_exec(bprm);
if (retval)
- return retval;
+ goto out_interp;
/* OK, This is the point of no return */
current->mm->end_data = 0;
@@ -737,8 +721,7 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
old_fs = get_fs();
set_fs(get_ds());
- map_executable(current->files->fd[elf_exec_fileno], elf_phdata,
- elf_ex.e_phnum, &elf_stack, &load_addr,
+ map_executable(file, elf_phdata, elf_ex.e_phnum, &elf_stack, &load_addr,
&start_code, &elf_bss, &end_code, &end_data, &elf_brk);
if(elf_interpreter) {
@@ -758,6 +741,7 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
set_fs(old_fs);
kfree(elf_phdata);
+ fput(file);
sys_close(elf_exec_fileno);
current->personality = PER_IRIX32;
@@ -820,6 +804,17 @@ static inline int do_load_irix_binary(struct linux_binprm * bprm,
if (current->flags & PF_PTRACED)
send_sig(SIGTRAP, current, 0);
return 0;
+
+out_interp:
+ if(elf_interpreter) {
+ kfree(elf_interpreter);
+ }
+out_file:
+ fput(file);
+ sys_close(elf_exec_fileno);
+out_phdata:
+ kfree (elf_phdata);
+ return retval;
}
static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
@@ -835,9 +830,8 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
/* This is really simpleminded and specialized - we are loading an
* a.out library that is given an ELF header.
*/
-static inline int do_load_irix_library(int fd)
+static inline int do_load_irix_library(struct file *file)
{
- struct file * file;
struct elfhdr elf_ex;
struct elf_phdr *elf_phdata = NULL;
struct dentry *dentry;
@@ -850,14 +844,12 @@ static inline int do_load_irix_library(int fd)
int i,j, k;
len = 0;
- file = current->files->fd[fd];
+ if (!file->f_op)
+ return -EACCES;
dentry = file->f_dentry;
inode = dentry->d_inode;
elf_bss = 0;
- if (!file || !file->f_op)
- return -EACCES;
-
/* Seek to the beginning of the file. */
if (file->f_op->llseek) {
if ((error = file->f_op->llseek(file, 0, 0)) != 0)
@@ -934,10 +926,15 @@ static inline int do_load_irix_library(int fd)
static int load_irix_library(int fd)
{
- int retval;
+ int retval = -EACCES;
+ struct file *file;
MOD_INC_USE_COUNT;
- retval = do_load_irix_library(fd);
+ file = fget(fd);
+ if (file) {
+ retval = do_load_irix_library(file);
+ fput(file);
+ }
MOD_DEC_USE_COUNT;
return retval;
}
@@ -978,9 +975,12 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
return -ENOEXEC;
}
- filp = current->files->fd[fd];
- if(!filp || !filp->f_op) {
+ filp = fget(fd);
+ if (!filp)
+ return -EACCES;
+ if(!filp->f_op) {
printk("irix_mapelf: Bogon filp!\n");
+ fput(file);
return -EACCES;
}
@@ -998,6 +998,7 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
if(retval != (hp->p_vaddr & 0xfffff000)) {
printk("irix_mapelf: do_mmap fails with %d!\n", retval);
+ fput(file);
return retval;
}
}
@@ -1005,6 +1006,7 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
#ifdef DEBUG_ELF
printk("irix_mapelf: Success, returning %08lx\n", user_phdrp->p_vaddr);
#endif
+ fput(file);
return user_phdrp->p_vaddr;
}