]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - kernel/ptrace.c
xen-netfront: Fix NULL sring after live migration
[mirror_ubuntu-jammy-kernel.git] / kernel / ptrace.c
index f8589bf8d7dcec03c9e2d592a41ad64ea84d013d..0cf547531ddf0aa62005f8fe6270fda803517617 100644 (file)
@@ -371,6 +371,26 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
        return !err;
 }
 
+static int check_ptrace_options(unsigned long data)
+{
+       if (data & ~(unsigned long)PTRACE_O_MASK)
+               return -EINVAL;
+
+       if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) {
+               if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) ||
+                   !IS_ENABLED(CONFIG_SECCOMP))
+                       return -EINVAL;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+
+               if (seccomp_mode(&current->seccomp) != SECCOMP_MODE_DISABLED ||
+                   current->ptrace & PT_SUSPEND_SECCOMP)
+                       return -EPERM;
+       }
+       return 0;
+}
+
 static int ptrace_attach(struct task_struct *task, long request,
                         unsigned long addr,
                         unsigned long flags)
@@ -382,8 +402,16 @@ static int ptrace_attach(struct task_struct *task, long request,
        if (seize) {
                if (addr != 0)
                        goto out;
+               /*
+                * This duplicates the check in check_ptrace_options() because
+                * ptrace_attach() and ptrace_setoptions() have historically
+                * used different error codes for unknown ptrace options.
+                */
                if (flags & ~(unsigned long)PTRACE_O_MASK)
                        goto out;
+               retval = check_ptrace_options(flags);
+               if (retval)
+                       return retval;
                flags = PT_PTRACED | PT_SEIZED | (flags << PT_OPT_FLAG_SHIFT);
        } else {
                flags = PT_PTRACED;
@@ -656,22 +684,11 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
 static int ptrace_setoptions(struct task_struct *child, unsigned long data)
 {
        unsigned flags;
+       int ret;
 
-       if (data & ~(unsigned long)PTRACE_O_MASK)
-               return -EINVAL;
-
-       if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) {
-               if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) ||
-                   !IS_ENABLED(CONFIG_SECCOMP))
-                       return -EINVAL;
-
-               if (!capable(CAP_SYS_ADMIN))
-                       return -EPERM;
-
-               if (seccomp_mode(&current->seccomp) != SECCOMP_MODE_DISABLED ||
-                   current->ptrace & PT_SUSPEND_SECCOMP)
-                       return -EPERM;
-       }
+       ret = check_ptrace_options(data);
+       if (ret)
+               return ret;
 
        /* Avoid intermediate state when all opts are cleared */
        flags = child->ptrace;
@@ -1221,9 +1238,8 @@ int ptrace_request(struct task_struct *child, long request,
                return ptrace_resume(child, request, data);
 
        case PTRACE_KILL:
-               if (child->exit_state)  /* already dead */
-                       return 0;
-               return ptrace_resume(child, request, SIGKILL);
+               send_sig_info(SIGKILL, SEND_SIG_NOINFO, child);
+               return 0;
 
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
        case PTRACE_GETREGSET: