diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-05-10 13:49:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-05-10 13:49:08 -0400 |
commit | 93b49d45eb97574057ee03dfdd590c209f5132f8 (patch) | |
tree | d01e5af58331ab6a8c758e445aeb943cf803dfa9 /fs/exec.c | |
parent | f9f51cc0ce544224a8332a4c1733624fcbc70a32 (diff) | |
parent | b0c4f3222c7406f0aee9d52b7d604a1d36108463 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6: (22 commits)
Fix the race between capifs remount and node creation
Fix races around the access to ->s_options
switch ufs directories to ufs_sync_file()
Switch open_exec() and sys_uselib() to do_open_filp()
Make open_exec() and sys_uselib() use may_open(), instead of duplicating its parts
Reduce path_lookup() abuses
Make checkpatch.pl shut up on fs/inode.c
NULL noise in fs/super.c:kill_bdev_super()
romfs: cleanup romfs_fs.h
ROMFS: romfs_dev_read() error ignored
fs: dcache fix LRU ordering
ocfs2: Use nd_set_link().
Fix deadlock in ipathfs ->get_sb()
Fix a leak in failure exit in 9p ->get_sb()
Convert obvious places to deactivate_locked_super()
New helper: deactivate_locked_super()
reiserfs: remove privroot hiding in lookup
reiserfs: dont associate security.* with xattr files
reiserfs: fixup xattr_root caching
Always lookup priv_root on reiserfs mount and keep it
...
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 79 |
1 files changed, 25 insertions, 54 deletions
@@ -105,40 +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 = inode_permission(nd.path.dentry->d_inode, | ||
130 | MAY_READ | MAY_EXEC | MAY_OPEN); | ||
131 | if (error) | ||
132 | goto exit; | ||
133 | error = ima_path_check(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN); | ||
134 | if (error) | ||
135 | goto exit; | 128 | goto exit; |
136 | 129 | ||
137 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); | ||
138 | error = PTR_ERR(file); | ||
139 | if (IS_ERR(file)) | ||
140 | goto out; | ||
141 | |||
142 | fsnotify_open(file->f_path.dentry); | 130 | fsnotify_open(file->f_path.dentry); |
143 | 131 | ||
144 | error = -ENOEXEC; | 132 | error = -ENOEXEC; |
@@ -160,13 +148,10 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) | |||
160 | } | 148 | } |
161 | read_unlock(&binfmt_lock); | 149 | read_unlock(&binfmt_lock); |
162 | } | 150 | } |
151 | exit: | ||
163 | fput(file); | 152 | fput(file); |
164 | out: | 153 | out: |
165 | return error; | 154 | return error; |
166 | exit: | ||
167 | release_open_intent(&nd); | ||
168 | path_put(&nd.path); | ||
169 | goto out; | ||
170 | } | 155 | } |
171 | 156 | ||
172 | #ifdef CONFIG_MMU | 157 | #ifdef CONFIG_MMU |
@@ -661,47 +646,33 @@ EXPORT_SYMBOL(setup_arg_pages); | |||
661 | 646 | ||
662 | struct file *open_exec(const char *name) | 647 | struct file *open_exec(const char *name) |
663 | { | 648 | { |
664 | struct nameidata nd; | ||
665 | struct file *file; | 649 | struct file *file; |
666 | int err; | 650 | int err; |
667 | 651 | ||
668 | err = path_lookup_open(AT_FDCWD, name, LOOKUP_FOLLOW, &nd, | 652 | file = do_filp_open(AT_FDCWD, name, |
669 | FMODE_READ|FMODE_EXEC); | 653 | O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0, |
670 | if (err) | 654 | MAY_EXEC | MAY_OPEN); |
655 | if (IS_ERR(file)) | ||
671 | goto out; | 656 | goto out; |
672 | 657 | ||
673 | err = -EACCES; | 658 | err = -EACCES; |
674 | if (!S_ISREG(nd.path.dentry->d_inode->i_mode)) | 659 | if (!S_ISREG(file->f_path.dentry->d_inode->i_mode)) |
675 | goto out_path_put; | 660 | goto exit; |
676 | |||
677 | if (nd.path.mnt->mnt_flags & MNT_NOEXEC) | ||
678 | goto out_path_put; | ||
679 | |||
680 | err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN); | ||
681 | if (err) | ||
682 | goto out_path_put; | ||
683 | err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN); | ||
684 | if (err) | ||
685 | goto out_path_put; | ||
686 | 661 | ||
687 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); | 662 | if (file->f_path.mnt->mnt_flags & MNT_NOEXEC) |
688 | if (IS_ERR(file)) | 663 | goto exit; |
689 | return file; | ||
690 | 664 | ||
691 | fsnotify_open(file->f_path.dentry); | 665 | fsnotify_open(file->f_path.dentry); |
692 | 666 | ||
693 | err = deny_write_access(file); | 667 | err = deny_write_access(file); |
694 | if (err) { | 668 | if (err) |
695 | fput(file); | 669 | goto exit; |
696 | goto out; | ||
697 | } | ||
698 | 670 | ||
671 | out: | ||
699 | return file; | 672 | return file; |
700 | 673 | ||
701 | out_path_put: | 674 | exit: |
702 | release_open_intent(&nd); | 675 | fput(file); |
703 | path_put(&nd.path); | ||
704 | out: | ||
705 | return ERR_PTR(err); | 676 | return ERR_PTR(err); |
706 | } | 677 | } |
707 | EXPORT_SYMBOL(open_exec); | 678 | EXPORT_SYMBOL(open_exec); |