diff options
Diffstat (limited to 'kernel/signal.c')
-rw-r--r-- | kernel/signal.c | 869 |
1 files changed, 595 insertions, 274 deletions
diff --git a/kernel/signal.c b/kernel/signal.c index 4e3cff10fdce..86c32b884f8e 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -124,7 +124,7 @@ static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked) | |||
124 | 124 | ||
125 | static int recalc_sigpending_tsk(struct task_struct *t) | 125 | static int recalc_sigpending_tsk(struct task_struct *t) |
126 | { | 126 | { |
127 | if (t->signal->group_stop_count > 0 || | 127 | if ((t->group_stop & GROUP_STOP_PENDING) || |
128 | PENDING(&t->pending, &t->blocked) || | 128 | PENDING(&t->pending, &t->blocked) || |
129 | PENDING(&t->signal->shared_pending, &t->blocked)) { | 129 | PENDING(&t->signal->shared_pending, &t->blocked)) { |
130 | set_tsk_thread_flag(t, TIF_SIGPENDING); | 130 | set_tsk_thread_flag(t, TIF_SIGPENDING); |
@@ -223,10 +223,87 @@ static inline void print_dropped_signal(int sig) | |||
223 | current->comm, current->pid, sig); | 223 | current->comm, current->pid, sig); |
224 | } | 224 | } |
225 | 225 | ||
226 | /** | ||
227 | * task_clear_group_stop_trapping - clear group stop trapping bit | ||
228 | * @task: target task | ||
229 | * | ||
230 | * If GROUP_STOP_TRAPPING is set, a ptracer is waiting for us. Clear it | ||
231 | * and wake up the ptracer. Note that we don't need any further locking. | ||
232 | * @task->siglock guarantees that @task->parent points to the ptracer. | ||
233 | * | ||
234 | * CONTEXT: | ||
235 | * Must be called with @task->sighand->siglock held. | ||
236 | */ | ||
237 | static void task_clear_group_stop_trapping(struct task_struct *task) | ||
238 | { | ||
239 | if (unlikely(task->group_stop & GROUP_STOP_TRAPPING)) { | ||
240 | task->group_stop &= ~GROUP_STOP_TRAPPING; | ||
241 | __wake_up_sync_key(&task->parent->signal->wait_chldexit, | ||
242 | TASK_UNINTERRUPTIBLE, 1, task); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * task_clear_group_stop_pending - clear pending group stop | ||
248 | * @task: target task | ||
249 | * | ||
250 | * Clear group stop states for @task. | ||
251 | * | ||
252 | * CONTEXT: | ||
253 | * Must be called with @task->sighand->siglock held. | ||
254 | */ | ||
255 | void task_clear_group_stop_pending(struct task_struct *task) | ||
256 | { | ||
257 | task->group_stop &= ~(GROUP_STOP_PENDING | GROUP_STOP_CONSUME | | ||
258 | GROUP_STOP_DEQUEUED); | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * task_participate_group_stop - participate in a group stop | ||
263 | * @task: task participating in a group stop | ||
264 | * | ||
265 | * @task has GROUP_STOP_PENDING set and is participating in a group stop. | ||
266 | * Group stop states are cleared and the group stop count is consumed if | ||
267 | * %GROUP_STOP_CONSUME was set. If the consumption completes the group | ||
268 | * stop, the appropriate %SIGNAL_* flags are set. | ||
269 | * | ||
270 | * CONTEXT: | ||
271 | * Must be called with @task->sighand->siglock held. | ||
272 | * | ||
273 | * RETURNS: | ||
274 | * %true if group stop completion should be notified to the parent, %false | ||
275 | * otherwise. | ||
276 | */ | ||
277 | static bool task_participate_group_stop(struct task_struct *task) | ||
278 | { | ||
279 | struct signal_struct *sig = task->signal; | ||
280 | bool consume = task->group_stop & GROUP_STOP_CONSUME; | ||
281 | |||
282 | WARN_ON_ONCE(!(task->group_stop & GROUP_STOP_PENDING)); | ||
283 | |||
284 | task_clear_group_stop_pending(task); | ||
285 | |||
286 | if (!consume) | ||
287 | return false; | ||
288 | |||
289 | if (!WARN_ON_ONCE(sig->group_stop_count == 0)) | ||
290 | sig->group_stop_count--; | ||
291 | |||
292 | /* | ||
293 | * Tell the caller to notify completion iff we are entering into a | ||
294 | * fresh group stop. Read comment in do_signal_stop() for details. | ||
295 | */ | ||
296 | if (!sig->group_stop_count && !(sig->flags & SIGNAL_STOP_STOPPED)) { | ||
297 | sig->flags = SIGNAL_STOP_STOPPED; | ||
298 | return true; | ||
299 | } | ||
300 | return false; | ||
301 | } | ||
302 | |||
226 | /* | 303 | /* |
227 | * allocate a new signal queue record | 304 | * allocate a new signal queue record |
228 | * - this may be called without locks if and only if t == current, otherwise an | 305 | * - this may be called without locks if and only if t == current, otherwise an |
229 | * appopriate lock must be held to stop the target task from exiting | 306 | * appropriate lock must be held to stop the target task from exiting |
230 | */ | 307 | */ |
231 | static struct sigqueue * | 308 | static struct sigqueue * |
232 | __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) | 309 | __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) |
@@ -375,15 +452,15 @@ int unhandled_signal(struct task_struct *tsk, int sig) | |||
375 | return !tracehook_consider_fatal_signal(tsk, sig); | 452 | return !tracehook_consider_fatal_signal(tsk, sig); |
376 | } | 453 | } |
377 | 454 | ||
378 | 455 | /* | |
379 | /* Notify the system that a driver wants to block all signals for this | 456 | * Notify the system that a driver wants to block all signals for this |
380 | * process, and wants to be notified if any signals at all were to be | 457 | * process, and wants to be notified if any signals at all were to be |
381 | * sent/acted upon. If the notifier routine returns non-zero, then the | 458 | * sent/acted upon. If the notifier routine returns non-zero, then the |
382 | * signal will be acted upon after all. If the notifier routine returns 0, | 459 | * signal will be acted upon after all. If the notifier routine returns 0, |
383 | * then then signal will be blocked. Only one block per process is | 460 | * then then signal will be blocked. Only one block per process is |
384 | * allowed. priv is a pointer to private data that the notifier routine | 461 | * allowed. priv is a pointer to private data that the notifier routine |
385 | * can use to determine if the signal should be blocked or not. */ | 462 | * can use to determine if the signal should be blocked or not. |
386 | 463 | */ | |
387 | void | 464 | void |
388 | block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask) | 465 | block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask) |
389 | { | 466 | { |
@@ -434,9 +511,10 @@ still_pending: | |||
434 | copy_siginfo(info, &first->info); | 511 | copy_siginfo(info, &first->info); |
435 | __sigqueue_free(first); | 512 | __sigqueue_free(first); |
436 | } else { | 513 | } else { |
437 | /* Ok, it wasn't in the queue. This must be | 514 | /* |
438 | a fast-pathed signal or we must have been | 515 | * Ok, it wasn't in the queue. This must be |
439 | out of queue space. So zero out the info. | 516 | * a fast-pathed signal or we must have been |
517 | * out of queue space. So zero out the info. | ||
440 | */ | 518 | */ |
441 | info->si_signo = sig; | 519 | info->si_signo = sig; |
442 | info->si_errno = 0; | 520 | info->si_errno = 0; |
@@ -468,7 +546,7 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, | |||
468 | } | 546 | } |
469 | 547 | ||
470 | /* | 548 | /* |
471 | * Dequeue a signal and return the element to the caller, which is | 549 | * Dequeue a signal and return the element to the caller, which is |
472 | * expected to free it. | 550 | * expected to free it. |
473 | * | 551 | * |
474 | * All callers have to hold the siglock. | 552 | * All callers have to hold the siglock. |
@@ -490,7 +568,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) | |||
490 | * itimers are process shared and we restart periodic | 568 | * itimers are process shared and we restart periodic |
491 | * itimers in the signal delivery path to prevent DoS | 569 | * itimers in the signal delivery path to prevent DoS |
492 | * attacks in the high resolution timer case. This is | 570 | * attacks in the high resolution timer case. This is |
493 | * compliant with the old way of self restarting | 571 | * compliant with the old way of self-restarting |
494 | * itimers, as the SIGALRM is a legacy signal and only | 572 | * itimers, as the SIGALRM is a legacy signal and only |
495 | * queued once. Changing the restart behaviour to | 573 | * queued once. Changing the restart behaviour to |
496 | * restart the timer in the signal dequeue path is | 574 | * restart the timer in the signal dequeue path is |
@@ -526,7 +604,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) | |||
526 | * is to alert stop-signal processing code when another | 604 | * is to alert stop-signal processing code when another |
527 | * processor has come along and cleared the flag. | 605 | * processor has come along and cleared the flag. |
528 | */ | 606 | */ |
529 | tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; | 607 | current->group_stop |= GROUP_STOP_DEQUEUED; |
530 | } | 608 | } |
531 | if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { | 609 | if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { |
532 | /* | 610 | /* |
@@ -591,7 +669,7 @@ static int rm_from_queue_full(sigset_t *mask, struct sigpending *s) | |||
591 | if (sigisemptyset(&m)) | 669 | if (sigisemptyset(&m)) |
592 | return 0; | 670 | return 0; |
593 | 671 | ||
594 | signandsets(&s->signal, &s->signal, mask); | 672 | sigandnsets(&s->signal, &s->signal, mask); |
595 | list_for_each_entry_safe(q, n, &s->list, list) { | 673 | list_for_each_entry_safe(q, n, &s->list, list) { |
596 | if (sigismember(mask, q->info.si_signo)) { | 674 | if (sigismember(mask, q->info.si_signo)) { |
597 | list_del_init(&q->list); | 675 | list_del_init(&q->list); |
@@ -636,13 +714,33 @@ static inline bool si_fromuser(const struct siginfo *info) | |||
636 | } | 714 | } |
637 | 715 | ||
638 | /* | 716 | /* |
717 | * called with RCU read lock from check_kill_permission() | ||
718 | */ | ||
719 | static int kill_ok_by_cred(struct task_struct *t) | ||
720 | { | ||
721 | const struct cred *cred = current_cred(); | ||
722 | const struct cred *tcred = __task_cred(t); | ||
723 | |||
724 | if (cred->user->user_ns == tcred->user->user_ns && | ||
725 | (cred->euid == tcred->suid || | ||
726 | cred->euid == tcred->uid || | ||
727 | cred->uid == tcred->suid || | ||
728 | cred->uid == tcred->uid)) | ||
729 | return 1; | ||
730 | |||
731 | if (ns_capable(tcred->user->user_ns, CAP_KILL)) | ||
732 | return 1; | ||
733 | |||
734 | return 0; | ||
735 | } | ||
736 | |||
737 | /* | ||
639 | * Bad permissions for sending the signal | 738 | * Bad permissions for sending the signal |
640 | * - the caller must hold the RCU read lock | 739 | * - the caller must hold the RCU read lock |
641 | */ | 740 | */ |
642 | static int check_kill_permission(int sig, struct siginfo *info, | 741 | static int check_kill_permission(int sig, struct siginfo *info, |
643 | struct task_struct *t) | 742 | struct task_struct *t) |
644 | { | 743 | { |
645 | const struct cred *cred, *tcred; | ||
646 | struct pid *sid; | 744 | struct pid *sid; |
647 | int error; | 745 | int error; |
648 | 746 | ||
@@ -656,14 +754,8 @@ static int check_kill_permission(int sig, struct siginfo *info, | |||
656 | if (error) | 754 | if (error) |
657 | return error; | 755 | return error; |
658 | 756 | ||
659 | cred = current_cred(); | ||
660 | tcred = __task_cred(t); | ||
661 | if (!same_thread_group(current, t) && | 757 | if (!same_thread_group(current, t) && |
662 | (cred->euid ^ tcred->suid) && | 758 | !kill_ok_by_cred(t)) { |
663 | (cred->euid ^ tcred->uid) && | ||
664 | (cred->uid ^ tcred->suid) && | ||
665 | (cred->uid ^ tcred->uid) && | ||
666 | !capable(CAP_KILL)) { | ||
667 | switch (sig) { | 759 | switch (sig) { |
668 | case SIGCONT: | 760 | case SIGCONT: |
669 | sid = task_session(t); | 761 | sid = task_session(t); |
@@ -712,34 +804,14 @@ static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns) | |||
712 | } else if (sig == SIGCONT) { | 804 | } else if (sig == SIGCONT) { |
713 | unsigned int why; | 805 | unsigned int why; |
714 | /* | 806 | /* |
715 | * Remove all stop signals from all queues, | 807 | * Remove all stop signals from all queues, wake all threads. |
716 | * and wake all threads. | ||
717 | */ | 808 | */ |
718 | rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending); | 809 | rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending); |
719 | t = p; | 810 | t = p; |
720 | do { | 811 | do { |
721 | unsigned int state; | 812 | task_clear_group_stop_pending(t); |
722 | rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending); | 813 | rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending); |
723 | /* | 814 | wake_up_state(t, __TASK_STOPPED); |
724 | * If there is a handler for SIGCONT, we must make | ||
725 | * sure that no thread returns to user mode before | ||
726 | * we post the signal, in case it was the only | ||
727 | * thread eligible to run the signal handler--then | ||
728 | * it must not do anything between resuming and | ||
729 | * running the handler. With the TIF_SIGPENDING | ||
730 | * flag set, the thread will pause and acquire the | ||
731 | * siglock that we hold now and until we've queued | ||
732 | * the pending signal. | ||
733 | * | ||
734 | * Wake up the stopped thread _after_ setting | ||
735 | * TIF_SIGPENDING | ||
736 | */ | ||
737 | state = __TASK_STOPPED; | ||
738 | if (sig_user_defined(t, SIGCONT) && !sigismember(&t->blocked, SIGCONT)) { | ||
739 | set_tsk_thread_flag(t, TIF_SIGPENDING); | ||
740 | state |= TASK_INTERRUPTIBLE; | ||
741 | } | ||
742 | wake_up_state(t, state); | ||
743 | } while_each_thread(p, t); | 815 | } while_each_thread(p, t); |
744 | 816 | ||
745 | /* | 817 | /* |
@@ -765,13 +837,6 @@ static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns) | |||
765 | signal->flags = why | SIGNAL_STOP_CONTINUED; | 837 | signal->flags = why | SIGNAL_STOP_CONTINUED; |
766 | signal->group_stop_count = 0; | 838 | signal->group_stop_count = 0; |
767 | signal->group_exit_code = 0; | 839 | signal->group_exit_code = 0; |
768 | } else { | ||
769 | /* | ||
770 | * We are not stopped, but there could be a stop | ||
771 | * signal in the middle of being processed after | ||
772 | * being removed from the queue. Clear that too. | ||
773 | */ | ||
774 | signal->flags &= ~SIGNAL_STOP_DEQUEUED; | ||
775 | } | 840 | } |
776 | } | 841 | } |
777 | 842 | ||
@@ -860,6 +925,7 @@ static void complete_signal(int sig, struct task_struct *p, int group) | |||
860 | signal->group_stop_count = 0; | 925 | signal->group_stop_count = 0; |
861 | t = p; | 926 | t = p; |
862 | do { | 927 | do { |
928 | task_clear_group_stop_pending(t); | ||
863 | sigaddset(&t->pending.signal, SIGKILL); | 929 | sigaddset(&t->pending.signal, SIGKILL); |
864 | signal_wake_up(t, 1); | 930 | signal_wake_up(t, 1); |
865 | } while_each_thread(p, t); | 931 | } while_each_thread(p, t); |
@@ -909,14 +975,15 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, | |||
909 | if (info == SEND_SIG_FORCED) | 975 | if (info == SEND_SIG_FORCED) |
910 | goto out_set; | 976 | goto out_set; |
911 | 977 | ||
912 | /* Real-time signals must be queued if sent by sigqueue, or | 978 | /* |
913 | some other real-time mechanism. It is implementation | 979 | * Real-time signals must be queued if sent by sigqueue, or |
914 | defined whether kill() does so. We attempt to do so, on | 980 | * some other real-time mechanism. It is implementation |
915 | the principle of least surprise, but since kill is not | 981 | * defined whether kill() does so. We attempt to do so, on |
916 | allowed to fail with EAGAIN when low on memory we just | 982 | * the principle of least surprise, but since kill is not |
917 | make sure at least one signal gets delivered and don't | 983 | * allowed to fail with EAGAIN when low on memory we just |
918 | pass on the info struct. */ | 984 | * make sure at least one signal gets delivered and don't |
919 | 985 | * pass on the info struct. | |
986 | */ | ||
920 | if (sig < SIGRTMIN) | 987 | if (sig < SIGRTMIN) |
921 | override_rlimit = (is_si_special(info) || info->si_code >= 0); | 988 | override_rlimit = (is_si_special(info) || info->si_code >= 0); |
922 | else | 989 | else |
@@ -1093,6 +1160,7 @@ int zap_other_threads(struct task_struct *p) | |||
1093 | p->signal->group_stop_count = 0; | 1160 | p->signal->group_stop_count = 0; |
1094 | 1161 | ||
1095 | while_each_thread(p, t) { | 1162 | while_each_thread(p, t) { |
1163 | task_clear_group_stop_pending(t); | ||
1096 | count++; | 1164 | count++; |
1097 | 1165 | ||
1098 | /* Don't bother with already dead threads */ | 1166 | /* Don't bother with already dead threads */ |
@@ -1187,8 +1255,7 @@ retry: | |||
1187 | return error; | 1255 | return error; |
1188 | } | 1256 | } |
1189 | 1257 | ||
1190 | int | 1258 | int kill_proc_info(int sig, struct siginfo *info, pid_t pid) |
1191 | kill_proc_info(int sig, struct siginfo *info, pid_t pid) | ||
1192 | { | 1259 | { |
1193 | int error; | 1260 | int error; |
1194 | rcu_read_lock(); | 1261 | rcu_read_lock(); |
@@ -1285,8 +1352,7 @@ static int kill_something_info(int sig, struct siginfo *info, pid_t pid) | |||
1285 | * These are for backward compatibility with the rest of the kernel source. | 1352 | * These are for backward compatibility with the rest of the kernel source. |
1286 | */ | 1353 | */ |
1287 | 1354 | ||
1288 | int | 1355 | int send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
1289 | send_sig_info(int sig, struct siginfo *info, struct task_struct *p) | ||
1290 | { | 1356 | { |
1291 | /* | 1357 | /* |
1292 | * Make sure legacy kernel users don't send in bad values | 1358 | * Make sure legacy kernel users don't send in bad values |
@@ -1354,7 +1420,7 @@ EXPORT_SYMBOL(kill_pid); | |||
1354 | * These functions support sending signals using preallocated sigqueue | 1420 | * These functions support sending signals using preallocated sigqueue |
1355 | * structures. This is needed "because realtime applications cannot | 1421 | * structures. This is needed "because realtime applications cannot |
1356 | * afford to lose notifications of asynchronous events, like timer | 1422 | * afford to lose notifications of asynchronous events, like timer |
1357 | * expirations or I/O completions". In the case of Posix Timers | 1423 | * expirations or I/O completions". In the case of POSIX Timers |
1358 | * we allocate the sigqueue structure from the timer_create. If this | 1424 | * we allocate the sigqueue structure from the timer_create. If this |
1359 | * allocation fails we are able to report the failure to the application | 1425 | * allocation fails we are able to report the failure to the application |
1360 | * with an EAGAIN error. | 1426 | * with an EAGAIN error. |
@@ -1522,16 +1588,30 @@ int do_notify_parent(struct task_struct *tsk, int sig) | |||
1522 | return ret; | 1588 | return ret; |
1523 | } | 1589 | } |
1524 | 1590 | ||
1525 | static void do_notify_parent_cldstop(struct task_struct *tsk, int why) | 1591 | /** |
1592 | * do_notify_parent_cldstop - notify parent of stopped/continued state change | ||
1593 | * @tsk: task reporting the state change | ||
1594 | * @for_ptracer: the notification is for ptracer | ||
1595 | * @why: CLD_{CONTINUED|STOPPED|TRAPPED} to report | ||
1596 | * | ||
1597 | * Notify @tsk's parent that the stopped/continued state has changed. If | ||
1598 | * @for_ptracer is %false, @tsk's group leader notifies to its real parent. | ||
1599 | * If %true, @tsk reports to @tsk->parent which should be the ptracer. | ||
1600 | * | ||
1601 | * CONTEXT: | ||
1602 | * Must be called with tasklist_lock at least read locked. | ||
1603 | */ | ||
1604 | static void do_notify_parent_cldstop(struct task_struct *tsk, | ||
1605 | bool for_ptracer, int why) | ||
1526 | { | 1606 | { |
1527 | struct siginfo info; | 1607 | struct siginfo info; |
1528 | unsigned long flags; | 1608 | unsigned long flags; |
1529 | struct task_struct *parent; | 1609 | struct task_struct *parent; |
1530 | struct sighand_struct *sighand; | 1610 | struct sighand_struct *sighand; |
1531 | 1611 | ||
1532 | if (task_ptrace(tsk)) | 1612 | if (for_ptracer) { |
1533 | parent = tsk->parent; | 1613 | parent = tsk->parent; |
1534 | else { | 1614 | } else { |
1535 | tsk = tsk->group_leader; | 1615 | tsk = tsk->group_leader; |
1536 | parent = tsk->real_parent; | 1616 | parent = tsk->real_parent; |
1537 | } | 1617 | } |
@@ -1539,7 +1619,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why) | |||
1539 | info.si_signo = SIGCHLD; | 1619 | info.si_signo = SIGCHLD; |
1540 | info.si_errno = 0; | 1620 | info.si_errno = 0; |
1541 | /* | 1621 | /* |
1542 | * see comment in do_notify_parent() abot the following 3 lines | 1622 | * see comment in do_notify_parent() about the following 4 lines |
1543 | */ | 1623 | */ |
1544 | rcu_read_lock(); | 1624 | rcu_read_lock(); |
1545 | info.si_pid = task_pid_nr_ns(tsk, parent->nsproxy->pid_ns); | 1625 | info.si_pid = task_pid_nr_ns(tsk, parent->nsproxy->pid_ns); |
@@ -1597,7 +1677,7 @@ static inline int may_ptrace_stop(void) | |||
1597 | } | 1677 | } |
1598 | 1678 | ||
1599 | /* | 1679 | /* |
1600 | * Return nonzero if there is a SIGKILL that should be waking us up. | 1680 | * Return non-zero if there is a SIGKILL that should be waking us up. |
1601 | * Called with the siglock held. | 1681 | * Called with the siglock held. |
1602 | */ | 1682 | */ |
1603 | static int sigkill_pending(struct task_struct *tsk) | 1683 | static int sigkill_pending(struct task_struct *tsk) |
@@ -1607,6 +1687,15 @@ static int sigkill_pending(struct task_struct *tsk) | |||
1607 | } | 1687 | } |
1608 | 1688 | ||
1609 | /* | 1689 | /* |
1690 | * Test whether the target task of the usual cldstop notification - the | ||
1691 | * real_parent of @child - is in the same group as the ptracer. | ||
1692 | */ | ||
1693 | static bool real_parent_is_ptracer(struct task_struct *child) | ||
1694 | { | ||
1695 | return same_thread_group(child->parent, child->real_parent); | ||
1696 | } | ||
1697 | |||
1698 | /* | ||
1610 | * This must be called with current->sighand->siglock held. | 1699 | * This must be called with current->sighand->siglock held. |
1611 | * | 1700 | * |
1612 | * This should be the path for all ptrace stops. | 1701 | * This should be the path for all ptrace stops. |
@@ -1617,10 +1706,12 @@ static int sigkill_pending(struct task_struct *tsk) | |||
1617 | * If we actually decide not to stop at all because the tracer | 1706 | * If we actually decide not to stop at all because the tracer |
1618 | * is gone, we keep current->exit_code unless clear_code. | 1707 | * is gone, we keep current->exit_code unless clear_code. |
1619 | */ | 1708 | */ |
1620 | static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | 1709 | static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) |
1621 | __releases(¤t->sighand->siglock) | 1710 | __releases(¤t->sighand->siglock) |
1622 | __acquires(¤t->sighand->siglock) | 1711 | __acquires(¤t->sighand->siglock) |
1623 | { | 1712 | { |
1713 | bool gstop_done = false; | ||
1714 | |||
1624 | if (arch_ptrace_stop_needed(exit_code, info)) { | 1715 | if (arch_ptrace_stop_needed(exit_code, info)) { |
1625 | /* | 1716 | /* |
1626 | * The arch code has something special to do before a | 1717 | * The arch code has something special to do before a |
@@ -1641,21 +1732,49 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | |||
1641 | } | 1732 | } |
1642 | 1733 | ||
1643 | /* | 1734 | /* |
1644 | * If there is a group stop in progress, | 1735 | * If @why is CLD_STOPPED, we're trapping to participate in a group |
1645 | * we must participate in the bookkeeping. | 1736 | * stop. Do the bookkeeping. Note that if SIGCONT was delievered |
1737 | * while siglock was released for the arch hook, PENDING could be | ||
1738 | * clear now. We act as if SIGCONT is received after TASK_TRACED | ||
1739 | * is entered - ignore it. | ||
1646 | */ | 1740 | */ |
1647 | if (current->signal->group_stop_count > 0) | 1741 | if (why == CLD_STOPPED && (current->group_stop & GROUP_STOP_PENDING)) |
1648 | --current->signal->group_stop_count; | 1742 | gstop_done = task_participate_group_stop(current); |
1649 | 1743 | ||
1650 | current->last_siginfo = info; | 1744 | current->last_siginfo = info; |
1651 | current->exit_code = exit_code; | 1745 | current->exit_code = exit_code; |
1652 | 1746 | ||
1653 | /* Let the debugger run. */ | 1747 | /* |
1654 | __set_current_state(TASK_TRACED); | 1748 | * TRACED should be visible before TRAPPING is cleared; otherwise, |
1749 | * the tracer might fail do_wait(). | ||
1750 | */ | ||
1751 | set_current_state(TASK_TRACED); | ||
1752 | |||
1753 | /* | ||
1754 | * We're committing to trapping. Clearing GROUP_STOP_TRAPPING and | ||
1755 | * transition to TASK_TRACED should be atomic with respect to | ||
1756 | * siglock. This hsould be done after the arch hook as siglock is | ||
1757 | * released and regrabbed across it. | ||
1758 | */ | ||
1759 | task_clear_group_stop_trapping(current); | ||
1760 | |||
1655 | spin_unlock_irq(¤t->sighand->siglock); | 1761 | spin_unlock_irq(¤t->sighand->siglock); |
1656 | read_lock(&tasklist_lock); | 1762 | read_lock(&tasklist_lock); |
1657 | if (may_ptrace_stop()) { | 1763 | if (may_ptrace_stop()) { |
1658 | do_notify_parent_cldstop(current, CLD_TRAPPED); | 1764 | /* |
1765 | * Notify parents of the stop. | ||
1766 | * | ||
1767 | * While ptraced, there are two parents - the ptracer and | ||
1768 | * the real_parent of the group_leader. The ptracer should | ||
1769 | * know about every stop while the real parent is only | ||
1770 | * interested in the completion of group stop. The states | ||
1771 | * for the two don't interact with each other. Notify | ||
1772 | * separately unless they're gonna be duplicates. | ||
1773 | */ | ||
1774 | do_notify_parent_cldstop(current, true, why); | ||
1775 | if (gstop_done && !real_parent_is_ptracer(current)) | ||
1776 | do_notify_parent_cldstop(current, false, why); | ||
1777 | |||
1659 | /* | 1778 | /* |
1660 | * Don't want to allow preemption here, because | 1779 | * Don't want to allow preemption here, because |
1661 | * sys_ptrace() needs this task to be inactive. | 1780 | * sys_ptrace() needs this task to be inactive. |
@@ -1670,7 +1789,16 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | |||
1670 | /* | 1789 | /* |
1671 | * By the time we got the lock, our tracer went away. | 1790 | * By the time we got the lock, our tracer went away. |
1672 | * Don't drop the lock yet, another tracer may come. | 1791 | * Don't drop the lock yet, another tracer may come. |
1792 | * | ||
1793 | * If @gstop_done, the ptracer went away between group stop | ||
1794 | * completion and here. During detach, it would have set | ||
1795 | * GROUP_STOP_PENDING on us and we'll re-enter TASK_STOPPED | ||
1796 | * in do_signal_stop() on return, so notifying the real | ||
1797 | * parent of the group stop completion is enough. | ||
1673 | */ | 1798 | */ |
1799 | if (gstop_done) | ||
1800 | do_notify_parent_cldstop(current, false, why); | ||
1801 | |||
1674 | __set_current_state(TASK_RUNNING); | 1802 | __set_current_state(TASK_RUNNING); |
1675 | if (clear_code) | 1803 | if (clear_code) |
1676 | current->exit_code = 0; | 1804 | current->exit_code = 0; |
@@ -1714,79 +1842,128 @@ void ptrace_notify(int exit_code) | |||
1714 | 1842 | ||
1715 | /* Let the debugger run. */ | 1843 | /* Let the debugger run. */ |
1716 | spin_lock_irq(¤t->sighand->siglock); | 1844 | spin_lock_irq(¤t->sighand->siglock); |
1717 | ptrace_stop(exit_code, 1, &info); | 1845 | ptrace_stop(exit_code, CLD_TRAPPED, 1, &info); |
1718 | spin_unlock_irq(¤t->sighand->siglock); | 1846 | spin_unlock_irq(¤t->sighand->siglock); |
1719 | } | 1847 | } |
1720 | 1848 | ||
1721 | /* | 1849 | /* |
1722 | * This performs the stopping for SIGSTOP and other stop signals. | 1850 | * This performs the stopping for SIGSTOP and other stop signals. |
1723 | * We have to stop all threads in the thread group. | 1851 | * We have to stop all threads in the thread group. |
1724 | * Returns nonzero if we've actually stopped and released the siglock. | 1852 | * Returns non-zero if we've actually stopped and released the siglock. |
1725 | * Returns zero if we didn't stop and still hold the siglock. | 1853 | * Returns zero if we didn't stop and still hold the siglock. |
1726 | */ | 1854 | */ |
1727 | static int do_signal_stop(int signr) | 1855 | static int do_signal_stop(int signr) |
1728 | { | 1856 | { |
1729 | struct signal_struct *sig = current->signal; | 1857 | struct signal_struct *sig = current->signal; |
1730 | int notify; | ||
1731 | 1858 | ||
1732 | if (!sig->group_stop_count) { | 1859 | if (!(current->group_stop & GROUP_STOP_PENDING)) { |
1860 | unsigned int gstop = GROUP_STOP_PENDING | GROUP_STOP_CONSUME; | ||
1733 | struct task_struct *t; | 1861 | struct task_struct *t; |
1734 | 1862 | ||
1735 | if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || | 1863 | /* signr will be recorded in task->group_stop for retries */ |
1864 | WARN_ON_ONCE(signr & ~GROUP_STOP_SIGMASK); | ||
1865 | |||
1866 | if (!likely(current->group_stop & GROUP_STOP_DEQUEUED) || | ||
1736 | unlikely(signal_group_exit(sig))) | 1867 | unlikely(signal_group_exit(sig))) |
1737 | return 0; | 1868 | return 0; |
1738 | /* | 1869 | /* |
1739 | * There is no group stop already in progress. | 1870 | * There is no group stop already in progress. We must |
1740 | * We must initiate one now. | 1871 | * initiate one now. |
1872 | * | ||
1873 | * While ptraced, a task may be resumed while group stop is | ||
1874 | * still in effect and then receive a stop signal and | ||
1875 | * initiate another group stop. This deviates from the | ||
1876 | * usual behavior as two consecutive stop signals can't | ||
1877 | * cause two group stops when !ptraced. That is why we | ||
1878 | * also check !task_is_stopped(t) below. | ||
1879 | * | ||
1880 | * The condition can be distinguished by testing whether | ||
1881 | * SIGNAL_STOP_STOPPED is already set. Don't generate | ||
1882 | * group_exit_code in such case. | ||
1883 | * | ||
1884 | * This is not necessary for SIGNAL_STOP_CONTINUED because | ||
1885 | * an intervening stop signal is required to cause two | ||
1886 | * continued events regardless of ptrace. | ||
1741 | */ | 1887 | */ |
1742 | sig->group_exit_code = signr; | 1888 | if (!(sig->flags & SIGNAL_STOP_STOPPED)) |
1889 | sig->group_exit_code = signr; | ||
1890 | else | ||
1891 | WARN_ON_ONCE(!task_ptrace(current)); | ||
1743 | 1892 | ||
1893 | current->group_stop &= ~GROUP_STOP_SIGMASK; | ||
1894 | current->group_stop |= signr | gstop; | ||
1744 | sig->group_stop_count = 1; | 1895 | sig->group_stop_count = 1; |
1745 | for (t = next_thread(current); t != current; t = next_thread(t)) | 1896 | for (t = next_thread(current); t != current; |
1897 | t = next_thread(t)) { | ||
1898 | t->group_stop &= ~GROUP_STOP_SIGMASK; | ||
1746 | /* | 1899 | /* |
1747 | * Setting state to TASK_STOPPED for a group | 1900 | * Setting state to TASK_STOPPED for a group |
1748 | * stop is always done with the siglock held, | 1901 | * stop is always done with the siglock held, |
1749 | * so this check has no races. | 1902 | * so this check has no races. |
1750 | */ | 1903 | */ |
1751 | if (!(t->flags & PF_EXITING) && | 1904 | if (!(t->flags & PF_EXITING) && !task_is_stopped(t)) { |
1752 | !task_is_stopped_or_traced(t)) { | 1905 | t->group_stop |= signr | gstop; |
1753 | sig->group_stop_count++; | 1906 | sig->group_stop_count++; |
1754 | signal_wake_up(t, 0); | 1907 | signal_wake_up(t, 0); |
1755 | } | 1908 | } |
1909 | } | ||
1756 | } | 1910 | } |
1757 | /* | 1911 | retry: |
1758 | * If there are no other threads in the group, or if there is | 1912 | if (likely(!task_ptrace(current))) { |
1759 | * a group stop in progress and we are the last to stop, report | 1913 | int notify = 0; |
1760 | * to the parent. When ptraced, every thread reports itself. | 1914 | |
1761 | */ | 1915 | /* |
1762 | notify = sig->group_stop_count == 1 ? CLD_STOPPED : 0; | 1916 | * If there are no other threads in the group, or if there |
1763 | notify = tracehook_notify_jctl(notify, CLD_STOPPED); | 1917 | * is a group stop in progress and we are the last to stop, |
1764 | /* | 1918 | * report to the parent. |
1765 | * tracehook_notify_jctl() can drop and reacquire siglock, so | 1919 | */ |
1766 | * we keep ->group_stop_count != 0 before the call. If SIGCONT | 1920 | if (task_participate_group_stop(current)) |
1767 | * or SIGKILL comes in between ->group_stop_count == 0. | 1921 | notify = CLD_STOPPED; |
1768 | */ | 1922 | |
1769 | if (sig->group_stop_count) { | ||
1770 | if (!--sig->group_stop_count) | ||
1771 | sig->flags = SIGNAL_STOP_STOPPED; | ||
1772 | current->exit_code = sig->group_exit_code; | ||
1773 | __set_current_state(TASK_STOPPED); | 1923 | __set_current_state(TASK_STOPPED); |
1924 | spin_unlock_irq(¤t->sighand->siglock); | ||
1925 | |||
1926 | /* | ||
1927 | * Notify the parent of the group stop completion. Because | ||
1928 | * we're not holding either the siglock or tasklist_lock | ||
1929 | * here, ptracer may attach inbetween; however, this is for | ||
1930 | * group stop and should always be delivered to the real | ||
1931 | * parent of the group leader. The new ptracer will get | ||
1932 | * its notification when this task transitions into | ||
1933 | * TASK_TRACED. | ||
1934 | */ | ||
1935 | if (notify) { | ||
1936 | read_lock(&tasklist_lock); | ||
1937 | do_notify_parent_cldstop(current, false, notify); | ||
1938 | read_unlock(&tasklist_lock); | ||
1939 | } | ||
1940 | |||
1941 | /* Now we don't run again until woken by SIGCONT or SIGKILL */ | ||
1942 | schedule(); | ||
1943 | |||
1944 | spin_lock_irq(¤t->sighand->siglock); | ||
1945 | } else { | ||
1946 | ptrace_stop(current->group_stop & GROUP_STOP_SIGMASK, | ||
1947 | CLD_STOPPED, 0, NULL); | ||
1948 | current->exit_code = 0; | ||
1774 | } | 1949 | } |
1775 | spin_unlock_irq(¤t->sighand->siglock); | ||
1776 | 1950 | ||
1777 | if (notify) { | 1951 | /* |
1778 | read_lock(&tasklist_lock); | 1952 | * GROUP_STOP_PENDING could be set if another group stop has |
1779 | do_notify_parent_cldstop(current, notify); | 1953 | * started since being woken up or ptrace wants us to transit |
1780 | read_unlock(&tasklist_lock); | 1954 | * between TASK_STOPPED and TRACED. Retry group stop. |
1955 | */ | ||
1956 | if (current->group_stop & GROUP_STOP_PENDING) { | ||
1957 | WARN_ON_ONCE(!(current->group_stop & GROUP_STOP_SIGMASK)); | ||
1958 | goto retry; | ||
1781 | } | 1959 | } |
1782 | 1960 | ||
1783 | /* Now we don't run again until woken by SIGCONT or SIGKILL */ | 1961 | /* PTRACE_ATTACH might have raced with task killing, clear trapping */ |
1784 | do { | 1962 | task_clear_group_stop_trapping(current); |
1785 | schedule(); | 1963 | |
1786 | } while (try_to_freeze()); | 1964 | spin_unlock_irq(¤t->sighand->siglock); |
1787 | 1965 | ||
1788 | tracehook_finish_jctl(); | 1966 | tracehook_finish_jctl(); |
1789 | current->exit_code = 0; | ||
1790 | 1967 | ||
1791 | return 1; | 1968 | return 1; |
1792 | } | 1969 | } |
@@ -1800,7 +1977,7 @@ static int ptrace_signal(int signr, siginfo_t *info, | |||
1800 | ptrace_signal_deliver(regs, cookie); | 1977 | ptrace_signal_deliver(regs, cookie); |
1801 | 1978 | ||
1802 | /* Let the debugger run. */ | 1979 | /* Let the debugger run. */ |
1803 | ptrace_stop(signr, 0, info); | 1980 | ptrace_stop(signr, CLD_TRAPPED, 0, info); |
1804 | 1981 | ||
1805 | /* We're back. Did the debugger cancel the sig? */ | 1982 | /* We're back. Did the debugger cancel the sig? */ |
1806 | signr = current->exit_code; | 1983 | signr = current->exit_code; |
@@ -1809,10 +1986,12 @@ static int ptrace_signal(int signr, siginfo_t *info, | |||
1809 | 1986 | ||
1810 | current->exit_code = 0; | 1987 | current->exit_code = 0; |
1811 | 1988 | ||
1812 | /* Update the siginfo structure if the signal has | 1989 | /* |
1813 | changed. If the debugger wanted something | 1990 | * Update the siginfo structure if the signal has |
1814 | specific in the siginfo structure then it should | 1991 | * changed. If the debugger wanted something |
1815 | have updated *info via PTRACE_SETSIGINFO. */ | 1992 | * specific in the siginfo structure then it should |
1993 | * have updated *info via PTRACE_SETSIGINFO. | ||
1994 | */ | ||
1816 | if (signr != info->si_signo) { | 1995 | if (signr != info->si_signo) { |
1817 | info->si_signo = signr; | 1996 | info->si_signo = signr; |
1818 | info->si_errno = 0; | 1997 | info->si_errno = 0; |
@@ -1853,25 +2032,43 @@ relock: | |||
1853 | * the CLD_ si_code into SIGNAL_CLD_MASK bits. | 2032 | * the CLD_ si_code into SIGNAL_CLD_MASK bits. |
1854 | */ | 2033 | */ |
1855 | if (unlikely(signal->flags & SIGNAL_CLD_MASK)) { | 2034 | if (unlikely(signal->flags & SIGNAL_CLD_MASK)) { |
1856 | int why = (signal->flags & SIGNAL_STOP_CONTINUED) | 2035 | struct task_struct *leader; |
1857 | ? CLD_CONTINUED : CLD_STOPPED; | 2036 | int why; |
2037 | |||
2038 | if (signal->flags & SIGNAL_CLD_CONTINUED) | ||
2039 | why = CLD_CONTINUED; | ||
2040 | else | ||
2041 | why = CLD_STOPPED; | ||
2042 | |||
1858 | signal->flags &= ~SIGNAL_CLD_MASK; | 2043 | signal->flags &= ~SIGNAL_CLD_MASK; |
1859 | 2044 | ||
1860 | why = tracehook_notify_jctl(why, CLD_CONTINUED); | ||
1861 | spin_unlock_irq(&sighand->siglock); | 2045 | spin_unlock_irq(&sighand->siglock); |
1862 | 2046 | ||
1863 | if (why) { | 2047 | /* |
1864 | read_lock(&tasklist_lock); | 2048 | * Notify the parent that we're continuing. This event is |
1865 | do_notify_parent_cldstop(current->group_leader, why); | 2049 | * always per-process and doesn't make whole lot of sense |
1866 | read_unlock(&tasklist_lock); | 2050 | * for ptracers, who shouldn't consume the state via |
1867 | } | 2051 | * wait(2) either, but, for backward compatibility, notify |
2052 | * the ptracer of the group leader too unless it's gonna be | ||
2053 | * a duplicate. | ||
2054 | */ | ||
2055 | read_lock(&tasklist_lock); | ||
2056 | |||
2057 | do_notify_parent_cldstop(current, false, why); | ||
2058 | |||
2059 | leader = current->group_leader; | ||
2060 | if (task_ptrace(leader) && !real_parent_is_ptracer(leader)) | ||
2061 | do_notify_parent_cldstop(leader, true, why); | ||
2062 | |||
2063 | read_unlock(&tasklist_lock); | ||
2064 | |||
1868 | goto relock; | 2065 | goto relock; |
1869 | } | 2066 | } |
1870 | 2067 | ||
1871 | for (;;) { | 2068 | for (;;) { |
1872 | struct k_sigaction *ka; | 2069 | struct k_sigaction *ka; |
1873 | /* | 2070 | /* |
1874 | * Tracing can induce an artifical signal and choose sigaction. | 2071 | * Tracing can induce an artificial signal and choose sigaction. |
1875 | * The return value in @signr determines the default action, | 2072 | * The return value in @signr determines the default action, |
1876 | * but @info->si_signo is the signal number we will report. | 2073 | * but @info->si_signo is the signal number we will report. |
1877 | */ | 2074 | */ |
@@ -1881,8 +2078,8 @@ relock: | |||
1881 | if (unlikely(signr != 0)) | 2078 | if (unlikely(signr != 0)) |
1882 | ka = return_ka; | 2079 | ka = return_ka; |
1883 | else { | 2080 | else { |
1884 | if (unlikely(signal->group_stop_count > 0) && | 2081 | if (unlikely(current->group_stop & |
1885 | do_signal_stop(0)) | 2082 | GROUP_STOP_PENDING) && do_signal_stop(0)) |
1886 | goto relock; | 2083 | goto relock; |
1887 | 2084 | ||
1888 | signr = dequeue_signal(current, ¤t->blocked, | 2085 | signr = dequeue_signal(current, ¤t->blocked, |
@@ -2001,10 +2198,42 @@ relock: | |||
2001 | return signr; | 2198 | return signr; |
2002 | } | 2199 | } |
2003 | 2200 | ||
2201 | /* | ||
2202 | * It could be that complete_signal() picked us to notify about the | ||
2203 | * group-wide signal. Other threads should be notified now to take | ||
2204 | * the shared signals in @which since we will not. | ||
2205 | */ | ||
2206 | static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which) | ||
2207 | { | ||
2208 | sigset_t retarget; | ||
2209 | struct task_struct *t; | ||
2210 | |||
2211 | sigandsets(&retarget, &tsk->signal->shared_pending.signal, which); | ||
2212 | if (sigisemptyset(&retarget)) | ||
2213 | return; | ||
2214 | |||
2215 | t = tsk; | ||
2216 | while_each_thread(tsk, t) { | ||
2217 | if (t->flags & PF_EXITING) | ||
2218 | continue; | ||
2219 | |||
2220 | if (!has_pending_signals(&retarget, &t->blocked)) | ||
2221 | continue; | ||
2222 | /* Remove the signals this thread can handle. */ | ||
2223 | sigandsets(&retarget, &retarget, &t->blocked); | ||
2224 | |||
2225 | if (!signal_pending(t)) | ||
2226 | signal_wake_up(t, 0); | ||
2227 | |||
2228 | if (sigisemptyset(&retarget)) | ||
2229 | break; | ||
2230 | } | ||
2231 | } | ||
2232 | |||
2004 | void exit_signals(struct task_struct *tsk) | 2233 | void exit_signals(struct task_struct *tsk) |
2005 | { | 2234 | { |
2006 | int group_stop = 0; | 2235 | int group_stop = 0; |
2007 | struct task_struct *t; | 2236 | sigset_t unblocked; |
2008 | 2237 | ||
2009 | if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) { | 2238 | if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) { |
2010 | tsk->flags |= PF_EXITING; | 2239 | tsk->flags |= PF_EXITING; |
@@ -2020,25 +2249,23 @@ void exit_signals(struct task_struct *tsk) | |||
2020 | if (!signal_pending(tsk)) | 2249 | if (!signal_pending(tsk)) |
2021 | goto out; | 2250 | goto out; |
2022 | 2251 | ||
2023 | /* It could be that __group_complete_signal() choose us to | 2252 | unblocked = tsk->blocked; |
2024 | * notify about group-wide signal. Another thread should be | 2253 | signotset(&unblocked); |
2025 | * woken now to take the signal since we will not. | 2254 | retarget_shared_pending(tsk, &unblocked); |
2026 | */ | ||
2027 | for (t = tsk; (t = next_thread(t)) != tsk; ) | ||
2028 | if (!signal_pending(t) && !(t->flags & PF_EXITING)) | ||
2029 | recalc_sigpending_and_wake(t); | ||
2030 | 2255 | ||
2031 | if (unlikely(tsk->signal->group_stop_count) && | 2256 | if (unlikely(tsk->group_stop & GROUP_STOP_PENDING) && |
2032 | !--tsk->signal->group_stop_count) { | 2257 | task_participate_group_stop(tsk)) |
2033 | tsk->signal->flags = SIGNAL_STOP_STOPPED; | 2258 | group_stop = CLD_STOPPED; |
2034 | group_stop = tracehook_notify_jctl(CLD_STOPPED, CLD_STOPPED); | ||
2035 | } | ||
2036 | out: | 2259 | out: |
2037 | spin_unlock_irq(&tsk->sighand->siglock); | 2260 | spin_unlock_irq(&tsk->sighand->siglock); |
2038 | 2261 | ||
2262 | /* | ||
2263 | * If group stop has completed, deliver the notification. This | ||
2264 | * should always go to the real parent of the group leader. | ||
2265 | */ | ||
2039 | if (unlikely(group_stop)) { | 2266 | if (unlikely(group_stop)) { |
2040 | read_lock(&tasklist_lock); | 2267 | read_lock(&tasklist_lock); |
2041 | do_notify_parent_cldstop(tsk, group_stop); | 2268 | do_notify_parent_cldstop(tsk, false, group_stop); |
2042 | read_unlock(&tasklist_lock); | 2269 | read_unlock(&tasklist_lock); |
2043 | } | 2270 | } |
2044 | } | 2271 | } |
@@ -2058,6 +2285,9 @@ EXPORT_SYMBOL(unblock_all_signals); | |||
2058 | * System call entry points. | 2285 | * System call entry points. |
2059 | */ | 2286 | */ |
2060 | 2287 | ||
2288 | /** | ||
2289 | * sys_restart_syscall - restart a system call | ||
2290 | */ | ||
2061 | SYSCALL_DEFINE0(restart_syscall) | 2291 | SYSCALL_DEFINE0(restart_syscall) |
2062 | { | 2292 | { |
2063 | struct restart_block *restart = ¤t_thread_info()->restart_block; | 2293 | struct restart_block *restart = ¤t_thread_info()->restart_block; |
@@ -2069,11 +2299,33 @@ long do_no_restart_syscall(struct restart_block *param) | |||
2069 | return -EINTR; | 2299 | return -EINTR; |
2070 | } | 2300 | } |
2071 | 2301 | ||
2072 | /* | 2302 | static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset) |
2073 | * We don't need to get the kernel lock - this is all local to this | 2303 | { |
2074 | * particular thread.. (and that's good, because this is _heavily_ | 2304 | if (signal_pending(tsk) && !thread_group_empty(tsk)) { |
2075 | * used by various programs) | 2305 | sigset_t newblocked; |
2306 | /* A set of now blocked but previously unblocked signals. */ | ||
2307 | sigandnsets(&newblocked, newset, ¤t->blocked); | ||
2308 | retarget_shared_pending(tsk, &newblocked); | ||
2309 | } | ||
2310 | tsk->blocked = *newset; | ||
2311 | recalc_sigpending(); | ||
2312 | } | ||
2313 | |||
2314 | /** | ||
2315 | * set_current_blocked - change current->blocked mask | ||
2316 | * @newset: new mask | ||
2317 | * | ||
2318 | * It is wrong to change ->blocked directly, this helper should be used | ||
2319 | * to ensure the process can't miss a shared signal we are going to block. | ||
2076 | */ | 2320 | */ |
2321 | void set_current_blocked(const sigset_t *newset) | ||
2322 | { | ||
2323 | struct task_struct *tsk = current; | ||
2324 | |||
2325 | spin_lock_irq(&tsk->sighand->siglock); | ||
2326 | __set_task_blocked(tsk, newset); | ||
2327 | spin_unlock_irq(&tsk->sighand->siglock); | ||
2328 | } | ||
2077 | 2329 | ||
2078 | /* | 2330 | /* |
2079 | * This is also useful for kernel threads that want to temporarily | 2331 | * This is also useful for kernel threads that want to temporarily |
@@ -2085,66 +2337,66 @@ long do_no_restart_syscall(struct restart_block *param) | |||
2085 | */ | 2337 | */ |
2086 | int sigprocmask(int how, sigset_t *set, sigset_t *oldset) | 2338 | int sigprocmask(int how, sigset_t *set, sigset_t *oldset) |
2087 | { | 2339 | { |
2088 | int error; | 2340 | struct task_struct *tsk = current; |
2341 | sigset_t newset; | ||
2089 | 2342 | ||
2090 | spin_lock_irq(¤t->sighand->siglock); | 2343 | /* Lockless, only current can change ->blocked, never from irq */ |
2091 | if (oldset) | 2344 | if (oldset) |
2092 | *oldset = current->blocked; | 2345 | *oldset = tsk->blocked; |
2093 | 2346 | ||
2094 | error = 0; | ||
2095 | switch (how) { | 2347 | switch (how) { |
2096 | case SIG_BLOCK: | 2348 | case SIG_BLOCK: |
2097 | sigorsets(¤t->blocked, ¤t->blocked, set); | 2349 | sigorsets(&newset, &tsk->blocked, set); |
2098 | break; | 2350 | break; |
2099 | case SIG_UNBLOCK: | 2351 | case SIG_UNBLOCK: |
2100 | signandsets(¤t->blocked, ¤t->blocked, set); | 2352 | sigandnsets(&newset, &tsk->blocked, set); |
2101 | break; | 2353 | break; |
2102 | case SIG_SETMASK: | 2354 | case SIG_SETMASK: |
2103 | current->blocked = *set; | 2355 | newset = *set; |
2104 | break; | 2356 | break; |
2105 | default: | 2357 | default: |
2106 | error = -EINVAL; | 2358 | return -EINVAL; |
2107 | } | 2359 | } |
2108 | recalc_sigpending(); | ||
2109 | spin_unlock_irq(¤t->sighand->siglock); | ||
2110 | 2360 | ||
2111 | return error; | 2361 | set_current_blocked(&newset); |
2362 | return 0; | ||
2112 | } | 2363 | } |
2113 | 2364 | ||
2114 | SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, set, | 2365 | /** |
2366 | * sys_rt_sigprocmask - change the list of currently blocked signals | ||
2367 | * @how: whether to add, remove, or set signals | ||
2368 | * @set: stores pending signals | ||
2369 | * @oset: previous value of signal mask if non-null | ||
2370 | * @sigsetsize: size of sigset_t type | ||
2371 | */ | ||
2372 | SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, nset, | ||
2115 | sigset_t __user *, oset, size_t, sigsetsize) | 2373 | sigset_t __user *, oset, size_t, sigsetsize) |
2116 | { | 2374 | { |
2117 | int error = -EINVAL; | ||
2118 | sigset_t old_set, new_set; | 2375 | sigset_t old_set, new_set; |
2376 | int error; | ||
2119 | 2377 | ||
2120 | /* XXX: Don't preclude handling different sized sigset_t's. */ | 2378 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
2121 | if (sigsetsize != sizeof(sigset_t)) | 2379 | if (sigsetsize != sizeof(sigset_t)) |
2122 | goto out; | 2380 | return -EINVAL; |
2123 | 2381 | ||
2124 | if (set) { | 2382 | old_set = current->blocked; |
2125 | error = -EFAULT; | 2383 | |
2126 | if (copy_from_user(&new_set, set, sizeof(*set))) | 2384 | if (nset) { |
2127 | goto out; | 2385 | if (copy_from_user(&new_set, nset, sizeof(sigset_t))) |
2386 | return -EFAULT; | ||
2128 | sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); | 2387 | sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
2129 | 2388 | ||
2130 | error = sigprocmask(how, &new_set, &old_set); | 2389 | error = sigprocmask(how, &new_set, NULL); |
2131 | if (error) | 2390 | if (error) |
2132 | goto out; | 2391 | return error; |
2133 | if (oset) | 2392 | } |
2134 | goto set_old; | ||
2135 | } else if (oset) { | ||
2136 | spin_lock_irq(¤t->sighand->siglock); | ||
2137 | old_set = current->blocked; | ||
2138 | spin_unlock_irq(¤t->sighand->siglock); | ||
2139 | 2393 | ||
2140 | set_old: | 2394 | if (oset) { |
2141 | error = -EFAULT; | 2395 | if (copy_to_user(oset, &old_set, sizeof(sigset_t))) |
2142 | if (copy_to_user(oset, &old_set, sizeof(*oset))) | 2396 | return -EFAULT; |
2143 | goto out; | ||
2144 | } | 2397 | } |
2145 | error = 0; | 2398 | |
2146 | out: | 2399 | return 0; |
2147 | return error; | ||
2148 | } | 2400 | } |
2149 | 2401 | ||
2150 | long do_sigpending(void __user *set, unsigned long sigsetsize) | 2402 | long do_sigpending(void __user *set, unsigned long sigsetsize) |
@@ -2169,8 +2421,14 @@ long do_sigpending(void __user *set, unsigned long sigsetsize) | |||
2169 | 2421 | ||
2170 | out: | 2422 | out: |
2171 | return error; | 2423 | return error; |
2172 | } | 2424 | } |
2173 | 2425 | ||
2426 | /** | ||
2427 | * sys_rt_sigpending - examine a pending signal that has been raised | ||
2428 | * while blocked | ||
2429 | * @set: stores pending signals | ||
2430 | * @sigsetsize: size of sigset_t type or larger | ||
2431 | */ | ||
2174 | SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize) | 2432 | SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize) |
2175 | { | 2433 | { |
2176 | return do_sigpending(set, sigsetsize); | 2434 | return do_sigpending(set, sigsetsize); |
@@ -2219,9 +2477,9 @@ int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from) | |||
2219 | err |= __put_user(from->si_trapno, &to->si_trapno); | 2477 | err |= __put_user(from->si_trapno, &to->si_trapno); |
2220 | #endif | 2478 | #endif |
2221 | #ifdef BUS_MCEERR_AO | 2479 | #ifdef BUS_MCEERR_AO |
2222 | /* | 2480 | /* |
2223 | * Other callers might not initialize the si_lsb field, | 2481 | * Other callers might not initialize the si_lsb field, |
2224 | * so check explicitely for the right codes here. | 2482 | * so check explicitly for the right codes here. |
2225 | */ | 2483 | */ |
2226 | if (from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO) | 2484 | if (from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO) |
2227 | err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb); | 2485 | err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb); |
@@ -2250,15 +2508,82 @@ int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from) | |||
2250 | 2508 | ||
2251 | #endif | 2509 | #endif |
2252 | 2510 | ||
2511 | /** | ||
2512 | * do_sigtimedwait - wait for queued signals specified in @which | ||
2513 | * @which: queued signals to wait for | ||
2514 | * @info: if non-null, the signal's siginfo is returned here | ||
2515 | * @ts: upper bound on process time suspension | ||
2516 | */ | ||
2517 | int do_sigtimedwait(const sigset_t *which, siginfo_t *info, | ||
2518 | const struct timespec *ts) | ||
2519 | { | ||
2520 | struct task_struct *tsk = current; | ||
2521 | long timeout = MAX_SCHEDULE_TIMEOUT; | ||
2522 | sigset_t mask = *which; | ||
2523 | int sig; | ||
2524 | |||
2525 | if (ts) { | ||
2526 | if (!timespec_valid(ts)) | ||
2527 | return -EINVAL; | ||
2528 | timeout = timespec_to_jiffies(ts); | ||
2529 | /* | ||
2530 | * We can be close to the next tick, add another one | ||
2531 | * to ensure we will wait at least the time asked for. | ||
2532 | */ | ||
2533 | if (ts->tv_sec || ts->tv_nsec) | ||
2534 | timeout++; | ||
2535 | } | ||
2536 | |||
2537 | /* | ||
2538 | * Invert the set of allowed signals to get those we want to block. | ||
2539 | */ | ||
2540 | sigdelsetmask(&mask, sigmask(SIGKILL) | sigmask(SIGSTOP)); | ||
2541 | signotset(&mask); | ||
2542 | |||
2543 | spin_lock_irq(&tsk->sighand->siglock); | ||
2544 | sig = dequeue_signal(tsk, &mask, info); | ||
2545 | if (!sig && timeout) { | ||
2546 | /* | ||
2547 | * None ready, temporarily unblock those we're interested | ||
2548 | * while we are sleeping in so that we'll be awakened when | ||
2549 | * they arrive. Unblocking is always fine, we can avoid | ||
2550 | * set_current_blocked(). | ||
2551 | */ | ||
2552 | tsk->real_blocked = tsk->blocked; | ||
2553 | sigandsets(&tsk->blocked, &tsk->blocked, &mask); | ||
2554 | recalc_sigpending(); | ||
2555 | spin_unlock_irq(&tsk->sighand->siglock); | ||
2556 | |||
2557 | timeout = schedule_timeout_interruptible(timeout); | ||
2558 | |||
2559 | spin_lock_irq(&tsk->sighand->siglock); | ||
2560 | __set_task_blocked(tsk, &tsk->real_blocked); | ||
2561 | siginitset(&tsk->real_blocked, 0); | ||
2562 | sig = dequeue_signal(tsk, &mask, info); | ||
2563 | } | ||
2564 | spin_unlock_irq(&tsk->sighand->siglock); | ||
2565 | |||
2566 | if (sig) | ||
2567 | return sig; | ||
2568 | return timeout ? -EINTR : -EAGAIN; | ||
2569 | } | ||
2570 | |||
2571 | /** | ||
2572 | * sys_rt_sigtimedwait - synchronously wait for queued signals specified | ||
2573 | * in @uthese | ||
2574 | * @uthese: queued signals to wait for | ||
2575 | * @uinfo: if non-null, the signal's siginfo is returned here | ||
2576 | * @uts: upper bound on process time suspension | ||
2577 | * @sigsetsize: size of sigset_t type | ||
2578 | */ | ||
2253 | SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, | 2579 | SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, |
2254 | siginfo_t __user *, uinfo, const struct timespec __user *, uts, | 2580 | siginfo_t __user *, uinfo, const struct timespec __user *, uts, |
2255 | size_t, sigsetsize) | 2581 | size_t, sigsetsize) |
2256 | { | 2582 | { |
2257 | int ret, sig; | ||
2258 | sigset_t these; | 2583 | sigset_t these; |
2259 | struct timespec ts; | 2584 | struct timespec ts; |
2260 | siginfo_t info; | 2585 | siginfo_t info; |
2261 | long timeout = 0; | 2586 | int ret; |
2262 | 2587 | ||
2263 | /* XXX: Don't preclude handling different sized sigset_t's. */ | 2588 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
2264 | if (sigsetsize != sizeof(sigset_t)) | 2589 | if (sigsetsize != sizeof(sigset_t)) |
@@ -2266,65 +2591,27 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, | |||
2266 | 2591 | ||
2267 | if (copy_from_user(&these, uthese, sizeof(these))) | 2592 | if (copy_from_user(&these, uthese, sizeof(these))) |
2268 | return -EFAULT; | 2593 | return -EFAULT; |
2269 | |||
2270 | /* | ||
2271 | * Invert the set of allowed signals to get those we | ||
2272 | * want to block. | ||
2273 | */ | ||
2274 | sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP)); | ||
2275 | signotset(&these); | ||
2276 | 2594 | ||
2277 | if (uts) { | 2595 | if (uts) { |
2278 | if (copy_from_user(&ts, uts, sizeof(ts))) | 2596 | if (copy_from_user(&ts, uts, sizeof(ts))) |
2279 | return -EFAULT; | 2597 | return -EFAULT; |
2280 | if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0 | ||
2281 | || ts.tv_sec < 0) | ||
2282 | return -EINVAL; | ||
2283 | } | 2598 | } |
2284 | 2599 | ||
2285 | spin_lock_irq(¤t->sighand->siglock); | 2600 | ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL); |
2286 | sig = dequeue_signal(current, &these, &info); | ||
2287 | if (!sig) { | ||
2288 | timeout = MAX_SCHEDULE_TIMEOUT; | ||
2289 | if (uts) | ||
2290 | timeout = (timespec_to_jiffies(&ts) | ||
2291 | + (ts.tv_sec || ts.tv_nsec)); | ||
2292 | |||
2293 | if (timeout) { | ||
2294 | /* None ready -- temporarily unblock those we're | ||
2295 | * interested while we are sleeping in so that we'll | ||
2296 | * be awakened when they arrive. */ | ||
2297 | current->real_blocked = current->blocked; | ||
2298 | sigandsets(¤t->blocked, ¤t->blocked, &these); | ||
2299 | recalc_sigpending(); | ||
2300 | spin_unlock_irq(¤t->sighand->siglock); | ||
2301 | |||
2302 | timeout = schedule_timeout_interruptible(timeout); | ||
2303 | |||
2304 | spin_lock_irq(¤t->sighand->siglock); | ||
2305 | sig = dequeue_signal(current, &these, &info); | ||
2306 | current->blocked = current->real_blocked; | ||
2307 | siginitset(¤t->real_blocked, 0); | ||
2308 | recalc_sigpending(); | ||
2309 | } | ||
2310 | } | ||
2311 | spin_unlock_irq(¤t->sighand->siglock); | ||
2312 | 2601 | ||
2313 | if (sig) { | 2602 | if (ret > 0 && uinfo) { |
2314 | ret = sig; | 2603 | if (copy_siginfo_to_user(uinfo, &info)) |
2315 | if (uinfo) { | 2604 | ret = -EFAULT; |
2316 | if (copy_siginfo_to_user(uinfo, &info)) | ||
2317 | ret = -EFAULT; | ||
2318 | } | ||
2319 | } else { | ||
2320 | ret = -EAGAIN; | ||
2321 | if (timeout) | ||
2322 | ret = -EINTR; | ||
2323 | } | 2605 | } |
2324 | 2606 | ||
2325 | return ret; | 2607 | return ret; |
2326 | } | 2608 | } |
2327 | 2609 | ||
2610 | /** | ||
2611 | * sys_kill - send a signal to a process | ||
2612 | * @pid: the PID of the process | ||
2613 | * @sig: signal to be sent | ||
2614 | */ | ||
2328 | SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) | 2615 | SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
2329 | { | 2616 | { |
2330 | struct siginfo info; | 2617 | struct siginfo info; |
@@ -2400,7 +2687,11 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig) | |||
2400 | return do_tkill(tgid, pid, sig); | 2687 | return do_tkill(tgid, pid, sig); |
2401 | } | 2688 | } |
2402 | 2689 | ||
2403 | /* | 2690 | /** |
2691 | * sys_tkill - send signal to one specific task | ||
2692 | * @pid: the PID of the task | ||
2693 | * @sig: signal to be sent | ||
2694 | * | ||
2404 | * Send a signal to only one task, even if it's a CLONE_THREAD task. | 2695 | * Send a signal to only one task, even if it's a CLONE_THREAD task. |
2405 | */ | 2696 | */ |
2406 | SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) | 2697 | SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) |
@@ -2412,6 +2703,12 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) | |||
2412 | return do_tkill(0, pid, sig); | 2703 | return do_tkill(0, pid, sig); |
2413 | } | 2704 | } |
2414 | 2705 | ||
2706 | /** | ||
2707 | * sys_rt_sigqueueinfo - send signal information to a signal | ||
2708 | * @pid: the PID of the thread | ||
2709 | * @sig: signal to be sent | ||
2710 | * @uinfo: signal info to be sent | ||
2711 | */ | ||
2415 | SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, | 2712 | SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, |
2416 | siginfo_t __user *, uinfo) | 2713 | siginfo_t __user *, uinfo) |
2417 | { | 2714 | { |
@@ -2421,9 +2718,13 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, | |||
2421 | return -EFAULT; | 2718 | return -EFAULT; |
2422 | 2719 | ||
2423 | /* Not even root can pretend to send signals from the kernel. | 2720 | /* Not even root can pretend to send signals from the kernel. |
2424 | Nor can they impersonate a kill(), which adds source info. */ | 2721 | * Nor can they impersonate a kill()/tgkill(), which adds source info. |
2425 | if (info.si_code >= 0) | 2722 | */ |
2723 | if (info.si_code >= 0 || info.si_code == SI_TKILL) { | ||
2724 | /* We used to allow any < 0 si_code */ | ||
2725 | WARN_ON_ONCE(info.si_code < 0); | ||
2426 | return -EPERM; | 2726 | return -EPERM; |
2727 | } | ||
2427 | info.si_signo = sig; | 2728 | info.si_signo = sig; |
2428 | 2729 | ||
2429 | /* POSIX.1b doesn't mention process groups. */ | 2730 | /* POSIX.1b doesn't mention process groups. */ |
@@ -2437,9 +2738,13 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info) | |||
2437 | return -EINVAL; | 2738 | return -EINVAL; |
2438 | 2739 | ||
2439 | /* Not even root can pretend to send signals from the kernel. | 2740 | /* Not even root can pretend to send signals from the kernel. |
2440 | Nor can they impersonate a kill(), which adds source info. */ | 2741 | * Nor can they impersonate a kill()/tgkill(), which adds source info. |
2441 | if (info->si_code >= 0) | 2742 | */ |
2743 | if (info->si_code >= 0 || info->si_code == SI_TKILL) { | ||
2744 | /* We used to allow any < 0 si_code */ | ||
2745 | WARN_ON_ONCE(info->si_code < 0); | ||
2442 | return -EPERM; | 2746 | return -EPERM; |
2747 | } | ||
2443 | info->si_signo = sig; | 2748 | info->si_signo = sig; |
2444 | 2749 | ||
2445 | return do_send_specific(tgid, pid, sig, info); | 2750 | return do_send_specific(tgid, pid, sig, info); |
@@ -2531,12 +2836,11 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s | |||
2531 | 2836 | ||
2532 | error = -EINVAL; | 2837 | error = -EINVAL; |
2533 | /* | 2838 | /* |
2534 | * | 2839 | * Note - this code used to test ss_flags incorrectly: |
2535 | * Note - this code used to test ss_flags incorrectly | ||
2536 | * old code may have been written using ss_flags==0 | 2840 | * old code may have been written using ss_flags==0 |
2537 | * to mean ss_flags==SS_ONSTACK (as this was the only | 2841 | * to mean ss_flags==SS_ONSTACK (as this was the only |
2538 | * way that worked) - this fix preserves that older | 2842 | * way that worked) - this fix preserves that older |
2539 | * mechanism | 2843 | * mechanism. |
2540 | */ | 2844 | */ |
2541 | if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0) | 2845 | if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0) |
2542 | goto out; | 2846 | goto out; |
@@ -2570,6 +2874,10 @@ out: | |||
2570 | 2874 | ||
2571 | #ifdef __ARCH_WANT_SYS_SIGPENDING | 2875 | #ifdef __ARCH_WANT_SYS_SIGPENDING |
2572 | 2876 | ||
2877 | /** | ||
2878 | * sys_sigpending - examine pending signals | ||
2879 | * @set: where mask of pending signal is returned | ||
2880 | */ | ||
2573 | SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set) | 2881 | SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set) |
2574 | { | 2882 | { |
2575 | return do_sigpending(set, sizeof(*set)); | 2883 | return do_sigpending(set, sizeof(*set)); |
@@ -2578,60 +2886,65 @@ SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set) | |||
2578 | #endif | 2886 | #endif |
2579 | 2887 | ||
2580 | #ifdef __ARCH_WANT_SYS_SIGPROCMASK | 2888 | #ifdef __ARCH_WANT_SYS_SIGPROCMASK |
2581 | /* Some platforms have their own version with special arguments others | 2889 | /** |
2582 | support only sys_rt_sigprocmask. */ | 2890 | * sys_sigprocmask - examine and change blocked signals |
2891 | * @how: whether to add, remove, or set signals | ||
2892 | * @nset: signals to add or remove (if non-null) | ||
2893 | * @oset: previous value of signal mask if non-null | ||
2894 | * | ||
2895 | * Some platforms have their own version with special arguments; | ||
2896 | * others support only sys_rt_sigprocmask. | ||
2897 | */ | ||
2583 | 2898 | ||
2584 | SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set, | 2899 | SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, nset, |
2585 | old_sigset_t __user *, oset) | 2900 | old_sigset_t __user *, oset) |
2586 | { | 2901 | { |
2587 | int error; | ||
2588 | old_sigset_t old_set, new_set; | 2902 | old_sigset_t old_set, new_set; |
2903 | sigset_t new_blocked; | ||
2589 | 2904 | ||
2590 | if (set) { | 2905 | old_set = current->blocked.sig[0]; |
2591 | error = -EFAULT; | 2906 | |
2592 | if (copy_from_user(&new_set, set, sizeof(*set))) | 2907 | if (nset) { |
2593 | goto out; | 2908 | if (copy_from_user(&new_set, nset, sizeof(*nset))) |
2909 | return -EFAULT; | ||
2594 | new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP)); | 2910 | new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP)); |
2595 | 2911 | ||
2596 | spin_lock_irq(¤t->sighand->siglock); | 2912 | new_blocked = current->blocked; |
2597 | old_set = current->blocked.sig[0]; | ||
2598 | 2913 | ||
2599 | error = 0; | ||
2600 | switch (how) { | 2914 | switch (how) { |
2601 | default: | ||
2602 | error = -EINVAL; | ||
2603 | break; | ||
2604 | case SIG_BLOCK: | 2915 | case SIG_BLOCK: |
2605 | sigaddsetmask(¤t->blocked, new_set); | 2916 | sigaddsetmask(&new_blocked, new_set); |
2606 | break; | 2917 | break; |
2607 | case SIG_UNBLOCK: | 2918 | case SIG_UNBLOCK: |
2608 | sigdelsetmask(¤t->blocked, new_set); | 2919 | sigdelsetmask(&new_blocked, new_set); |
2609 | break; | 2920 | break; |
2610 | case SIG_SETMASK: | 2921 | case SIG_SETMASK: |
2611 | current->blocked.sig[0] = new_set; | 2922 | new_blocked.sig[0] = new_set; |
2612 | break; | 2923 | break; |
2924 | default: | ||
2925 | return -EINVAL; | ||
2613 | } | 2926 | } |
2614 | 2927 | ||
2615 | recalc_sigpending(); | 2928 | set_current_blocked(&new_blocked); |
2616 | spin_unlock_irq(¤t->sighand->siglock); | 2929 | } |
2617 | if (error) | 2930 | |
2618 | goto out; | 2931 | if (oset) { |
2619 | if (oset) | ||
2620 | goto set_old; | ||
2621 | } else if (oset) { | ||
2622 | old_set = current->blocked.sig[0]; | ||
2623 | set_old: | ||
2624 | error = -EFAULT; | ||
2625 | if (copy_to_user(oset, &old_set, sizeof(*oset))) | 2932 | if (copy_to_user(oset, &old_set, sizeof(*oset))) |
2626 | goto out; | 2933 | return -EFAULT; |
2627 | } | 2934 | } |
2628 | error = 0; | 2935 | |
2629 | out: | 2936 | return 0; |
2630 | return error; | ||
2631 | } | 2937 | } |
2632 | #endif /* __ARCH_WANT_SYS_SIGPROCMASK */ | 2938 | #endif /* __ARCH_WANT_SYS_SIGPROCMASK */ |
2633 | 2939 | ||
2634 | #ifdef __ARCH_WANT_SYS_RT_SIGACTION | 2940 | #ifdef __ARCH_WANT_SYS_RT_SIGACTION |
2941 | /** | ||
2942 | * sys_rt_sigaction - alter an action taken by a process | ||
2943 | * @sig: signal to be sent | ||
2944 | * @act: new sigaction | ||
2945 | * @oact: used to save the previous sigaction | ||
2946 | * @sigsetsize: size of sigset_t type | ||
2947 | */ | ||
2635 | SYSCALL_DEFINE4(rt_sigaction, int, sig, | 2948 | SYSCALL_DEFINE4(rt_sigaction, int, sig, |
2636 | const struct sigaction __user *, act, | 2949 | const struct sigaction __user *, act, |
2637 | struct sigaction __user *, oact, | 2950 | struct sigaction __user *, oact, |
@@ -2710,14 +3023,22 @@ SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler) | |||
2710 | 3023 | ||
2711 | SYSCALL_DEFINE0(pause) | 3024 | SYSCALL_DEFINE0(pause) |
2712 | { | 3025 | { |
2713 | current->state = TASK_INTERRUPTIBLE; | 3026 | while (!signal_pending(current)) { |
2714 | schedule(); | 3027 | current->state = TASK_INTERRUPTIBLE; |
3028 | schedule(); | ||
3029 | } | ||
2715 | return -ERESTARTNOHAND; | 3030 | return -ERESTARTNOHAND; |
2716 | } | 3031 | } |
2717 | 3032 | ||
2718 | #endif | 3033 | #endif |
2719 | 3034 | ||
2720 | #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND | 3035 | #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND |
3036 | /** | ||
3037 | * sys_rt_sigsuspend - replace the signal mask for a value with the | ||
3038 | * @unewset value until a signal is received | ||
3039 | * @unewset: new signal mask value | ||
3040 | * @sigsetsize: size of sigset_t type | ||
3041 | */ | ||
2721 | SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize) | 3042 | SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize) |
2722 | { | 3043 | { |
2723 | sigset_t newset; | 3044 | sigset_t newset; |