diff options
author | David Howells <dhowells@redhat.com> | 2009-05-08 08:55:22 -0400 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2009-05-10 18:15:36 -0400 |
commit | 5e751e992f3fb08ba35e1ca8095ec8fbf9eda523 (patch) | |
tree | 711b1b47622dc9661f1d3d9c67d55c0b21456e8c | |
parent | d254117099d711f215e62427f55dfb8ebd5ad011 (diff) |
CRED: Rename cred_exec_mutex to reflect that it's a guard against ptrace
Rename cred_exec_mutex to reflect that it's a guard against foreign
intervention on a process's credential state, such as is made by ptrace(). The
attachment of a debugger to a process affects execve()'s calculation of the new
credential state - _and_ also setprocattr()'s calculation of that state.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
-rw-r--r-- | fs/compat.c | 6 | ||||
-rw-r--r-- | fs/exec.c | 10 | ||||
-rw-r--r-- | include/linux/init_task.h | 4 | ||||
-rw-r--r-- | include/linux/sched.h | 4 | ||||
-rw-r--r-- | kernel/cred.c | 4 | ||||
-rw-r--r-- | kernel/ptrace.c | 9 |
6 files changed, 20 insertions, 17 deletions
diff --git a/fs/compat.c b/fs/compat.c index 681ed81e6be0..bb2a9b2e8173 100644 --- a/fs/compat.c +++ b/fs/compat.c | |||
@@ -1488,7 +1488,7 @@ int compat_do_execve(char * filename, | |||
1488 | if (!bprm) | 1488 | if (!bprm) |
1489 | goto out_files; | 1489 | goto out_files; |
1490 | 1490 | ||
1491 | retval = mutex_lock_interruptible(¤t->cred_exec_mutex); | 1491 | retval = mutex_lock_interruptible(¤t->cred_guard_mutex); |
1492 | if (retval < 0) | 1492 | if (retval < 0) |
1493 | goto out_free; | 1493 | goto out_free; |
1494 | current->in_execve = 1; | 1494 | current->in_execve = 1; |
@@ -1550,7 +1550,7 @@ int compat_do_execve(char * filename, | |||
1550 | /* execve succeeded */ | 1550 | /* execve succeeded */ |
1551 | current->fs->in_exec = 0; | 1551 | current->fs->in_exec = 0; |
1552 | current->in_execve = 0; | 1552 | current->in_execve = 0; |
1553 | mutex_unlock(¤t->cred_exec_mutex); | 1553 | mutex_unlock(¤t->cred_guard_mutex); |
1554 | acct_update_integrals(current); | 1554 | acct_update_integrals(current); |
1555 | free_bprm(bprm); | 1555 | free_bprm(bprm); |
1556 | if (displaced) | 1556 | if (displaced) |
@@ -1573,7 +1573,7 @@ out_unmark: | |||
1573 | 1573 | ||
1574 | out_unlock: | 1574 | out_unlock: |
1575 | current->in_execve = 0; | 1575 | current->in_execve = 0; |
1576 | mutex_unlock(¤t->cred_exec_mutex); | 1576 | mutex_unlock(¤t->cred_guard_mutex); |
1577 | 1577 | ||
1578 | out_free: | 1578 | out_free: |
1579 | free_bprm(bprm); | 1579 | free_bprm(bprm); |
@@ -1045,7 +1045,7 @@ void install_exec_creds(struct linux_binprm *bprm) | |||
1045 | commit_creds(bprm->cred); | 1045 | commit_creds(bprm->cred); |
1046 | bprm->cred = NULL; | 1046 | bprm->cred = NULL; |
1047 | 1047 | ||
1048 | /* cred_exec_mutex must be held at least to this point to prevent | 1048 | /* cred_guard_mutex must be held at least to this point to prevent |
1049 | * ptrace_attach() from altering our determination of the task's | 1049 | * ptrace_attach() from altering our determination of the task's |
1050 | * credentials; any time after this it may be unlocked */ | 1050 | * credentials; any time after this it may be unlocked */ |
1051 | 1051 | ||
@@ -1055,7 +1055,7 @@ EXPORT_SYMBOL(install_exec_creds); | |||
1055 | 1055 | ||
1056 | /* | 1056 | /* |
1057 | * determine how safe it is to execute the proposed program | 1057 | * determine how safe it is to execute the proposed program |
1058 | * - the caller must hold current->cred_exec_mutex to protect against | 1058 | * - the caller must hold current->cred_guard_mutex to protect against |
1059 | * PTRACE_ATTACH | 1059 | * PTRACE_ATTACH |
1060 | */ | 1060 | */ |
1061 | int check_unsafe_exec(struct linux_binprm *bprm) | 1061 | int check_unsafe_exec(struct linux_binprm *bprm) |
@@ -1297,7 +1297,7 @@ int do_execve(char * filename, | |||
1297 | if (!bprm) | 1297 | if (!bprm) |
1298 | goto out_files; | 1298 | goto out_files; |
1299 | 1299 | ||
1300 | retval = mutex_lock_interruptible(¤t->cred_exec_mutex); | 1300 | retval = mutex_lock_interruptible(¤t->cred_guard_mutex); |
1301 | if (retval < 0) | 1301 | if (retval < 0) |
1302 | goto out_free; | 1302 | goto out_free; |
1303 | current->in_execve = 1; | 1303 | current->in_execve = 1; |
@@ -1360,7 +1360,7 @@ int do_execve(char * filename, | |||
1360 | /* execve succeeded */ | 1360 | /* execve succeeded */ |
1361 | current->fs->in_exec = 0; | 1361 | current->fs->in_exec = 0; |
1362 | current->in_execve = 0; | 1362 | current->in_execve = 0; |
1363 | mutex_unlock(¤t->cred_exec_mutex); | 1363 | mutex_unlock(¤t->cred_guard_mutex); |
1364 | acct_update_integrals(current); | 1364 | acct_update_integrals(current); |
1365 | free_bprm(bprm); | 1365 | free_bprm(bprm); |
1366 | if (displaced) | 1366 | if (displaced) |
@@ -1383,7 +1383,7 @@ out_unmark: | |||
1383 | 1383 | ||
1384 | out_unlock: | 1384 | out_unlock: |
1385 | current->in_execve = 0; | 1385 | current->in_execve = 0; |
1386 | mutex_unlock(¤t->cred_exec_mutex); | 1386 | mutex_unlock(¤t->cred_guard_mutex); |
1387 | 1387 | ||
1388 | out_free: | 1388 | out_free: |
1389 | free_bprm(bprm); | 1389 | free_bprm(bprm); |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index d87247d2641f..7f54ba942429 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
@@ -145,8 +145,8 @@ extern struct cred init_cred; | |||
145 | .group_leader = &tsk, \ | 145 | .group_leader = &tsk, \ |
146 | .real_cred = &init_cred, \ | 146 | .real_cred = &init_cred, \ |
147 | .cred = &init_cred, \ | 147 | .cred = &init_cred, \ |
148 | .cred_exec_mutex = \ | 148 | .cred_guard_mutex = \ |
149 | __MUTEX_INITIALIZER(tsk.cred_exec_mutex), \ | 149 | __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \ |
150 | .comm = "swapper", \ | 150 | .comm = "swapper", \ |
151 | .thread = INIT_THREAD, \ | 151 | .thread = INIT_THREAD, \ |
152 | .fs = &init_fs, \ | 152 | .fs = &init_fs, \ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 3fa82b353c98..5932ace22400 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1247,7 +1247,9 @@ struct task_struct { | |||
1247 | * credentials (COW) */ | 1247 | * credentials (COW) */ |
1248 | const struct cred *cred; /* effective (overridable) subjective task | 1248 | const struct cred *cred; /* effective (overridable) subjective task |
1249 | * credentials (COW) */ | 1249 | * credentials (COW) */ |
1250 | struct mutex cred_exec_mutex; /* execve vs ptrace cred calculation mutex */ | 1250 | struct mutex cred_guard_mutex; /* guard against foreign influences on |
1251 | * credential calculations | ||
1252 | * (notably. ptrace) */ | ||
1251 | 1253 | ||
1252 | char comm[TASK_COMM_LEN]; /* executable name excluding path | 1254 | char comm[TASK_COMM_LEN]; /* executable name excluding path |
1253 | - access with [gs]et_task_comm (which lock | 1255 | - access with [gs]et_task_comm (which lock |
diff --git a/kernel/cred.c b/kernel/cred.c index 3a039189d707..1bb4d7e5d616 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
@@ -167,7 +167,7 @@ EXPORT_SYMBOL(prepare_creds); | |||
167 | 167 | ||
168 | /* | 168 | /* |
169 | * Prepare credentials for current to perform an execve() | 169 | * Prepare credentials for current to perform an execve() |
170 | * - The caller must hold current->cred_exec_mutex | 170 | * - The caller must hold current->cred_guard_mutex |
171 | */ | 171 | */ |
172 | struct cred *prepare_exec_creds(void) | 172 | struct cred *prepare_exec_creds(void) |
173 | { | 173 | { |
@@ -276,7 +276,7 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
276 | struct cred *new; | 276 | struct cred *new; |
277 | int ret; | 277 | int ret; |
278 | 278 | ||
279 | mutex_init(&p->cred_exec_mutex); | 279 | mutex_init(&p->cred_guard_mutex); |
280 | 280 | ||
281 | if ( | 281 | if ( |
282 | #ifdef CONFIG_KEYS | 282 | #ifdef CONFIG_KEYS |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 0692ab5a0d67..27ac80298bfa 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -185,10 +185,11 @@ int ptrace_attach(struct task_struct *task) | |||
185 | if (same_thread_group(task, current)) | 185 | if (same_thread_group(task, current)) |
186 | goto out; | 186 | goto out; |
187 | 187 | ||
188 | /* Protect exec's credential calculations against our interference; | 188 | /* Protect the target's credential calculations against our |
189 | * SUID, SGID and LSM creds get determined differently under ptrace. | 189 | * interference; SUID, SGID and LSM creds get determined differently |
190 | * under ptrace. | ||
190 | */ | 191 | */ |
191 | retval = mutex_lock_interruptible(&task->cred_exec_mutex); | 192 | retval = mutex_lock_interruptible(&task->cred_guard_mutex); |
192 | if (retval < 0) | 193 | if (retval < 0) |
193 | goto out; | 194 | goto out; |
194 | 195 | ||
@@ -232,7 +233,7 @@ repeat: | |||
232 | bad: | 233 | bad: |
233 | write_unlock_irqrestore(&tasklist_lock, flags); | 234 | write_unlock_irqrestore(&tasklist_lock, flags); |
234 | task_unlock(task); | 235 | task_unlock(task); |
235 | mutex_unlock(&task->cred_exec_mutex); | 236 | mutex_unlock(&task->cred_guard_mutex); |
236 | out: | 237 | out: |
237 | return retval; | 238 | return retval; |
238 | } | 239 | } |