aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-07-26 08:05:21 -0400
committerEric W. Biederman <ebiederm@xmission.com>2012-11-20 07:17:44 -0500
commit4c44aaafa8108f584831850ab48a975e971db2de (patch)
treec86f225e8256d28271acf3ea8926e70358f3e5c1 /security
parentbcf58e725ddc45d31addbc6627d4f0edccc824c1 (diff)
userns: Kill task_user_ns
The task_user_ns function hides the fact that it is getting the user namespace from struct cred on the task. struct cred may go away as soon as the rcu lock is released. This leads to a race where we can dereference a stale user namespace pointer. To make it obvious a struct cred is involved kill task_user_ns. To kill the race modify the users of task_user_ns to only reference the user namespace while the rcu lock is held. Cc: Kees Cook <keescook@chromium.org> Cc: James Morris <james.l.morris@oracle.com> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'security')
-rw-r--r--security/yama/yama_lsm.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index b4c29848b49d..0e72239aeb05 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -262,14 +262,18 @@ int yama_ptrace_access_check(struct task_struct *child,
262 /* No additional restrictions. */ 262 /* No additional restrictions. */
263 break; 263 break;
264 case YAMA_SCOPE_RELATIONAL: 264 case YAMA_SCOPE_RELATIONAL:
265 rcu_read_lock();
265 if (!task_is_descendant(current, child) && 266 if (!task_is_descendant(current, child) &&
266 !ptracer_exception_found(current, child) && 267 !ptracer_exception_found(current, child) &&
267 !ns_capable(task_user_ns(child), CAP_SYS_PTRACE)) 268 !ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE))
268 rc = -EPERM; 269 rc = -EPERM;
270 rcu_read_unlock();
269 break; 271 break;
270 case YAMA_SCOPE_CAPABILITY: 272 case YAMA_SCOPE_CAPABILITY:
271 if (!ns_capable(task_user_ns(child), CAP_SYS_PTRACE)) 273 rcu_read_lock();
274 if (!ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE))
272 rc = -EPERM; 275 rc = -EPERM;
276 rcu_read_unlock();
273 break; 277 break;
274 case YAMA_SCOPE_NO_ATTACH: 278 case YAMA_SCOPE_NO_ATTACH:
275 default: 279 default:
@@ -307,8 +311,10 @@ int yama_ptrace_traceme(struct task_struct *parent)
307 /* Only disallow PTRACE_TRACEME on more aggressive settings. */ 311 /* Only disallow PTRACE_TRACEME on more aggressive settings. */
308 switch (ptrace_scope) { 312 switch (ptrace_scope) {
309 case YAMA_SCOPE_CAPABILITY: 313 case YAMA_SCOPE_CAPABILITY:
310 if (!ns_capable(task_user_ns(parent), CAP_SYS_PTRACE)) 314 rcu_read_lock();
315 if (!ns_capable(__task_cred(parent)->user_ns, CAP_SYS_PTRACE))
311 rc = -EPERM; 316 rc = -EPERM;
317 rcu_read_unlock();
312 break; 318 break;
313 case YAMA_SCOPE_NO_ATTACH: 319 case YAMA_SCOPE_NO_ATTACH:
314 rc = -EPERM; 320 rc = -EPERM;