Skip to content

Commit

Permalink
ptrace: Always take siglock in ptrace_resume
Browse files Browse the repository at this point in the history
Make code analysis simpler and future changes easier by
always taking siglock in ptrace_resume.

Tested-by: Kees Cook <[email protected]>
Reviewed-by: Oleg Nesterov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed May 11, 2022
1 parent 2500ad1 commit 5b4197c
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,6 @@ static long ptrace_get_rseq_configuration(struct task_struct *task,
static int ptrace_resume(struct task_struct *child, long request,
unsigned long data)
{
bool need_siglock;

if (!valid_signal(data))
return -EIO;

Expand Down Expand Up @@ -874,18 +872,11 @@ static int ptrace_resume(struct task_struct *child, long request,
* Note that we need siglock even if ->exit_code == data and/or this
* status was not reported yet, the new status must not be cleared by
* wait_task_stopped() after resume.
*
* If data == 0 we do not care if wait_task_stopped() reports the old
* status and clears the code too; this can't race with the tracee, it
* takes siglock after resume.
*/
need_siglock = data && !thread_group_empty(current);
if (need_siglock)
spin_lock_irq(&child->sighand->siglock);
spin_lock_irq(&child->sighand->siglock);
child->exit_code = data;
wake_up_state(child, __TASK_TRACED);
if (need_siglock)
spin_unlock_irq(&child->sighand->siglock);
spin_unlock_irq(&child->sighand->siglock);

return 0;
}
Expand Down

0 comments on commit 5b4197c

Please sign in to comment.