diff options
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 72 |
1 files changed, 25 insertions, 47 deletions
@@ -105,36 +105,28 @@ static inline void put_binfmt(struct linux_binfmt * fmt) | |||
105 | SYSCALL_DEFINE1(uselib, const char __user *, library) | 105 | SYSCALL_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 | } |
151 | exit: | ||
159 | fput(file); | 152 | fput(file); |
160 | out: | 153 | out: |
161 | return error; | 154 | return error; |
162 | exit: | ||
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 | ||
658 | struct file *open_exec(const char *name) | 647 | struct 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 | ||
671 | out: | ||
692 | return file; | 672 | return file; |
693 | 673 | ||
694 | out_path_put: | 674 | exit: |
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 | } |
700 | EXPORT_SYMBOL(open_exec); | 678 | EXPORT_SYMBOL(open_exec); |