ptrace_attach: shift send(SIGSTOP) into ptrace_set_stopped()
authorOleg Nesterov <oleg@redhat.com>
Mon, 22 Jan 2024 17:16:31 +0000 (18:16 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 22 Feb 2024 23:38:52 +0000 (15:38 -0800)
Turn send_sig_info(SIGSTOP) into send_signal_locked(SIGSTOP) and move it
from ptrace_attach() to ptrace_set_stopped().

This looks more logical and avoids lock(siglock) right after unlock().

Link: https://lkml.kernel.org/r/20240122171631.GA29844@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/ptrace.c

index 2fabd497d6598831d1144ecb8696e85ca4fb3f3d..d5f89f9ef29f65f137ef8a6978e6dbe75564056b 100644 (file)
@@ -375,10 +375,13 @@ static int check_ptrace_options(unsigned long data)
        return 0;
 }
 
-static inline void ptrace_set_stopped(struct task_struct *task)
+static inline void ptrace_set_stopped(struct task_struct *task, bool seize)
 {
        guard(spinlock)(&task->sighand->siglock);
 
+       /* SEIZE doesn't trap tracee on attach */
+       if (!seize)
+               send_signal_locked(SIGSTOP, SEND_SIG_PRIV, task, PIDTYPE_PID);
        /*
         * If the task is already STOPPED, set JOBCTL_TRAP_STOP and
         * TRAPPING, and kick it so that it transits to TRACED.  TRAPPING
@@ -457,14 +460,8 @@ static int ptrace_attach(struct task_struct *task, long request,
                                return -EPERM;
 
                        task->ptrace = flags;
-
                        ptrace_link(task, current);
-
-                       /* SEIZE doesn't trap tracee on attach */
-                       if (!seize)
-                               send_sig_info(SIGSTOP, SEND_SIG_PRIV, task);
-
-                       ptrace_set_stopped(task);
+                       ptrace_set_stopped(task, seize);
                }
        }