Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptrace: Always take siglock in ptrace_resume

Make code analysis simpler and future changes easier by
always taking siglock in ptrace_resume.

Tested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lkml.kernel.org/r/20220505182645.497868-11-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+2 -11
+2 -11
kernel/ptrace.c
··· 837 837 static int ptrace_resume(struct task_struct *child, long request, 838 838 unsigned long data) 839 839 { 840 - bool need_siglock; 841 - 842 840 if (!valid_signal(data)) 843 841 return -EIO; 844 842 ··· 872 874 * Note that we need siglock even if ->exit_code == data and/or this 873 875 * status was not reported yet, the new status must not be cleared by 874 876 * wait_task_stopped() after resume. 875 - * 876 - * If data == 0 we do not care if wait_task_stopped() reports the old 877 - * status and clears the code too; this can't race with the tracee, it 878 - * takes siglock after resume. 879 877 */ 880 - need_siglock = data && !thread_group_empty(current); 881 - if (need_siglock) 882 - spin_lock_irq(&child->sighand->siglock); 878 + spin_lock_irq(&child->sighand->siglock); 883 879 child->exit_code = data; 884 880 wake_up_state(child, __TASK_TRACED); 885 - if (need_siglock) 886 - spin_unlock_irq(&child->sighand->siglock); 881 + spin_unlock_irq(&child->sighand->siglock); 887 882 888 883 return 0; 889 884 }