aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
authorJames Morris <jmorris@namei.org>2009-05-22 04:40:59 -0400
committerJames Morris <jmorris@namei.org>2009-05-22 04:40:59 -0400
commit2c9e703c618106f5383226fbb1f526cb11034f8a (patch)
tree87d7548001ea82f655fede0640466fc16aabcdf7 /fs/exec.c
parent6470c077cae12227318f40f3e6d756caadcce4b0 (diff)
parent5805977e63a36ad56594a623f3bd2bebcb7db233 (diff)
Merge branch 'master' into next
Conflicts: fs/exec.c Removed IMA changes (the IMA checks are now performed via may_open()). Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c80
1 files changed, 25 insertions, 55 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 618d6d1e2c52..a7fcd975c6b2 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -105,41 +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 = 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 IMA_COUNT_UPDATE);
135 if (error)
136 goto exit; 128 goto exit;
137 129
138 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
139 error = PTR_ERR(file);
140 if (IS_ERR(file))
141 goto out;
142
143 fsnotify_open(file->f_path.dentry); 130 fsnotify_open(file->f_path.dentry);
144 131
145 error = -ENOEXEC; 132 error = -ENOEXEC;
@@ -161,13 +148,10 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
161 } 148 }
162 read_unlock(&binfmt_lock); 149 read_unlock(&binfmt_lock);
163 } 150 }
151exit:
164 fput(file); 152 fput(file);
165out: 153out:
166 return error; 154 return error;
167exit:
168 release_open_intent(&nd);
169 path_put(&nd.path);
170 goto out;
171} 155}
172 156
173#ifdef CONFIG_MMU 157#ifdef CONFIG_MMU
@@ -662,47 +646,33 @@ EXPORT_SYMBOL(setup_arg_pages);
662 646
663struct file *open_exec(const char *name) 647struct file *open_exec(const char *name)
664{ 648{
665 struct nameidata nd;
666 struct file *file; 649 struct file *file;
667 int err; 650 int err;
668 651
669 err = path_lookup_open(AT_FDCWD, name, LOOKUP_FOLLOW, &nd, 652 file = do_filp_open(AT_FDCWD, name,
670 FMODE_READ|FMODE_EXEC); 653 O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
671 if (err) 654 MAY_EXEC | MAY_OPEN);
655 if (IS_ERR(file))
672 goto out; 656 goto out;
673 657
674 err = -EACCES; 658 err = -EACCES;
675 if (!S_ISREG(nd.path.dentry->d_inode->i_mode)) 659 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
676 goto out_path_put; 660 goto exit;
677
678 if (nd.path.mnt->mnt_flags & MNT_NOEXEC)
679 goto out_path_put;
680
681 err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN);
682 if (err)
683 goto out_path_put;
684 err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN, IMA_COUNT_UPDATE);
685 if (err)
686 goto out_path_put;
687 661
688 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 662 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
689 if (IS_ERR(file)) 663 goto exit;
690 return file;
691 664
692 fsnotify_open(file->f_path.dentry); 665 fsnotify_open(file->f_path.dentry);
693 666
694 err = deny_write_access(file); 667 err = deny_write_access(file);
695 if (err) { 668 if (err)
696 fput(file); 669 goto exit;
697 goto out;
698 }
699 670
671out:
700 return file; 672 return file;
701 673
702 out_path_put: 674exit:
703 release_open_intent(&nd); 675 fput(file);
704 path_put(&nd.path);
705 out:
706 return ERR_PTR(err); 676 return ERR_PTR(err);
707} 677}
708EXPORT_SYMBOL(open_exec); 678EXPORT_SYMBOL(open_exec);