aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2009-04-06 11:16:22 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2009-05-09 10:49:42 -0400
commit6e8341a11eb21826b7192d0bb88cb5b44900a9af (patch)
treef9e03050f0834c2c4a21f1e6a255b6b0d1262b25 /fs/exec.c
parenta44ddbb6d8a8ffe4e34e417048dfdd8f3dd1de4f (diff)
Switch open_exec() and sys_uselib() to do_open_filp()
... and make path_lookup_open() static Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c72
1 files changed, 25 insertions, 47 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 41ae8e0de72..895823d0149 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -105,36 +105,28 @@ static inline void put_binfmt(struct linux_binfmt * fmt)
105SYSCALL_DEFINE1(uselib, const char __user *, library) 105SYSCALL_DEFINE1(uselib, const char __user *, library)
106{ 106{
107 struct file *file; 107 struct file *file;
108 struct nameidata nd;
109 char *tmp = getname(library); 108 char *tmp = getname(library);
110 int error = PTR_ERR(tmp); 109 int error = PTR_ERR(tmp);
111 110
112 if (!IS_ERR(tmp)) { 111 if (IS_ERR(tmp))
113 error = path_lookup_open(AT_FDCWD, tmp, 112 goto out;
114 LOOKUP_FOLLOW, &nd, 113
115 FMODE_READ|FMODE_EXEC); 114 file = do_filp_open(AT_FDCWD, tmp,
116 putname(tmp); 115 O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
117 } 116 MAY_READ | MAY_EXEC | MAY_OPEN);
118 if (error) 117 putname(tmp);
118 error = PTR_ERR(file);
119 if (IS_ERR(file))
119 goto out; 120 goto out;
120 121
121 error = -EINVAL; 122 error = -EINVAL;
122 if (!S_ISREG(nd.path.dentry->d_inode->i_mode)) 123 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
123 goto exit; 124 goto exit;
124 125
125 error = -EACCES; 126 error = -EACCES;
126 if (nd.path.mnt->mnt_flags & MNT_NOEXEC) 127 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
127 goto exit;
128
129 error = may_open(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN, 0);
130 if (error)
131 goto exit; 128 goto exit;
132 129
133 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
134 error = PTR_ERR(file);
135 if (IS_ERR(file))
136 goto out;
137
138 fsnotify_open(file->f_path.dentry); 130 fsnotify_open(file->f_path.dentry);
139 131
140 error = -ENOEXEC; 132 error = -ENOEXEC;
@@ -156,13 +148,10 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
156 } 148 }
157 read_unlock(&binfmt_lock); 149 read_unlock(&binfmt_lock);
158 } 150 }
151exit:
159 fput(file); 152 fput(file);
160out: 153out:
161 return error; 154 return error;
162exit:
163 release_open_intent(&nd);
164 path_put(&nd.path);
165 goto out;
166} 155}
167 156
168#ifdef CONFIG_MMU 157#ifdef CONFIG_MMU
@@ -657,44 +646,33 @@ EXPORT_SYMBOL(setup_arg_pages);
657 646
658struct file *open_exec(const char *name) 647struct file *open_exec(const char *name)
659{ 648{
660 struct nameidata nd;
661 struct file *file; 649 struct file *file;
662 int err; 650 int err;
663 651
664 err = path_lookup_open(AT_FDCWD, name, LOOKUP_FOLLOW, &nd, 652 file = do_filp_open(AT_FDCWD, name,
665 FMODE_READ|FMODE_EXEC); 653 O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
666 if (err) 654 MAY_EXEC | MAY_OPEN);
655 if (IS_ERR(file))
667 goto out; 656 goto out;
668 657
669 err = -EACCES; 658 err = -EACCES;
670 if (!S_ISREG(nd.path.dentry->d_inode->i_mode)) 659 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
671 goto out_path_put; 660 goto exit;
672
673 if (nd.path.mnt->mnt_flags & MNT_NOEXEC)
674 goto out_path_put;
675
676 err = may_open(&nd.path, MAY_EXEC | MAY_OPEN, 0);
677 if (err)
678 goto out_path_put;
679 661
680 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 662 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
681 if (IS_ERR(file)) 663 goto exit;
682 return file;
683 664
684 fsnotify_open(file->f_path.dentry); 665 fsnotify_open(file->f_path.dentry);
685 666
686 err = deny_write_access(file); 667 err = deny_write_access(file);
687 if (err) { 668 if (err)
688 fput(file); 669 goto exit;
689 goto out;
690 }
691 670
671out:
692 return file; 672 return file;
693 673
694 out_path_put: 674exit:
695 release_open_intent(&nd); 675 fput(file);
696 path_put(&nd.path);
697 out:
698 return ERR_PTR(err); 676 return ERR_PTR(err);
699} 677}
700EXPORT_SYMBOL(open_exec); 678EXPORT_SYMBOL(open_exec);