Now we can kill ->ptrace check in ptrace_attach_task(), if the task is
not dead we always clear ->ptrace before UTRACE_DETACH.

This reverts most part of
"[PATCH 09] move ->ptrace == 0 checks to ptrace_attach_task()", but
I am just sending the new patch on top of previous changes to avoid
the confusion.

---

 kernel/ptrace.c |   39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

--- PU/kernel/ptrace.c~14_ATTACH_DONT_CK_PTRACE 2009-08-22 20:31:26.000000000 
+0200
+++ PU/kernel/ptrace.c  2009-08-22 20:46:41.000000000 +0200
@@ -485,43 +485,30 @@ static int ptrace_attach_task(struct tas
 {
        struct utrace_engine *engine;
        unsigned long events;
-       int err = -EPERM;
 
        engine = utrace_attach_task(tracee, UTRACE_ATTACH_CREATE |
                                                UTRACE_ATTACH_EXCLUSIVE |
                                                UTRACE_ATTACH_MATCH_OPS,
                                                &ptrace_utrace_ops, NULL);
        if (unlikely(IS_ERR(engine))) {
-               if (PTR_ERR(engine) == -ESRCH ||
-                   PTR_ERR(engine) == -ERESTARTNOINTR)
-                       err = PTR_ERR(engine);
+               int err = PTR_ERR(engine);
+               if (err != -ESRCH && err != -ERESTARTNOINTR)
+                       err = -EPERM ;
                return err;
        }
-
        /*
-        * Check ->ptrace to make sure we don't race with the previous
-        * tracer which didn't finish detach. If it is clear, nobody
-        * can change it except us due to UTRACE_ATTACH_EXCLUSIVE.
+        * We need QUIESCE for resume handling, CLONE to check
+        * for CLONE_PTRACE, other events are always reported.
         */
-       if (unlikely(tracee->ptrace)) {
-               utrace_control(tracee, engine, UTRACE_DETACH);
-       } else {
-               /*
-                * We need QUIESCE for resume handling, CLONE to check
-                * for CLONE_PTRACE, other events are always reported.
-                */
-               events = UTRACE_EVENT(QUIESCE) | UTRACE_EVENT(CLONE) |
-                        UTRACE_EVENT(EXEC) | UTRACE_EVENT_SIGNAL_ALL;
-               /*
-                * It can fail only if the tracee is dead, the caller
-                * must notice this before setting PT_PTRACED.
-                */
-               utrace_set_events(tracee, engine, events);
-               err = 0;
-       }
-
+       events = UTRACE_EVENT(QUIESCE) | UTRACE_EVENT(CLONE) |
+                UTRACE_EVENT(EXEC) | UTRACE_EVENT_SIGNAL_ALL;
+       /*
+        * It can fail only if the tracee is dead, the caller
+        * must notice this before setting PT_PTRACED.
+        */
+       utrace_set_events(tracee, engine, events);
        utrace_engine_put(engine);
-       return err;
+       return 0;
 }
 
 static void ptrace_abort_attach(struct task_struct *tracee)

Reply via email to