Skip to content

Commit 71c7692

Browse files
oleg-nesterovkees
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent a3aac12 commit 71c7692

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

security/yama/yama_lsm.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
222222
unsigned long arg4, unsigned long arg5)
223223
{
224224
int rc = -ENOSYS;
225-
struct task_struct *myself = current;
225+
struct task_struct *myself;
226226

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

241237
if (arg2 == 0) {
242238
yama_ptracer_del(NULL, myself);
@@ -255,7 +251,6 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
255251
}
256252
}
257253

258-
put_task_struct(myself);
259254
break;
260255
}
261256

0 commit comments

Comments
 (0)