Commit:     d36174bc2bce0372693a9cfbdef8b2689c9982cb
Parent:     f374ada53bd1ca7c16d7607369fccc6769704956
Author:     Oleg Nesterov <[EMAIL PROTECTED]>
AuthorDate: Fri Feb 8 04:19:18 2008 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Fri Feb 8 09:22:28 2008 -0800

    uglify kill_pid_info() to fix kill() vs exec() race
    kill_pid_info()->pid_task() could be the old leader of the execing process.
    In that case it is possible that the leader will be released before we take
    siglock. This means that kill_pid_info() (and thus sys_kill()) can return a
    false -ESRCH.
    Change the code to retry when lock_task_sighand() fails. The endless loop is
    not possible, __exit_signal() both clears ->sighand and does detach_pid().
    Signed-off-by: Oleg Nesterov <[EMAIL PROTECTED]>
    Cc: "Eric W. Biederman" <[EMAIL PROTECTED]>
    Cc: Davide Libenzi <[EMAIL PROTECTED]>
    Cc: Pavel Emelyanov <[EMAIL PROTECTED]>
    Cc: Roland McGrath <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 kernel/signal.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 3d3adb9..b0b43a4 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1050,17 +1050,26 @@ int kill_pgrp_info(int sig, struct siginfo *info, 
struct pid *pgrp)
 int kill_pid_info(int sig, struct siginfo *info, struct pid *pid)
-       int error;
+       int error = -ESRCH;
        struct task_struct *p;
        if (unlikely(sig_needs_tasklist(sig)))
        p = pid_task(pid, PIDTYPE_PID);
-       error = -ESRCH;
-       if (p)
+       if (p) {
                error = group_send_sig_info(sig, info, p);
+               if (unlikely(error == -ESRCH))
+                       /*
+                        * The task was unhashed in between, try again.
+                        * If it is dead, pid_task() will return NULL,
+                        * if we race with de_thread() it will find the
+                        * new leader.
+                        */
+                       goto retry;
+       }
        if (unlikely(sig_needs_tasklist(sig)))
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to