]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/exit.c
autofs4: detect invalid direct mount requests
[linux-2.6-omap-h63xx.git] / kernel / exit.c
index 1e909826a80483a7acf6d52a8cee8b2bcc6d7522..93d2711b938123d34f1c0011e8f91a589b465615 100644 (file)
@@ -702,6 +702,23 @@ static void exit_mm(struct task_struct * tsk)
        mmput(mm);
 }
 
+/*
+ * Return nonzero if @parent's children should reap themselves.
+ *
+ * Called with write_lock_irq(&tasklist_lock) held.
+ */
+static int ignoring_children(struct task_struct *parent)
+{
+       int ret;
+       struct sighand_struct *psig = parent->sighand;
+       unsigned long flags;
+       spin_lock_irqsave(&psig->siglock, flags);
+       ret = (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
+              (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT));
+       spin_unlock_irqrestore(&psig->siglock, flags);
+       return ret;
+}
+
 /*
  * Detach all tasks we were using ptrace on.
  * Any that need to be release_task'd are put on the @dead list.
@@ -711,6 +728,7 @@ static void exit_mm(struct task_struct * tsk)
 static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
 {
        struct task_struct *p, *n;
+       int ign = -1;
 
        list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
                __ptrace_unlink(p);
@@ -726,10 +744,18 @@ static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
                 * release_task() here because we already hold tasklist_lock.
                 *
                 * If it's our own child, there is no notification to do.
+                * But if our normal children self-reap, then this child
+                * was prevented by ptrace and we must reap it now.
                 */
                if (!task_detached(p) && thread_group_empty(p)) {
                        if (!same_thread_group(p->real_parent, parent))
                                do_notify_parent(p, p->exit_signal);
+                       else {
+                               if (ign < 0)
+                                       ign = ignoring_children(parent);
+                               if (ign)
+                                       p->exit_signal = -1;
+                       }
                }
 
                if (task_detached(p)) {
@@ -1199,14 +1225,10 @@ static int eligible_child(enum pid_type type, struct pid *pid, int options,
                return 0;
 
        err = security_task_wait(p);
-       if (likely(!err))
-               return 1;
+       if (err)
+               return err;
 
-       if (type != PIDTYPE_PID)
-               return 0;
-       /* This child was explicitly requested, abort */
-       read_unlock(&tasklist_lock);
-       return err;
+       return 1;
 }
 
 static int wait_noreap_copyout(struct task_struct *p, pid_t pid, uid_t uid,
@@ -1536,7 +1558,8 @@ static int wait_task_continued(struct task_struct *p, int options,
  * -ECHILD should be in *@notask_error before the first call.
  * Returns nonzero for a final return, when we have unlocked tasklist_lock.
  * Returns zero if the search for a child should continue;
- * then *@notask_error is 0 if @p is an eligible child, or still -ECHILD.
+ * then *@notask_error is 0 if @p is an eligible child,
+ * or another error from security_task_wait(), or still -ECHILD.
  */
 static int wait_consider_task(struct task_struct *parent, int ptrace,
                              struct task_struct *p, int *notask_error,
@@ -1545,9 +1568,21 @@ static int wait_consider_task(struct task_struct *parent, int ptrace,
                              int __user *stat_addr, struct rusage __user *ru)
 {
        int ret = eligible_child(type, pid, options, p);
-       if (ret <= 0)
+       if (!ret)
                return ret;
 
+       if (unlikely(ret < 0)) {
+               /*
+                * If we have not yet seen any eligible child,
+                * then let this error code replace -ECHILD.
+                * A permission error will give the user a clue
+                * to look for security policy problems, rather
+                * than for mysterious wait bugs.
+                */
+               if (*notask_error)
+                       *notask_error = ret;
+       }
+
        if (likely(!ptrace) && unlikely(p->ptrace)) {
                /*
                 * This child is hidden by ptrace.
@@ -1585,7 +1620,8 @@ static int wait_consider_task(struct task_struct *parent, int ptrace,
  * -ECHILD should be in *@notask_error before the first call.
  * Returns nonzero for a final return, when we have unlocked tasklist_lock.
  * Returns zero if the search for a child should continue; then
- * *@notask_error is 0 if there were any eligible children, or still -ECHILD.
+ * *@notask_error is 0 if there were any eligible children,
+ * or another error from security_task_wait(), or still -ECHILD.
  */
 static int do_wait_thread(struct task_struct *tsk, int *notask_error,
                          enum pid_type type, struct pid *pid, int options,