aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 929b58004b7e..c5128fbc9165 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -45,6 +45,7 @@
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/mount.h> 46#include <linux/mount.h>
47#include <linux/security.h> 47#include <linux/security.h>
48#include <linux/ima.h>
48#include <linux/syscalls.h> 49#include <linux/syscalls.h>
49#include <linux/tsacct_kern.h> 50#include <linux/tsacct_kern.h>
50#include <linux/cn_proc.h> 51#include <linux/cn_proc.h>
@@ -127,6 +128,9 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
127 MAY_READ | MAY_EXEC | MAY_OPEN); 128 MAY_READ | MAY_EXEC | MAY_OPEN);
128 if (error) 129 if (error)
129 goto exit; 130 goto exit;
131 error = ima_path_check(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN);
132 if (error)
133 goto exit;
130 134
131 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 135 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
132 error = PTR_ERR(file); 136 error = PTR_ERR(file);
@@ -674,6 +678,9 @@ struct file *open_exec(const char *name)
674 err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN); 678 err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN);
675 if (err) 679 if (err)
676 goto out_path_put; 680 goto out_path_put;
681 err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN);
682 if (err)
683 goto out_path_put;
677 684
678 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 685 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
679 if (IS_ERR(file)) 686 if (IS_ERR(file))
@@ -1049,28 +1056,24 @@ EXPORT_SYMBOL(install_exec_creds);
1049 * - the caller must hold current->cred_exec_mutex to protect against 1056 * - the caller must hold current->cred_exec_mutex to protect against
1050 * PTRACE_ATTACH 1057 * PTRACE_ATTACH
1051 */ 1058 */
1052void check_unsafe_exec(struct linux_binprm *bprm, struct files_struct *files) 1059void check_unsafe_exec(struct linux_binprm *bprm)
1053{ 1060{
1054 struct task_struct *p = current, *t; 1061 struct task_struct *p = current, *t;
1055 unsigned long flags; 1062 unsigned long flags;
1056 unsigned n_fs, n_files, n_sighand; 1063 unsigned n_fs, n_sighand;
1057 1064
1058 bprm->unsafe = tracehook_unsafe_exec(p); 1065 bprm->unsafe = tracehook_unsafe_exec(p);
1059 1066
1060 n_fs = 1; 1067 n_fs = 1;
1061 n_files = 1;
1062 n_sighand = 1; 1068 n_sighand = 1;
1063 lock_task_sighand(p, &flags); 1069 lock_task_sighand(p, &flags);
1064 for (t = next_thread(p); t != p; t = next_thread(t)) { 1070 for (t = next_thread(p); t != p; t = next_thread(t)) {
1065 if (t->fs == p->fs) 1071 if (t->fs == p->fs)
1066 n_fs++; 1072 n_fs++;
1067 if (t->files == files)
1068 n_files++;
1069 n_sighand++; 1073 n_sighand++;
1070 } 1074 }
1071 1075
1072 if (atomic_read(&p->fs->count) > n_fs || 1076 if (atomic_read(&p->fs->count) > n_fs ||
1073 atomic_read(&p->files->count) > n_files ||
1074 atomic_read(&p->sighand->count) > n_sighand) 1077 atomic_read(&p->sighand->count) > n_sighand)
1075 bprm->unsafe |= LSM_UNSAFE_SHARE; 1078 bprm->unsafe |= LSM_UNSAFE_SHARE;
1076 1079
@@ -1184,6 +1187,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1184 retval = security_bprm_check(bprm); 1187 retval = security_bprm_check(bprm);
1185 if (retval) 1188 if (retval)
1186 return retval; 1189 return retval;
1190 retval = ima_bprm_check(bprm);
1191 if (retval)
1192 return retval;
1187 1193
1188 /* kernel module loader fixup */ 1194 /* kernel module loader fixup */
1189 /* so we don't try to load run modprobe in kernel space. */ 1195 /* so we don't try to load run modprobe in kernel space. */
@@ -1284,12 +1290,13 @@ int do_execve(char * filename,
1284 retval = mutex_lock_interruptible(&current->cred_exec_mutex); 1290 retval = mutex_lock_interruptible(&current->cred_exec_mutex);
1285 if (retval < 0) 1291 if (retval < 0)
1286 goto out_free; 1292 goto out_free;
1293 current->in_execve = 1;
1287 1294
1288 retval = -ENOMEM; 1295 retval = -ENOMEM;
1289 bprm->cred = prepare_exec_creds(); 1296 bprm->cred = prepare_exec_creds();
1290 if (!bprm->cred) 1297 if (!bprm->cred)
1291 goto out_unlock; 1298 goto out_unlock;
1292 check_unsafe_exec(bprm, displaced); 1299 check_unsafe_exec(bprm);
1293 1300
1294 file = open_exec(filename); 1301 file = open_exec(filename);
1295 retval = PTR_ERR(file); 1302 retval = PTR_ERR(file);
@@ -1337,6 +1344,7 @@ int do_execve(char * filename,
1337 goto out; 1344 goto out;
1338 1345
1339 /* execve succeeded */ 1346 /* execve succeeded */
1347 current->in_execve = 0;
1340 mutex_unlock(&current->cred_exec_mutex); 1348 mutex_unlock(&current->cred_exec_mutex);
1341 acct_update_integrals(current); 1349 acct_update_integrals(current);
1342 free_bprm(bprm); 1350 free_bprm(bprm);
@@ -1355,6 +1363,7 @@ out_file:
1355 } 1363 }
1356 1364
1357out_unlock: 1365out_unlock:
1366 current->in_execve = 0;
1358 mutex_unlock(&current->cred_exec_mutex); 1367 mutex_unlock(&current->cred_exec_mutex);
1359 1368
1360out_free: 1369out_free: