mirror of https://github.com/torvalds/linux.git
yama: don't abuse rcu_read_lock/get_task_struct in yama_task_prctl()
current->group_leader is stable, no need to take rcu_read_lock() and do get/put_task_struct(). Signed-off-by: Oleg Nesterov <oleg@redhat.com> Link: https://lore.kernel.org/r/20250219161417.GA20851@redhat.com Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
parent
a3aac126ca
commit
71c769231f
|
|
@ -222,7 +222,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
|
||||||
unsigned long arg4, unsigned long arg5)
|
unsigned long arg4, unsigned long arg5)
|
||||||
{
|
{
|
||||||
int rc = -ENOSYS;
|
int rc = -ENOSYS;
|
||||||
struct task_struct *myself = current;
|
struct task_struct *myself;
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case PR_SET_PTRACER:
|
case PR_SET_PTRACER:
|
||||||
|
|
@ -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
|
* leader checking is handled later when walking the ancestry
|
||||||
* at the time of PTRACE_ATTACH check.
|
* at the time of PTRACE_ATTACH check.
|
||||||
*/
|
*/
|
||||||
rcu_read_lock();
|
myself = current->group_leader;
|
||||||
if (!thread_group_leader(myself))
|
|
||||||
myself = rcu_dereference(myself->group_leader);
|
|
||||||
get_task_struct(myself);
|
|
||||||
rcu_read_unlock();
|
|
||||||
|
|
||||||
if (arg2 == 0) {
|
if (arg2 == 0) {
|
||||||
yama_ptracer_del(NULL, myself);
|
yama_ptracer_del(NULL, myself);
|
||||||
|
|
@ -255,7 +251,6 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
put_task_struct(myself);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue