aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c168
1 files changed, 97 insertions, 71 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 628d41f0dd54..f7864ac2ecc1 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -12,7 +12,6 @@
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/personality.h> 13#include <linux/personality.h>
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/mnt_namespace.h>
16#include <linux/iocontext.h> 15#include <linux/iocontext.h>
17#include <linux/key.h> 16#include <linux/key.h>
18#include <linux/security.h> 17#include <linux/security.h>
@@ -48,7 +47,7 @@
48#include <linux/tracehook.h> 47#include <linux/tracehook.h>
49#include <linux/fs_struct.h> 48#include <linux/fs_struct.h>
50#include <linux/init_task.h> 49#include <linux/init_task.h>
51#include <linux/perf_counter.h> 50#include <linux/perf_event.h>
52#include <trace/events/sched.h> 51#include <trace/events/sched.h>
53 52
54#include <asm/uaccess.h> 53#include <asm/uaccess.h>
@@ -155,8 +154,8 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
155{ 154{
156 struct task_struct *tsk = container_of(rhp, struct task_struct, rcu); 155 struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
157 156
158#ifdef CONFIG_PERF_COUNTERS 157#ifdef CONFIG_PERF_EVENTS
159 WARN_ON_ONCE(tsk->perf_counter_ctxp); 158 WARN_ON_ONCE(tsk->perf_event_ctxp);
160#endif 159#endif
161 trace_sched_process_free(tsk); 160 trace_sched_process_free(tsk);
162 put_task_struct(tsk); 161 put_task_struct(tsk);
@@ -902,6 +901,8 @@ NORET_TYPE void do_exit(long code)
902 901
903 tracehook_report_exit(&code); 902 tracehook_report_exit(&code);
904 903
904 validate_creds_for_do_exit(tsk);
905
905 /* 906 /*
906 * We're taking recursive faults here in do_exit. Safest is to just 907 * We're taking recursive faults here in do_exit. Safest is to just
907 * leave this task alone and wait for reboot. 908 * leave this task alone and wait for reboot.
@@ -944,6 +945,8 @@ NORET_TYPE void do_exit(long code)
944 if (group_dead) { 945 if (group_dead) {
945 hrtimer_cancel(&tsk->signal->real_timer); 946 hrtimer_cancel(&tsk->signal->real_timer);
946 exit_itimers(tsk->signal); 947 exit_itimers(tsk->signal);
948 if (tsk->mm)
949 setmax_mm_hiwater_rss(&tsk->signal->maxrss, tsk->mm);
947 } 950 }
948 acct_collect(code, group_dead); 951 acct_collect(code, group_dead);
949 if (group_dead) 952 if (group_dead)
@@ -971,8 +974,6 @@ NORET_TYPE void do_exit(long code)
971 disassociate_ctty(1); 974 disassociate_ctty(1);
972 975
973 module_put(task_thread_info(tsk)->exec_domain->module); 976 module_put(task_thread_info(tsk)->exec_domain->module);
974 if (tsk->binfmt)
975 module_put(tsk->binfmt->module);
976 977
977 proc_exit_connector(tsk); 978 proc_exit_connector(tsk);
978 979
@@ -980,7 +981,7 @@ NORET_TYPE void do_exit(long code)
980 * Flush inherited counters to the parent - before the parent 981 * Flush inherited counters to the parent - before the parent
981 * gets woken up by child-exit notifications. 982 * gets woken up by child-exit notifications.
982 */ 983 */
983 perf_counter_exit_task(tsk); 984 perf_event_exit_task(tsk);
984 985
985 exit_notify(tsk, group_dead); 986 exit_notify(tsk, group_dead);
986#ifdef CONFIG_NUMA 987#ifdef CONFIG_NUMA
@@ -988,8 +989,6 @@ NORET_TYPE void do_exit(long code)
988 tsk->mempolicy = NULL; 989 tsk->mempolicy = NULL;
989#endif 990#endif
990#ifdef CONFIG_FUTEX 991#ifdef CONFIG_FUTEX
991 if (unlikely(!list_empty(&tsk->pi_state_list)))
992 exit_pi_state_list(tsk);
993 if (unlikely(current->pi_state_cache)) 992 if (unlikely(current->pi_state_cache))
994 kfree(current->pi_state_cache); 993 kfree(current->pi_state_cache);
995#endif 994#endif
@@ -1010,7 +1009,10 @@ NORET_TYPE void do_exit(long code)
1010 if (tsk->splice_pipe) 1009 if (tsk->splice_pipe)
1011 __free_pipe_info(tsk->splice_pipe); 1010 __free_pipe_info(tsk->splice_pipe);
1012 1011
1012 validate_creds_for_do_exit(tsk);
1013
1013 preempt_disable(); 1014 preempt_disable();
1015 exit_rcu();
1014 /* causes final put_task_struct in finish_task_switch(). */ 1016 /* causes final put_task_struct in finish_task_switch(). */
1015 tsk->state = TASK_DEAD; 1017 tsk->state = TASK_DEAD;
1016 schedule(); 1018 schedule();
@@ -1089,28 +1091,28 @@ struct wait_opts {
1089 int __user *wo_stat; 1091 int __user *wo_stat;
1090 struct rusage __user *wo_rusage; 1092 struct rusage __user *wo_rusage;
1091 1093
1094 wait_queue_t child_wait;
1092 int notask_error; 1095 int notask_error;
1093}; 1096};
1094 1097
1095static struct pid *task_pid_type(struct task_struct *task, enum pid_type type) 1098static inline
1099struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
1096{ 1100{
1097 struct pid *pid = NULL; 1101 if (type != PIDTYPE_PID)
1098 if (type == PIDTYPE_PID) 1102 task = task->group_leader;
1099 pid = task->pids[type].pid; 1103 return task->pids[type].pid;
1100 else if (type < PIDTYPE_MAX)
1101 pid = task->group_leader->pids[type].pid;
1102 return pid;
1103} 1104}
1104 1105
1105static int eligible_child(struct wait_opts *wo, struct task_struct *p) 1106static int eligible_pid(struct wait_opts *wo, struct task_struct *p)
1106{ 1107{
1107 int err; 1108 return wo->wo_type == PIDTYPE_MAX ||
1108 1109 task_pid_type(p, wo->wo_type) == wo->wo_pid;
1109 if (wo->wo_type < PIDTYPE_MAX) { 1110}
1110 if (task_pid_type(p, wo->wo_type) != wo->wo_pid)
1111 return 0;
1112 }
1113 1111
1112static int eligible_child(struct wait_opts *wo, struct task_struct *p)
1113{
1114 if (!eligible_pid(wo, p))
1115 return 0;
1114 /* Wait for all children (clone and not) if __WALL is set; 1116 /* Wait for all children (clone and not) if __WALL is set;
1115 * otherwise, wait for clone children *only* if __WCLONE is 1117 * otherwise, wait for clone children *only* if __WCLONE is
1116 * set; otherwise, wait for non-clone children *only*. (Note: 1118 * set; otherwise, wait for non-clone children *only*. (Note:
@@ -1120,10 +1122,6 @@ static int eligible_child(struct wait_opts *wo, struct task_struct *p)
1120 && !(wo->wo_flags & __WALL)) 1122 && !(wo->wo_flags & __WALL))
1121 return 0; 1123 return 0;
1122 1124
1123 err = security_task_wait(p);
1124 if (err)
1125 return err;
1126
1127 return 1; 1125 return 1;
1128} 1126}
1129 1127
@@ -1136,18 +1134,20 @@ static int wait_noreap_copyout(struct wait_opts *wo, struct task_struct *p,
1136 1134
1137 put_task_struct(p); 1135 put_task_struct(p);
1138 infop = wo->wo_info; 1136 infop = wo->wo_info;
1139 if (!retval) 1137 if (infop) {
1140 retval = put_user(SIGCHLD, &infop->si_signo); 1138 if (!retval)
1141 if (!retval) 1139 retval = put_user(SIGCHLD, &infop->si_signo);
1142 retval = put_user(0, &infop->si_errno); 1140 if (!retval)
1143 if (!retval) 1141 retval = put_user(0, &infop->si_errno);
1144 retval = put_user((short)why, &infop->si_code); 1142 if (!retval)
1145 if (!retval) 1143 retval = put_user((short)why, &infop->si_code);
1146 retval = put_user(pid, &infop->si_pid); 1144 if (!retval)
1147 if (!retval) 1145 retval = put_user(pid, &infop->si_pid);
1148 retval = put_user(uid, &infop->si_uid); 1146 if (!retval)
1149 if (!retval) 1147 retval = put_user(uid, &infop->si_uid);
1150 retval = put_user(status, &infop->si_status); 1148 if (!retval)
1149 retval = put_user(status, &infop->si_status);
1150 }
1151 if (!retval) 1151 if (!retval)
1152 retval = pid; 1152 retval = pid;
1153 return retval; 1153 return retval;
@@ -1204,6 +1204,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1204 if (likely(!traced) && likely(!task_detached(p))) { 1204 if (likely(!traced) && likely(!task_detached(p))) {
1205 struct signal_struct *psig; 1205 struct signal_struct *psig;
1206 struct signal_struct *sig; 1206 struct signal_struct *sig;
1207 unsigned long maxrss;
1207 1208
1208 /* 1209 /*
1209 * The resource counters for the group leader are in its 1210 * The resource counters for the group leader are in its
@@ -1252,6 +1253,9 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1252 psig->coublock += 1253 psig->coublock +=
1253 task_io_get_oublock(p) + 1254 task_io_get_oublock(p) +
1254 sig->oublock + sig->coublock; 1255 sig->oublock + sig->coublock;
1256 maxrss = max(sig->maxrss, sig->cmaxrss);
1257 if (psig->cmaxrss < maxrss)
1258 psig->cmaxrss = maxrss;
1255 task_io_accounting_add(&psig->ioac, &p->ioac); 1259 task_io_accounting_add(&psig->ioac, &p->ioac);
1256 task_io_accounting_add(&psig->ioac, &sig->ioac); 1260 task_io_accounting_add(&psig->ioac, &sig->ioac);
1257 spin_unlock_irq(&p->real_parent->sighand->siglock); 1261 spin_unlock_irq(&p->real_parent->sighand->siglock);
@@ -1473,13 +1477,14 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p)
1473 * then ->notask_error is 0 if @p is an eligible child, 1477 * then ->notask_error is 0 if @p is an eligible child,
1474 * or another error from security_task_wait(), or still -ECHILD. 1478 * or another error from security_task_wait(), or still -ECHILD.
1475 */ 1479 */
1476static int wait_consider_task(struct wait_opts *wo, struct task_struct *parent, 1480static int wait_consider_task(struct wait_opts *wo, int ptrace,
1477 int ptrace, struct task_struct *p) 1481 struct task_struct *p)
1478{ 1482{
1479 int ret = eligible_child(wo, p); 1483 int ret = eligible_child(wo, p);
1480 if (!ret) 1484 if (!ret)
1481 return ret; 1485 return ret;
1482 1486
1487 ret = security_task_wait(p);
1483 if (unlikely(ret < 0)) { 1488 if (unlikely(ret < 0)) {
1484 /* 1489 /*
1485 * If we have not yet seen any eligible child, 1490 * If we have not yet seen any eligible child,
@@ -1541,7 +1546,7 @@ static int do_wait_thread(struct wait_opts *wo, struct task_struct *tsk)
1541 * Do not consider detached threads. 1546 * Do not consider detached threads.
1542 */ 1547 */
1543 if (!task_detached(p)) { 1548 if (!task_detached(p)) {
1544 int ret = wait_consider_task(wo, tsk, 0, p); 1549 int ret = wait_consider_task(wo, 0, p);
1545 if (ret) 1550 if (ret)
1546 return ret; 1551 return ret;
1547 } 1552 }
@@ -1555,7 +1560,7 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
1555 struct task_struct *p; 1560 struct task_struct *p;
1556 1561
1557 list_for_each_entry(p, &tsk->ptraced, ptrace_entry) { 1562 list_for_each_entry(p, &tsk->ptraced, ptrace_entry) {
1558 int ret = wait_consider_task(wo, tsk, 1, p); 1563 int ret = wait_consider_task(wo, 1, p);
1559 if (ret) 1564 if (ret)
1560 return ret; 1565 return ret;
1561 } 1566 }
@@ -1563,15 +1568,38 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
1563 return 0; 1568 return 0;
1564} 1569}
1565 1570
1571static int child_wait_callback(wait_queue_t *wait, unsigned mode,
1572 int sync, void *key)
1573{
1574 struct wait_opts *wo = container_of(wait, struct wait_opts,
1575 child_wait);
1576 struct task_struct *p = key;
1577
1578 if (!eligible_pid(wo, p))
1579 return 0;
1580
1581 if ((wo->wo_flags & __WNOTHREAD) && wait->private != p->parent)
1582 return 0;
1583
1584 return default_wake_function(wait, mode, sync, key);
1585}
1586
1587void __wake_up_parent(struct task_struct *p, struct task_struct *parent)
1588{
1589 __wake_up_sync_key(&parent->signal->wait_chldexit,
1590 TASK_INTERRUPTIBLE, 1, p);
1591}
1592
1566static long do_wait(struct wait_opts *wo) 1593static long do_wait(struct wait_opts *wo)
1567{ 1594{
1568 DECLARE_WAITQUEUE(wait, current);
1569 struct task_struct *tsk; 1595 struct task_struct *tsk;
1570 int retval; 1596 int retval;
1571 1597
1572 trace_sched_process_wait(wo->wo_pid); 1598 trace_sched_process_wait(wo->wo_pid);
1573 1599
1574 add_wait_queue(&current->signal->wait_chldexit,&wait); 1600 init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
1601 wo->child_wait.private = current;
1602 add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1575repeat: 1603repeat:
1576 /* 1604 /*
1577 * If there is nothing that can match our critiera just get out. 1605 * If there is nothing that can match our critiera just get out.
@@ -1612,32 +1640,7 @@ notask:
1612 } 1640 }
1613end: 1641end:
1614 __set_current_state(TASK_RUNNING); 1642 __set_current_state(TASK_RUNNING);
1615 remove_wait_queue(&current->signal->wait_chldexit,&wait); 1643 remove_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1616 if (wo->wo_info) {
1617 struct siginfo __user *infop = wo->wo_info;
1618
1619 if (retval > 0)
1620 retval = 0;
1621 else {
1622 /*
1623 * For a WNOHANG return, clear out all the fields
1624 * we would set so the user can easily tell the
1625 * difference.
1626 */
1627 if (!retval)
1628 retval = put_user(0, &infop->si_signo);
1629 if (!retval)
1630 retval = put_user(0, &infop->si_errno);
1631 if (!retval)
1632 retval = put_user(0, &infop->si_code);
1633 if (!retval)
1634 retval = put_user(0, &infop->si_pid);
1635 if (!retval)
1636 retval = put_user(0, &infop->si_uid);
1637 if (!retval)
1638 retval = put_user(0, &infop->si_status);
1639 }
1640 }
1641 return retval; 1644 return retval;
1642} 1645}
1643 1646
@@ -1682,6 +1685,29 @@ SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *,
1682 wo.wo_stat = NULL; 1685 wo.wo_stat = NULL;
1683 wo.wo_rusage = ru; 1686 wo.wo_rusage = ru;
1684 ret = do_wait(&wo); 1687 ret = do_wait(&wo);
1688
1689 if (ret > 0) {
1690 ret = 0;
1691 } else if (infop) {
1692 /*
1693 * For a WNOHANG return, clear out all the fields
1694 * we would set so the user can easily tell the
1695 * difference.
1696 */
1697 if (!ret)
1698 ret = put_user(0, &infop->si_signo);
1699 if (!ret)
1700 ret = put_user(0, &infop->si_errno);
1701 if (!ret)
1702 ret = put_user(0, &infop->si_code);
1703 if (!ret)
1704 ret = put_user(0, &infop->si_pid);
1705 if (!ret)
1706 ret = put_user(0, &infop->si_uid);
1707 if (!ret)
1708 ret = put_user(0, &infop->si_status);
1709 }
1710
1685 put_pid(pid); 1711 put_pid(pid);
1686 1712
1687 /* avoid REGPARM breakage on x86: */ 1713 /* avoid REGPARM breakage on x86: */