[PATCH] de_thread: fix lockless do_each_thread
[pandora-kernel.git] / fs / exec.c
index 4d38ad0..fffea1e 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -49,6 +49,7 @@
 #include <linux/rmap.h>
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
+#include <linux/audit.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -665,10 +666,6 @@ static int de_thread(struct task_struct *tsk)
         * and to assume its PID:
         */
        if (!thread_group_leader(current)) {
-               struct task_struct *parent;
-               struct dentry *proc_dentry1, *proc_dentry2;
-               unsigned long ptrace;
-
                /*
                 * Wait for the thread group leader to be a zombie.
                 * It should already be zombie at this point, most
@@ -678,10 +675,18 @@ static int de_thread(struct task_struct *tsk)
                while (leader->exit_state != EXIT_ZOMBIE)
                        yield();
 
-               spin_lock(&leader->proc_lock);
-               spin_lock(&current->proc_lock);
-               proc_dentry1 = proc_pid_unhash(current);
-               proc_dentry2 = proc_pid_unhash(leader);
+               /*
+                * The only record we have of the real-time age of a
+                * process, regardless of execs it's done, is start_time.
+                * All the past CPU time is accumulated in signal_struct
+                * from sister threads now dead.  But in this non-leader
+                * exec, nothing survives from the original leader thread,
+                * whose birth marks the true age of this process now.
+                * When we take on its identity by switching to its PID, we
+                * also take its birthdate (always earlier than our own).
+                */
+               current->start_time = leader->start_time;
+
                write_lock_irq(&tasklist_lock);
 
                BUG_ON(leader->tgid != current->tgid);
@@ -692,22 +697,6 @@ static int de_thread(struct task_struct *tsk)
                 * two threads with a switched PID, and release
                 * the former thread group leader:
                 */
-               ptrace = leader->ptrace;
-               parent = leader->parent;
-               if (unlikely(ptrace) && unlikely(parent == current)) {
-                       /*
-                        * Joker was ptracing his own group leader,
-                        * and now he wants to be his own parent!
-                        * We can't have that.
-                        */
-                       ptrace = 0;
-               }
-
-               ptrace_unlink(current);
-               ptrace_unlink(leader);
-               remove_parent(current);
-               remove_parent(leader);
-
 
                /* Become a process group leader with the old leader's pid.
                 * Note: The old leader also uses thispid until release_task
@@ -718,24 +707,14 @@ static int de_thread(struct task_struct *tsk)
                attach_pid(current, PIDTYPE_PID,  current->pid);
                attach_pid(current, PIDTYPE_PGID, current->signal->pgrp);
                attach_pid(current, PIDTYPE_SID,  current->signal->session);
-               list_add_tail(&current->tasks, &init_task.tasks);
+               list_replace_rcu(&leader->tasks, &current->tasks);
 
-               current->parent = current->real_parent = leader->real_parent;
-               leader->parent = leader->real_parent = child_reaper;
                current->group_leader = current;
                leader->group_leader = current;
 
                /* Reduce leader to a thread */
                detach_pid(leader, PIDTYPE_PGID);
                detach_pid(leader, PIDTYPE_SID);
-               list_del_init(&leader->tasks);
-
-               add_parent(current);
-               add_parent(leader);
-               if (ptrace) {
-                       current->ptrace = ptrace;
-                       __ptrace_link(current, parent);
-               }
 
                current->exit_signal = SIGCHLD;
 
@@ -743,10 +722,6 @@ static int de_thread(struct task_struct *tsk)
                leader->exit_state = EXIT_DEAD;
 
                write_unlock_irq(&tasklist_lock);
-               spin_unlock(&leader->proc_lock);
-               spin_unlock(&current->proc_lock);
-               proc_pid_flush(proc_dentry1);
-               proc_pid_flush(proc_dentry2);
         }
 
        /*
@@ -880,7 +855,6 @@ int flush_old_exec(struct linux_binprm * bprm)
        bprm->mm = NULL;                /* We're using it now */
 
        /* This is the point of no return */
-       steal_locks(files);
        put_files_struct(files);
 
        current->sas_ss_sp = current->sas_ss_size = 0;
@@ -1100,6 +1074,11 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
        /* kernel module loader fixup */
        /* so we don't try to load run modprobe in kernel space. */
        set_fs(USER_DS);
+
+       retval = audit_bprm(bprm);
+       if (retval)
+               return retval;
+
        retval = -ENOENT;
        for (try=0; try<2; try++) {
                read_lock(&binfmt_lock);