This patch modifies switch_exec_pids so that it uses the
normal attach_pid/detach_pid functions. This makes
the code more maintainable and it removes a race
where find_pid could fail to find a thread group or
a process id that currently exists.
We also now preserve the exit_signal of our thread group
leader when we call exec (when we take over the thread
group leaders identity).
And for good measure we set the thread group leaders
exit_signal to -1 so it will self reap. We are actually
past the point where that matters but it can't hurt, and
it might help someday.
Signed-off-by: Eric W. Biederman <[email protected]>
---
fs/exec.c | 3 ++-
kernel/pid.c | 33 +++++++++++++--------------------
2 files changed, 15 insertions(+), 21 deletions(-)
dab45943cf60c11f4432d6fdd26d68eb7092b8dd
diff --git a/fs/exec.c b/fs/exec.c
index c9d8e31..922dbee 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -721,10 +721,11 @@ static int de_thread(struct task_struct
list_del(¤t->tasks);
list_add_tail(¤t->tasks, &init_task.tasks);
- current->exit_signal = SIGCHLD;
+ current->exit_signal = leader->exit_signal;
BUG_ON(leader->exit_state != EXIT_ZOMBIE);
leader->exit_state = EXIT_DEAD;
+ leader->exit_signal = -1;
write_unlock_irq(&tasklist_lock);
spin_unlock(&leader->proc_lock);
diff --git a/kernel/pid.c b/kernel/pid.c
index 1acc072..d2247dc 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -220,31 +220,24 @@ EXPORT_SYMBOL(find_task_by_pid_type);
/*
* This function switches the PIDs if a non-leader thread calls
* sys_execve() - this must be done without releasing the PID.
- * (which a detach_pid() would eventually do.)
+ *
+ * The attach and detach operations have been carefully
+ * ordered so there is never an instant that pids that will
+ * survive are absent from the hash table. This ensures
+ * that we don't release pids we mean to keep.
*/
void switch_exec_pids(task_t *leader, task_t *thread)
{
- __detach_pid(leader, PIDTYPE_PID);
- __detach_pid(leader, PIDTYPE_TGID);
- __detach_pid(leader, PIDTYPE_PGID);
- __detach_pid(leader, PIDTYPE_SID);
-
- __detach_pid(thread, PIDTYPE_PID);
- __detach_pid(thread, PIDTYPE_TGID);
-
- leader->pid = leader->tgid = thread->pid;
- thread->pid = thread->tgid;
-
- attach_pid(thread, PIDTYPE_PID, thread->pid);
- attach_pid(thread, PIDTYPE_TGID, thread->tgid);
+ detach_pid(thread, PIDTYPE_PID);
+ thread->pid = leader->pid;
+ attach_pid(thread, PIDTYPE_PID, thread->pid);
attach_pid(thread, PIDTYPE_PGID, thread->signal->pgrp);
- attach_pid(thread, PIDTYPE_SID, thread->signal->session);
- list_add_tail(&thread->tasks, &init_task.tasks);
+ attach_pid(thread, PIDTYPE_SID, thread->signal->session);
- attach_pid(leader, PIDTYPE_PID, leader->pid);
- attach_pid(leader, PIDTYPE_TGID, leader->tgid);
- attach_pid(leader, PIDTYPE_PGID, leader->signal->pgrp);
- attach_pid(leader, PIDTYPE_SID, leader->signal->session);
+ detach_pid(leader, PIDTYPE_PID);
+ detach_pid(leader, PIDTYPE_TGID);
+ detach_pid(leader, PIDTYPE_PGID);
+ detach_pid(leader, PIDTYPE_SID);
}
/*
--
1.1.5.g3480
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]