History

Yama: Check for pid death before checking ancestry

It's possible that a pid has died before we take the rcu lock, in which case we can't walk the ancestry list as it may be detached. Instead, check for death first before doing the walk.

Kees Cook committed 7 years ago

Commit 9474f4e1 parent a811dc61 file · +3 −1Browse files

Unified · Split

security/yama/yama_lsm.c+3−1
@@ -368,7 +368,9 @@ static int yama_ptrace_access_check(struct task_struct *child, · 367 unmodified lines
368368 break;
369369 case YAMA_SCOPE_RELATIONAL:
370370 rcu_read_lock();
371− if (!task_is_descendant(current, child) &&
371+ if (!pid_alive(child))
372+ rc = -EPERM;
373+ if (!rc && !task_is_descendant(current, child) &&
372374 !ptracer_exception_found(current, child) &&
373375 !ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE))
374376 rc = -EPERM;