diff options
author | KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> | 2010-10-27 18:34:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-27 21:03:12 -0400 |
commit | 9b1bf12d5d51bca178dea21b04a0805e29d60cf1 (patch) | |
tree | 902a2c0e5882a2152da59a589958d6426dc84643 /fs | |
parent | b84011508360d6885a9d95a235ec77d56f133377 (diff) |
signals: move cred_guard_mutex from task_struct to signal_struct
Oleg Nesterov pointed out we have to prevent multiple-threads-inside-exec
itself and we can reuse ->cred_guard_mutex for it. Yes, concurrent
execve() has no worth.
Let's move ->cred_guard_mutex from task_struct to signal_struct. It
naturally prevent multiple-threads-inside-exec.
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Roland McGrath <roland@redhat.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/exec.c | 10 | ||||
-rw-r--r-- | fs/proc/base.c | 8 |
2 files changed, 9 insertions, 9 deletions
@@ -1083,14 +1083,14 @@ EXPORT_SYMBOL(setup_new_exec); | |||
1083 | */ | 1083 | */ |
1084 | int prepare_bprm_creds(struct linux_binprm *bprm) | 1084 | int prepare_bprm_creds(struct linux_binprm *bprm) |
1085 | { | 1085 | { |
1086 | if (mutex_lock_interruptible(¤t->cred_guard_mutex)) | 1086 | if (mutex_lock_interruptible(¤t->signal->cred_guard_mutex)) |
1087 | return -ERESTARTNOINTR; | 1087 | return -ERESTARTNOINTR; |
1088 | 1088 | ||
1089 | bprm->cred = prepare_exec_creds(); | 1089 | bprm->cred = prepare_exec_creds(); |
1090 | if (likely(bprm->cred)) | 1090 | if (likely(bprm->cred)) |
1091 | return 0; | 1091 | return 0; |
1092 | 1092 | ||
1093 | mutex_unlock(¤t->cred_guard_mutex); | 1093 | mutex_unlock(¤t->signal->cred_guard_mutex); |
1094 | return -ENOMEM; | 1094 | return -ENOMEM; |
1095 | } | 1095 | } |
1096 | 1096 | ||
@@ -1098,7 +1098,7 @@ void free_bprm(struct linux_binprm *bprm) | |||
1098 | { | 1098 | { |
1099 | free_arg_pages(bprm); | 1099 | free_arg_pages(bprm); |
1100 | if (bprm->cred) { | 1100 | if (bprm->cred) { |
1101 | mutex_unlock(¤t->cred_guard_mutex); | 1101 | mutex_unlock(¤t->signal->cred_guard_mutex); |
1102 | abort_creds(bprm->cred); | 1102 | abort_creds(bprm->cred); |
1103 | } | 1103 | } |
1104 | kfree(bprm); | 1104 | kfree(bprm); |
@@ -1119,13 +1119,13 @@ void install_exec_creds(struct linux_binprm *bprm) | |||
1119 | * credentials; any time after this it may be unlocked. | 1119 | * credentials; any time after this it may be unlocked. |
1120 | */ | 1120 | */ |
1121 | security_bprm_committed_creds(bprm); | 1121 | security_bprm_committed_creds(bprm); |
1122 | mutex_unlock(¤t->cred_guard_mutex); | 1122 | mutex_unlock(¤t->signal->cred_guard_mutex); |
1123 | } | 1123 | } |
1124 | EXPORT_SYMBOL(install_exec_creds); | 1124 | EXPORT_SYMBOL(install_exec_creds); |
1125 | 1125 | ||
1126 | /* | 1126 | /* |
1127 | * determine how safe it is to execute the proposed program | 1127 | * determine how safe it is to execute the proposed program |
1128 | * - the caller must hold current->cred_guard_mutex to protect against | 1128 | * - the caller must hold ->cred_guard_mutex to protect against |
1129 | * PTRACE_ATTACH | 1129 | * PTRACE_ATTACH |
1130 | */ | 1130 | */ |
1131 | int check_unsafe_exec(struct linux_binprm *bprm) | 1131 | int check_unsafe_exec(struct linux_binprm *bprm) |
diff --git a/fs/proc/base.c b/fs/proc/base.c index 9b094c1c8465..f3d02ca461ec 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -226,7 +226,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task) | |||
226 | { | 226 | { |
227 | struct mm_struct *mm; | 227 | struct mm_struct *mm; |
228 | 228 | ||
229 | if (mutex_lock_killable(&task->cred_guard_mutex)) | 229 | if (mutex_lock_killable(&task->signal->cred_guard_mutex)) |
230 | return NULL; | 230 | return NULL; |
231 | 231 | ||
232 | mm = get_task_mm(task); | 232 | mm = get_task_mm(task); |
@@ -235,7 +235,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task) | |||
235 | mmput(mm); | 235 | mmput(mm); |
236 | mm = NULL; | 236 | mm = NULL; |
237 | } | 237 | } |
238 | mutex_unlock(&task->cred_guard_mutex); | 238 | mutex_unlock(&task->signal->cred_guard_mutex); |
239 | 239 | ||
240 | return mm; | 240 | return mm; |
241 | } | 241 | } |
@@ -2354,14 +2354,14 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, | |||
2354 | goto out_free; | 2354 | goto out_free; |
2355 | 2355 | ||
2356 | /* Guard against adverse ptrace interaction */ | 2356 | /* Guard against adverse ptrace interaction */ |
2357 | length = mutex_lock_interruptible(&task->cred_guard_mutex); | 2357 | length = mutex_lock_interruptible(&task->signal->cred_guard_mutex); |
2358 | if (length < 0) | 2358 | if (length < 0) |
2359 | goto out_free; | 2359 | goto out_free; |
2360 | 2360 | ||
2361 | length = security_setprocattr(task, | 2361 | length = security_setprocattr(task, |
2362 | (char*)file->f_path.dentry->d_name.name, | 2362 | (char*)file->f_path.dentry->d_name.name, |
2363 | (void*)page, count); | 2363 | (void*)page, count); |
2364 | mutex_unlock(&task->cred_guard_mutex); | 2364 | mutex_unlock(&task->signal->cred_guard_mutex); |
2365 | out_free: | 2365 | out_free: |
2366 | free_page((unsigned long) page); | 2366 | free_page((unsigned long) page); |
2367 | out: | 2367 | out: |