include/asm-x86/local.h: checkpatch cleanups - formatting only
[sfrench/cifs-2.6.git] / kernel / ptrace.c
index ed1c3d56c2cde16f3db6f4725f1cdd8d41b2e383..fdb34e86f923f188113e7945e63c572c805c65a2 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/signal.h>
 #include <linux/audit.h>
 #include <linux/pid_namespace.h>
+#include <linux/syscalls.h>
 
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
@@ -51,9 +52,9 @@ void __ptrace_link(struct task_struct *child, struct task_struct *new_parent)
 void ptrace_untrace(struct task_struct *child)
 {
        spin_lock(&child->sighand->siglock);
-       if (child->state == TASK_TRACED) {
+       if (task_is_traced(child)) {
                if (child->signal->flags & SIGNAL_STOP_STOPPED) {
-                       child->state = TASK_STOPPED;
+                       __set_task_state(child, TASK_STOPPED);
                } else {
                        signal_wake_up(child, 1);
                }
@@ -79,7 +80,7 @@ void __ptrace_unlink(struct task_struct *child)
                add_parent(child);
        }
 
-       if (child->state == TASK_TRACED)
+       if (task_is_traced(child))
                ptrace_untrace(child);
 }
 
@@ -98,23 +99,23 @@ int ptrace_check_attach(struct task_struct *child, int kill)
         * be changed by us so it's not changing right after this.
         */
        read_lock(&tasklist_lock);
-       if ((child->ptrace & PT_PTRACED) && child->parent == current &&
-           (!(child->ptrace & PT_ATTACHED) || child->real_parent != current)
-           && child->signal != NULL) {
+       if ((child->ptrace & PT_PTRACED) && child->parent == current) {
                ret = 0;
+               /*
+                * child->sighand can't be NULL, release_task()
+                * does ptrace_unlink() before __exit_signal().
+                */
                spin_lock_irq(&child->sighand->siglock);
-               if (child->state == TASK_STOPPED) {
+               if (task_is_stopped(child))
                        child->state = TASK_TRACED;
-               } else if (child->state != TASK_TRACED && !kill) {
+               else if (!task_is_traced(child) && !kill)
                        ret = -ESRCH;
-               }
                spin_unlock_irq(&child->sighand->siglock);
        }
        read_unlock(&tasklist_lock);
 
-       if (!ret && !kill) {
+       if (!ret && !kill)
                wait_task_inactive(child);
-       }
 
        /* All systems go.. */
        return ret;
@@ -201,8 +202,7 @@ repeat:
                goto bad;
 
        /* Go */
-       task->ptrace |= PT_PTRACED | ((task->real_parent != current)
-                                     ? PT_ATTACHED : 0);
+       task->ptrace |= PT_PTRACED;
        if (capable(CAP_SYS_PTRACE))
                task->ptrace |= PT_PTRACE_CAP;
 
@@ -644,4 +644,50 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
 
        return ret;
 }
+
+#ifdef __ARCH_WANT_COMPAT_SYS_PTRACE
+asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
+                                 compat_long_t addr, compat_long_t data)
+{
+       struct task_struct *child;
+       long ret;
+
+       /*
+        * This lock_kernel fixes a subtle race with suid exec
+        */
+       lock_kernel();
+       if (request == PTRACE_TRACEME) {
+               ret = ptrace_traceme();
+               goto out;
+       }
+
+       child = ptrace_get_task_struct(pid);
+       if (IS_ERR(child)) {
+               ret = PTR_ERR(child);
+               goto out;
+       }
+
+       if (request == PTRACE_ATTACH) {
+               ret = ptrace_attach(child);
+               /*
+                * Some architectures need to do book-keeping after
+                * a ptrace attach.
+                */
+               if (!ret)
+                       arch_ptrace_attach(child);
+               goto out_put_task_struct;
+       }
+
+       ret = ptrace_check_attach(child, request == PTRACE_KILL);
+       if (!ret)
+               ret = compat_arch_ptrace(child, request, addr, data);
+
+ out_put_task_struct:
+       put_task_struct(child);
+ out:
+       unlock_kernel();
+       return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_PTRACE */
+
 #endif /* CONFIG_COMPAT */