Skip to content

Commit

Permalink
yama: don't abuse rcu_read_lock/get_task_struct in yama_task_prctl()
Browse files Browse the repository at this point in the history
current->group_leader is stable, no need to take rcu_read_lock() and do
get/put_task_struct().

Signed-off-by: Oleg Nesterov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
oleg-nesterov authored and kees committed Mar 4, 2025
1 parent e612e94 commit 50aadd0
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions security/yama/yama_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
int rc = -ENOSYS;
struct task_struct *myself = current;
struct task_struct *myself;

switch (option) {
case PR_SET_PTRACER:
Expand All @@ -232,11 +232,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
* leader checking is handled later when walking the ancestry
* at the time of PTRACE_ATTACH check.
*/
rcu_read_lock();
if (!thread_group_leader(myself))
myself = rcu_dereference(myself->group_leader);
get_task_struct(myself);
rcu_read_unlock();
myself = current->group_leader;

if (arg2 == 0) {
yama_ptracer_del(NULL, myself);
Expand All @@ -255,7 +251,6 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
}
}

put_task_struct(myself);
break;
}

Expand Down

0 comments on commit 50aadd0

Please sign in to comment.