aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/ptrace.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2008-11-13 18:39:19 -0500
committerJames Morris <jmorris@namei.org>2008-11-13 18:39:19 -0500
commitc69e8d9c01db2adc503464993c358901c9af9de4 (patch)
treebed94aaa9aeb7a7834d1c880f72b62a11a752c78 /kernel/ptrace.c
parent86a264abe542cfececb4df129bc45a0338d8cdb9 (diff)
CRED: Use RCU to access another task's creds and to release a task's own creds
Use RCU to access another task's creds and to release a task's own creds. This means that it will be possible for the credentials of a task to be replaced without another task (a) requiring a full lock to read them, and (b) seeing deallocated memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: James Morris <jmorris@namei.org> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'kernel/ptrace.c')
-rw-r--r--kernel/ptrace.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 49849d12dd12..b9d5f4e4f6a4 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -115,7 +115,7 @@ int ptrace_check_attach(struct task_struct *child, int kill)
115 115
116int __ptrace_may_access(struct task_struct *task, unsigned int mode) 116int __ptrace_may_access(struct task_struct *task, unsigned int mode)
117{ 117{
118 struct cred *cred = current->cred, *tcred = task->cred; 118 const struct cred *cred = current_cred(), *tcred;
119 119
120 /* May we inspect the given task? 120 /* May we inspect the given task?
121 * This check is used both for attaching with ptrace 121 * This check is used both for attaching with ptrace
@@ -125,19 +125,23 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
125 * because setting up the necessary parent/child relationship 125 * because setting up the necessary parent/child relationship
126 * or halting the specified task is impossible. 126 * or halting the specified task is impossible.
127 */ 127 */
128 uid_t uid = cred->uid;
129 gid_t gid = cred->gid;
130 int dumpable = 0; 128 int dumpable = 0;
131 /* Don't let security modules deny introspection */ 129 /* Don't let security modules deny introspection */
132 if (task == current) 130 if (task == current)
133 return 0; 131 return 0;
134 if ((uid != tcred->euid || 132 rcu_read_lock();
135 uid != tcred->suid || 133 tcred = __task_cred(task);
136 uid != tcred->uid || 134 if ((cred->uid != tcred->euid ||
137 gid != tcred->egid || 135 cred->uid != tcred->suid ||
138 gid != tcred->sgid || 136 cred->uid != tcred->uid ||
139 gid != tcred->gid) && !capable(CAP_SYS_PTRACE)) 137 cred->gid != tcred->egid ||
138 cred->gid != tcred->sgid ||
139 cred->gid != tcred->gid) &&
140 !capable(CAP_SYS_PTRACE)) {
141 rcu_read_unlock();
140 return -EPERM; 142 return -EPERM;
143 }
144 rcu_read_unlock();
141 smp_rmb(); 145 smp_rmb();
142 if (task->mm) 146 if (task->mm)
143 dumpable = get_dumpable(task->mm); 147 dumpable = get_dumpable(task->mm);