diff options
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -53,6 +53,7 @@ | |||
53 | #include <linux/tracehook.h> | 53 | #include <linux/tracehook.h> |
54 | #include <linux/kmod.h> | 54 | #include <linux/kmod.h> |
55 | #include <linux/fsnotify.h> | 55 | #include <linux/fsnotify.h> |
56 | #include <linux/fs_struct.h> | ||
56 | 57 | ||
57 | #include <asm/uaccess.h> | 58 | #include <asm/uaccess.h> |
58 | #include <asm/mmu_context.h> | 59 | #include <asm/mmu_context.h> |
@@ -1056,28 +1057,35 @@ EXPORT_SYMBOL(install_exec_creds); | |||
1056 | * - the caller must hold current->cred_exec_mutex to protect against | 1057 | * - the caller must hold current->cred_exec_mutex to protect against |
1057 | * PTRACE_ATTACH | 1058 | * PTRACE_ATTACH |
1058 | */ | 1059 | */ |
1059 | void check_unsafe_exec(struct linux_binprm *bprm) | 1060 | int check_unsafe_exec(struct linux_binprm *bprm) |
1060 | { | 1061 | { |
1061 | struct task_struct *p = current, *t; | 1062 | struct task_struct *p = current, *t; |
1062 | unsigned long flags; | 1063 | unsigned long flags; |
1063 | unsigned n_fs, n_sighand; | 1064 | unsigned n_fs; |
1065 | int res = 0; | ||
1064 | 1066 | ||
1065 | bprm->unsafe = tracehook_unsafe_exec(p); | 1067 | bprm->unsafe = tracehook_unsafe_exec(p); |
1066 | 1068 | ||
1067 | n_fs = 1; | 1069 | n_fs = 1; |
1068 | n_sighand = 1; | 1070 | write_lock(&p->fs->lock); |
1069 | lock_task_sighand(p, &flags); | 1071 | lock_task_sighand(p, &flags); |
1070 | for (t = next_thread(p); t != p; t = next_thread(t)) { | 1072 | for (t = next_thread(p); t != p; t = next_thread(t)) { |
1071 | if (t->fs == p->fs) | 1073 | if (t->fs == p->fs) |
1072 | n_fs++; | 1074 | n_fs++; |
1073 | n_sighand++; | ||
1074 | } | 1075 | } |
1075 | 1076 | ||
1076 | if (atomic_read(&p->fs->count) > n_fs || | 1077 | if (p->fs->users > n_fs) { |
1077 | atomic_read(&p->sighand->count) > n_sighand) | ||
1078 | bprm->unsafe |= LSM_UNSAFE_SHARE; | 1078 | bprm->unsafe |= LSM_UNSAFE_SHARE; |
1079 | } else { | ||
1080 | if (p->fs->in_exec) | ||
1081 | res = -EAGAIN; | ||
1082 | p->fs->in_exec = 1; | ||
1083 | } | ||
1079 | 1084 | ||
1080 | unlock_task_sighand(p, &flags); | 1085 | unlock_task_sighand(p, &flags); |
1086 | write_unlock(&p->fs->lock); | ||
1087 | |||
1088 | return res; | ||
1081 | } | 1089 | } |
1082 | 1090 | ||
1083 | /* | 1091 | /* |
@@ -1296,12 +1304,15 @@ int do_execve(char * filename, | |||
1296 | bprm->cred = prepare_exec_creds(); | 1304 | bprm->cred = prepare_exec_creds(); |
1297 | if (!bprm->cred) | 1305 | if (!bprm->cred) |
1298 | goto out_unlock; | 1306 | goto out_unlock; |
1299 | check_unsafe_exec(bprm); | 1307 | |
1308 | retval = check_unsafe_exec(bprm); | ||
1309 | if (retval) | ||
1310 | goto out_unlock; | ||
1300 | 1311 | ||
1301 | file = open_exec(filename); | 1312 | file = open_exec(filename); |
1302 | retval = PTR_ERR(file); | 1313 | retval = PTR_ERR(file); |
1303 | if (IS_ERR(file)) | 1314 | if (IS_ERR(file)) |
1304 | goto out_unlock; | 1315 | goto out_unmark; |
1305 | 1316 | ||
1306 | sched_exec(); | 1317 | sched_exec(); |
1307 | 1318 | ||
@@ -1344,6 +1355,9 @@ int do_execve(char * filename, | |||
1344 | goto out; | 1355 | goto out; |
1345 | 1356 | ||
1346 | /* execve succeeded */ | 1357 | /* execve succeeded */ |
1358 | write_lock(¤t->fs->lock); | ||
1359 | current->fs->in_exec = 0; | ||
1360 | write_unlock(¤t->fs->lock); | ||
1347 | current->in_execve = 0; | 1361 | current->in_execve = 0; |
1348 | mutex_unlock(¤t->cred_exec_mutex); | 1362 | mutex_unlock(¤t->cred_exec_mutex); |
1349 | acct_update_integrals(current); | 1363 | acct_update_integrals(current); |
@@ -1362,6 +1376,11 @@ out_file: | |||
1362 | fput(bprm->file); | 1376 | fput(bprm->file); |
1363 | } | 1377 | } |
1364 | 1378 | ||
1379 | out_unmark: | ||
1380 | write_lock(¤t->fs->lock); | ||
1381 | current->fs->in_exec = 0; | ||
1382 | write_unlock(¤t->fs->lock); | ||
1383 | |||
1365 | out_unlock: | 1384 | out_unlock: |
1366 | current->in_execve = 0; | 1385 | current->in_execve = 0; |
1367 | mutex_unlock(¤t->cred_exec_mutex); | 1386 | mutex_unlock(¤t->cred_exec_mutex); |