Skip to content

Commit

Permalink
Yama: Check for pid death before checking ancestry
Browse files Browse the repository at this point in the history
commit 9474f4e7cd71a633fa1ef93b7daefd44bbdfd482 upstream.

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.

Reported-by: [email protected]
Fixes: 2d51448 ("security: Yama LSM")
Cc: [email protected]
Suggested-by: Oleg Nesterov <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: James Morris <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
kees authored and gregkh committed Jan 22, 2019
1 parent 01634ac commit b955a2c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion security/yama/yama_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ static int yama_ptrace_access_check(struct task_struct *child,
break;
case YAMA_SCOPE_RELATIONAL:
rcu_read_lock();
if (!task_is_descendant(current, child) &&
if (!pid_alive(child))
rc = -EPERM;
if (!rc && !task_is_descendant(current, child) &&
!ptracer_exception_found(current, child) &&
!ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE))
rc = -EPERM;
Expand Down

0 comments on commit b955a2c

Please sign in to comment.