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