Lines Matching +full:signal +full:- +full:group
1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/kernel/signal.c
7 * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson
9 * 2003-06-02 Jim Houston - Concurrent Computer Corp.
32 #include <linux/signal.h>
45 #include <linux/posix-timers.h>
50 #include <trace/events/signal.h>
60 * SLAB caches for signal bits.
69 return t->sighand->action[sig - 1].sa.sa_handler; in sig_handler()
89 if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) && in sig_task_ignored()
94 if (unlikely((t->flags & PF_KTHREAD) && in sig_task_ignored()
105 * signal handler may change by the time it is in sig_ignored()
108 if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) in sig_ignored()
112 * Tracers may want to know about even ignored signal unless it in sig_ignored()
116 if (t->ptrace && sig != SIGKILL) in sig_ignored()
123 * Re-calculate pending state from the set of locally pending
126 static inline bool has_pending_signals(sigset_t *signal, sigset_t *blocked) in has_pending_signals() argument
133 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;) in has_pending_signals()
134 ready |= signal->sig[i] &~ blocked->sig[i]; in has_pending_signals()
137 case 4: ready = signal->sig[3] &~ blocked->sig[3]; in has_pending_signals()
138 ready |= signal->sig[2] &~ blocked->sig[2]; in has_pending_signals()
139 ready |= signal->sig[1] &~ blocked->sig[1]; in has_pending_signals()
140 ready |= signal->sig[0] &~ blocked->sig[0]; in has_pending_signals()
143 case 2: ready = signal->sig[1] &~ blocked->sig[1]; in has_pending_signals()
144 ready |= signal->sig[0] &~ blocked->sig[0]; in has_pending_signals()
147 case 1: ready = signal->sig[0] &~ blocked->sig[0]; in has_pending_signals()
152 #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
156 if ((t->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE)) || in recalc_sigpending_tsk()
157 PENDING(&t->pending, &t->blocked) || in recalc_sigpending_tsk()
158 PENDING(&t->signal->shared_pending, &t->blocked) || in recalc_sigpending_tsk()
166 * when it's possible the current syscall is returning -ERESTART*. in recalc_sigpending_tsk()
174 * This is superfluous when called on current, the wakeup is a harmless no-op.
195 spin_lock_irq(¤t->sighand->siglock); in calculate_sigpending()
198 spin_unlock_irq(¤t->sighand->siglock); in calculate_sigpending()
201 /* Given the mask, find the first available signal that should be serviced. */
212 s = pending->signal.sig; in next_signal()
213 m = mask->sig; in next_signal()
263 pr_info("%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n", in print_dropped_signal()
264 current->comm, current->pid, sig); in print_dropped_signal()
268 * task_set_jobctl_pending - set jobctl pending bits
272 * Clear @mask from @task->jobctl. @mask must be subset of
279 * Must be called with @task->sighand->siglock held.
290 if (unlikely(fatal_signal_pending(task) || (task->flags & PF_EXITING))) in task_set_jobctl_pending()
294 task->jobctl &= ~JOBCTL_STOP_SIGMASK; in task_set_jobctl_pending()
296 task->jobctl |= mask; in task_set_jobctl_pending()
301 * task_clear_jobctl_trapping - clear jobctl trapping bit
306 * locking. @task->siglock guarantees that @task->parent points to the
310 * Must be called with @task->sighand->siglock held.
314 if (unlikely(task->jobctl & JOBCTL_TRAPPING)) { in task_clear_jobctl_trapping()
315 task->jobctl &= ~JOBCTL_TRAPPING; in task_clear_jobctl_trapping()
317 wake_up_bit(&task->jobctl, JOBCTL_TRAPPING_BIT); in task_clear_jobctl_trapping()
322 * task_clear_jobctl_pending - clear jobctl pending bits
326 * Clear @mask from @task->jobctl. @mask must be subset of
334 * Must be called with @task->sighand->siglock held.
343 task->jobctl &= ~mask; in task_clear_jobctl_pending()
345 if (!(task->jobctl & JOBCTL_PENDING_MASK)) in task_clear_jobctl_pending()
350 * task_participate_group_stop - participate in a group stop
351 * @task: task participating in a group stop
353 * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
354 * Group stop states are cleared and the group stop count is consumed if
355 * %JOBCTL_STOP_CONSUME was set. If the consumption completes the group
359 * Must be called with @task->sighand->siglock held.
362 * %true if group stop completion should be notified to the parent, %false
367 struct signal_struct *sig = task->signal; in task_participate_group_stop()
368 bool consume = task->jobctl & JOBCTL_STOP_CONSUME; in task_participate_group_stop()
370 WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING)); in task_participate_group_stop()
377 if (!WARN_ON_ONCE(sig->group_stop_count == 0)) in task_participate_group_stop()
378 sig->group_stop_count--; in task_participate_group_stop()
382 * fresh group stop. Read comment in do_signal_stop() for details. in task_participate_group_stop()
384 if (!sig->group_stop_count && !(sig->flags & SIGNAL_STOP_STOPPED)) { in task_participate_group_stop()
393 unsigned long mask = current->jobctl & JOBCTL_STOP_SIGMASK; in task_join_group_stop()
394 struct signal_struct *sig = current->signal; in task_join_group_stop()
396 if (sig->group_stop_count) { in task_join_group_stop()
397 sig->group_stop_count++; in task_join_group_stop()
399 } else if (!(sig->flags & SIGNAL_STOP_STOPPED)) in task_join_group_stop()
402 /* Have the new thread join an on-going signal group stop */ in task_join_group_stop()
407 * allocate a new signal queue record
408 * - this may be called without locks if and only if t == current, otherwise an
423 * NOTE! A pending signal will hold on to the user refcount, in __sigqueue_alloc()
443 INIT_LIST_HEAD(&q->list); in __sigqueue_alloc()
444 q->flags = sigqueue_flags; in __sigqueue_alloc()
445 q->ucounts = ucounts; in __sigqueue_alloc()
452 if (q->flags & SIGQUEUE_PREALLOC) in __sigqueue_free()
454 if (q->ucounts) { in __sigqueue_free()
455 dec_rlimit_put_ucounts(q->ucounts, UCOUNT_RLIMIT_SIGPENDING); in __sigqueue_free()
456 q->ucounts = NULL; in __sigqueue_free()
465 sigemptyset(&queue->signal); in flush_sigqueue()
466 while (!list_empty(&queue->list)) { in flush_sigqueue()
467 q = list_entry(queue->list.next, struct sigqueue , list); in flush_sigqueue()
468 list_del_init(&q->list); in flush_sigqueue()
480 spin_lock_irqsave(&t->sighand->siglock, flags); in flush_signals()
482 flush_sigqueue(&t->pending); in flush_signals()
483 flush_sigqueue(&t->signal->shared_pending); in flush_signals()
484 spin_unlock_irqrestore(&t->sighand->siglock, flags); in flush_signals()
491 sigset_t signal, retain; in __flush_itimer_signals() local
494 signal = pending->signal; in __flush_itimer_signals()
497 list_for_each_entry_safe(q, n, &pending->list, list) { in __flush_itimer_signals()
498 int sig = q->info.si_signo; in __flush_itimer_signals()
500 if (likely(q->info.si_code != SI_TIMER)) { in __flush_itimer_signals()
503 sigdelset(&signal, sig); in __flush_itimer_signals()
504 list_del_init(&q->list); in __flush_itimer_signals()
509 sigorsets(&pending->signal, &signal, &retain); in __flush_itimer_signals()
517 spin_lock_irqsave(&tsk->sighand->siglock, flags); in flush_itimer_signals()
518 __flush_itimer_signals(&tsk->pending); in flush_itimer_signals()
519 __flush_itimer_signals(&tsk->signal->shared_pending); in flush_itimer_signals()
520 spin_unlock_irqrestore(&tsk->sighand->siglock, flags); in flush_itimer_signals()
529 t->sighand->action[i].sa.sa_handler = SIG_IGN; in ignore_signals()
542 struct k_sigaction *ka = &t->sighand->action[0]; in flush_signal_handlers()
543 for (i = _NSIG ; i != 0 ; i--) { in flush_signal_handlers()
544 if (force_default || ka->sa.sa_handler != SIG_IGN) in flush_signal_handlers()
545 ka->sa.sa_handler = SIG_DFL; in flush_signal_handlers()
546 ka->sa.sa_flags = 0; in flush_signal_handlers()
548 ka->sa.sa_restorer = NULL; in flush_signal_handlers()
550 sigemptyset(&ka->sa.sa_mask); in flush_signal_handlers()
557 void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler; in unhandled_signal()
565 return !tsk->ptrace; in unhandled_signal()
574 * Collect the siginfo appropriate to this signal. Check if in collect_signal()
575 * there is another siginfo for the same signal. in collect_signal()
577 list_for_each_entry(q, &list->list, list) { in collect_signal()
578 if (q->info.si_signo == sig) { in collect_signal()
585 sigdelset(&list->signal, sig); in collect_signal()
589 list_del_init(&first->list); in collect_signal()
590 copy_siginfo(info, &first->info); in collect_signal()
593 (first->flags & SIGQUEUE_PREALLOC) && in collect_signal()
594 (info->si_code == SI_TIMER) && in collect_signal()
595 (info->si_sys_private); in collect_signal()
601 * a fast-pathed signal or we must have been in collect_signal()
605 info->si_signo = sig; in collect_signal()
606 info->si_errno = 0; in collect_signal()
607 info->si_code = SI_USER; in collect_signal()
608 info->si_pid = 0; in collect_signal()
609 info->si_uid = 0; in collect_signal()
624 * Dequeue a signal and return the element to the caller, which is
639 signr = __dequeue_signal(&tsk->pending, mask, info, &resched_timer); in dequeue_signal()
642 signr = __dequeue_signal(&tsk->signal->shared_pending, in dequeue_signal()
646 * itimer signal ? in dequeue_signal()
649 * itimers in the signal delivery path to prevent DoS in dequeue_signal()
651 * compliant with the old way of self-restarting in dequeue_signal()
652 * itimers, as the SIGALRM is a legacy signal and only in dequeue_signal()
654 * restart the timer in the signal dequeue path is in dequeue_signal()
659 struct hrtimer *tmr = &tsk->signal->real_timer; in dequeue_signal()
662 tsk->signal->it_real_incr != 0) { in dequeue_signal()
663 hrtimer_forward(tmr, tmr->base->get_time(), in dequeue_signal()
664 tsk->signal->it_real_incr); in dequeue_signal()
677 * Set a marker that we have dequeued a stop signal. Our in dequeue_signal()
679 * stop signal it is about to process is no longer in the in dequeue_signal()
683 * remain set after the signal we return is ignored or in dequeue_signal()
685 * is to alert stop-signal processing code when another in dequeue_signal()
688 current->jobctl |= JOBCTL_STOP_DEQUEUED; in dequeue_signal()
695 * irqs disabled here, since the posix-timers code is in dequeue_signal()
698 spin_unlock(&tsk->sighand->siglock); in dequeue_signal()
700 spin_lock(&tsk->sighand->siglock); in dequeue_signal()
703 info->si_sys_private = 0; in dequeue_signal()
713 struct sigpending *pending = &tsk->pending; in dequeue_synchronous_signal()
717 * Might a synchronous signal be in the queue? in dequeue_synchronous_signal()
719 if (!((pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK)) in dequeue_synchronous_signal()
723 * Return the first synchronous signal in the queue. in dequeue_synchronous_signal()
725 list_for_each_entry(q, &pending->list, list) { in dequeue_synchronous_signal()
727 if ((q->info.si_code > SI_USER) && in dequeue_synchronous_signal()
728 (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) { in dequeue_synchronous_signal()
736 * Check if there is another siginfo for the same signal. in dequeue_synchronous_signal()
738 list_for_each_entry_continue(q, &pending->list, list) { in dequeue_synchronous_signal()
739 if (q->info.si_signo == sync->info.si_signo) in dequeue_synchronous_signal()
743 sigdelset(&pending->signal, sync->info.si_signo); in dequeue_synchronous_signal()
746 list_del_init(&sync->list); in dequeue_synchronous_signal()
747 copy_siginfo(info, &sync->info); in dequeue_synchronous_signal()
749 return info->si_signo; in dequeue_synchronous_signal()
753 * Tell a process that it has a new active signal..
760 * No need to set need_resched since signal event passing
761 * goes through ->blocked
765 lockdep_assert_held(&t->sighand->siglock); in signal_wake_up_state()
771 * case. We don't check t->state here because there is a race with it in signal_wake_up_state()
774 * handle its death signal. in signal_wake_up_state()
791 sigandsets(&m, mask, &s->signal); in flush_sigqueue_mask()
795 sigandnsets(&s->signal, &s->signal, mask); in flush_sigqueue_mask()
796 list_for_each_entry_safe(q, n, &s->list, list) { in flush_sigqueue_mask()
797 if (sigismember(mask, q->info.si_signo)) { in flush_sigqueue_mask()
798 list_del_init(&q->list); in flush_sigqueue_mask()
823 return uid_eq(cred->euid, tcred->suid) || in kill_ok_by_cred()
824 uid_eq(cred->euid, tcred->uid) || in kill_ok_by_cred()
825 uid_eq(cred->uid, tcred->suid) || in kill_ok_by_cred()
826 uid_eq(cred->uid, tcred->uid) || in kill_ok_by_cred()
827 ns_capable(tcred->user_ns, CAP_KILL); in kill_ok_by_cred()
831 * Bad permissions for sending the signal
832 * - the caller must hold the RCU read lock
841 return -EINVAL; in check_kill_permission()
846 error = audit_signal_info(sig, t); /* Let audit system see the signal */ in check_kill_permission()
863 return -EPERM; in check_kill_permission()
871 * ptrace_trap_notify - schedule trap to notify ptracer
880 * re-trap for the new event. If trapped otherwise, STOP trap will be
885 * Must be called with @task->sighand->siglock held.
889 WARN_ON_ONCE(!(t->ptrace & PT_SEIZED)); in ptrace_trap_notify()
890 lockdep_assert_held(&t->sighand->siglock); in ptrace_trap_notify()
893 ptrace_signal_wake_up(t, t->jobctl & JOBCTL_LISTENING); in ptrace_trap_notify()
897 * Handle magic process-wide effects of stop/continue signals. Unlike
898 * the signal actions, these happen immediately at signal-generation
901 * signals. The process stop is done as a signal action for SIG_DFL.
903 * Returns true if the signal should be actually delivered, otherwise
908 struct signal_struct *signal = p->signal; in prepare_signal() local
912 if (signal->flags & SIGNAL_GROUP_EXIT) { in prepare_signal()
913 if (signal->core_state) in prepare_signal()
916 * The process is in the middle of dying, drop the signal. in prepare_signal()
921 * This is a stop signal. Remove SIGCONT from all queues. in prepare_signal()
924 flush_sigqueue_mask(&flush, &signal->shared_pending); in prepare_signal()
926 flush_sigqueue_mask(&flush, &t->pending); in prepare_signal()
933 flush_sigqueue_mask(&flush, &signal->shared_pending); in prepare_signal()
935 flush_sigqueue_mask(&flush, &t->pending); in prepare_signal()
937 if (likely(!(t->ptrace & PT_SEIZED))) { in prepare_signal()
938 t->jobctl &= ~JOBCTL_STOPPED; in prepare_signal()
947 * If we were in the middle of a group stop, we pretend it in prepare_signal()
953 if (signal->flags & SIGNAL_STOP_STOPPED) in prepare_signal()
955 else if (signal->group_stop_count) in prepare_signal()
961 * will take ->siglock, notice SIGNAL_CLD_MASK, and in prepare_signal()
964 signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED); in prepare_signal()
965 signal->group_stop_count = 0; in prepare_signal()
966 signal->group_exit_code = 0; in prepare_signal()
978 * as soon as they're available, so putting the signal on the shared queue
983 if (sigismember(&p->blocked, sig)) in wants_signal()
986 if (p->flags & PF_EXITING) in wants_signal()
1000 struct signal_struct *signal = p->signal; in complete_signal() local
1004 * Now find a thread we can wake up to take the signal off the queue. in complete_signal()
1006 * If the main thread wants the signal, it gets first crack. in complete_signal()
1021 t = signal->curr_target; in complete_signal()
1024 if (t == signal->curr_target) in complete_signal()
1028 * the signal in the queue soon. in complete_signal()
1032 signal->curr_target = t; in complete_signal()
1036 * Found a killable thread. If the signal will be fatal, in complete_signal()
1037 * then start taking the whole group down immediately. in complete_signal()
1040 (signal->core_state || !(signal->flags & SIGNAL_GROUP_EXIT)) && in complete_signal()
1041 !sigismember(&t->real_blocked, sig) && in complete_signal()
1042 (sig == SIGKILL || !p->ptrace)) { in complete_signal()
1044 * This signal will be fatal to the whole group. in complete_signal()
1048 * Start a group exit and wake everybody up. in complete_signal()
1051 * thread has the fatal signal pending. in complete_signal()
1053 signal->flags = SIGNAL_GROUP_EXIT; in complete_signal()
1054 signal->group_exit_code = sig; in complete_signal()
1055 signal->group_stop_count = 0; in complete_signal()
1059 sigaddset(&t->pending.signal, SIGKILL); in complete_signal()
1067 * The signal is already in the shared-pending queue. in complete_signal()
1076 return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); in legacy_queue()
1087 lockdep_assert_held(&t->sighand->siglock); in __send_signal_locked()
1093 pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; in __send_signal_locked()
1095 * Short-circuit ignored signals and support queuing in __send_signal_locked()
1096 * exactly one non-rt signal, so that we can get more in __send_signal_locked()
1097 * detailed information about the cause of the signal. in __send_signal_locked()
1107 if ((sig == SIGKILL) || (t->flags & PF_KTHREAD)) in __send_signal_locked()
1111 * Real-time signals must be queued if sent by sigqueue, or in __send_signal_locked()
1112 * some other real-time mechanism. It is implementation in __send_signal_locked()
1116 * make sure at least one signal gets delivered and don't in __send_signal_locked()
1120 override_rlimit = (is_si_special(info) || info->si_code >= 0); in __send_signal_locked()
1127 list_add_tail(&q->list, &pending->list); in __send_signal_locked()
1130 clear_siginfo(&q->info); in __send_signal_locked()
1131 q->info.si_signo = sig; in __send_signal_locked()
1132 q->info.si_errno = 0; in __send_signal_locked()
1133 q->info.si_code = SI_USER; in __send_signal_locked()
1134 q->info.si_pid = task_tgid_nr_ns(current, in __send_signal_locked()
1137 q->info.si_uid = in __send_signal_locked()
1143 clear_siginfo(&q->info); in __send_signal_locked()
1144 q->info.si_signo = sig; in __send_signal_locked()
1145 q->info.si_errno = 0; in __send_signal_locked()
1146 q->info.si_code = SI_KERNEL; in __send_signal_locked()
1147 q->info.si_pid = 0; in __send_signal_locked()
1148 q->info.si_uid = 0; in __send_signal_locked()
1151 copy_siginfo(&q->info, info); in __send_signal_locked()
1155 sig >= SIGRTMIN && info->si_code != SI_USER) { in __send_signal_locked()
1158 * signal was rt and sent by user using something in __send_signal_locked()
1162 ret = -EAGAIN; in __send_signal_locked()
1167 * send the signal, but the *info bits are lost. in __send_signal_locked()
1174 sigaddset(&pending->signal, sig); in __send_signal_locked()
1176 /* Let multiprocess signals appear after on-going forks */ in __send_signal_locked()
1179 hlist_for_each_entry(delayed, &t->signal->multiprocess, node) { in __send_signal_locked()
1180 sigset_t *signal = &delayed->signal; in __send_signal_locked() local
1181 /* Can't queue both a stop and a continue signal */ in __send_signal_locked()
1183 sigdelsetmask(signal, SIG_KERNEL_STOP_MASK); in __send_signal_locked()
1185 sigdelset(signal, SIGCONT); in __send_signal_locked()
1186 sigaddset(signal, sig); in __send_signal_locked()
1199 switch (siginfo_layout(info->si_signo, info->si_code)) { in has_si_pid_and_uid()
1239 kuid_t uid = make_kuid(current_user_ns(), info->si_uid); in send_signal_locked()
1240 info->si_uid = from_kuid_munged(t_user_ns, uid); in send_signal_locked()
1244 /* A kernel generated signal? */ in send_signal_locked()
1245 force = (info->si_code == SI_KERNEL); in send_signal_locked()
1249 info->si_pid = 0; in send_signal_locked()
1259 pr_info("potentially unexpected fatal signal %d.\n", signr); in print_fatal_signal()
1262 pr_info("code at %08lx: ", regs->ip); in print_fatal_signal()
1268 if (get_user(insn, (unsigned char *)(regs->ip + i))) in print_fatal_signal()
1287 __setup("print-fatal-signals=", setup_print_fatal_signals);
1293 int ret = -ESRCH; in do_send_sig_info()
1310 * Force a signal that the process can't ignore: if necessary
1311 * we unblock the signal and change any SIG_IGN to SIG_DFL.
1313 * Note: If we unblock the signal, we always reset it to SIG_DFL,
1314 * since we do not want to have a signal handler that was blocked
1327 int sig = info->si_signo; in force_sig_info_to_task()
1329 spin_lock_irqsave(&t->sighand->siglock, flags); in force_sig_info_to_task()
1330 action = &t->sighand->action[sig-1]; in force_sig_info_to_task()
1331 ignored = action->sa.sa_handler == SIG_IGN; in force_sig_info_to_task()
1332 blocked = sigismember(&t->blocked, sig); in force_sig_info_to_task()
1334 action->sa.sa_handler = SIG_DFL; in force_sig_info_to_task()
1336 action->sa.sa_flags |= SA_IMMUTABLE; in force_sig_info_to_task()
1338 sigdelset(&t->blocked, sig); in force_sig_info_to_task()
1346 if (action->sa.sa_handler == SIG_DFL && in force_sig_info_to_task()
1347 (!t->ptrace || (handler == HANDLER_EXIT))) in force_sig_info_to_task()
1348 t->signal->flags &= ~SIGNAL_UNKILLABLE; in force_sig_info_to_task()
1350 spin_unlock_irqrestore(&t->sighand->siglock, flags); in force_sig_info_to_task()
1361 * Nuke all other threads in the group.
1368 p->signal->group_stop_count = 0; in zap_other_threads()
1375 if (t->exit_state) in zap_other_threads()
1377 sigaddset(&t->pending.signal, SIGKILL); in zap_other_threads()
1391 sighand = rcu_dereference(tsk->sighand); in __lock_task_sighand()
1398 * initializes ->siglock: this slab can't go away, it has in __lock_task_sighand()
1399 * the same object type, ->siglock can't be reinitialized. in __lock_task_sighand()
1401 * We need to ensure that tsk->sighand is still the same in __lock_task_sighand()
1404 * must see ->sighand == NULL. in __lock_task_sighand()
1406 spin_lock_irqsave(&sighand->siglock, *flags); in __lock_task_sighand()
1407 if (likely(sighand == rcu_access_pointer(tsk->sighand))) in __lock_task_sighand()
1409 spin_unlock_irqrestore(&sighand->siglock, *flags); in __lock_task_sighand()
1422 sighand = rcu_dereference(task->sighand); in lockdep_assert_task_sighand_held()
1424 lockdep_assert_held(&sighand->siglock); in lockdep_assert_task_sighand_held()
1432 * send signal info to all the members of a group
1450 * __kill_pgrp_info() sends a signal to a process group: this is what the tty
1452 * - the caller must hold at least a readlock on tasklist_lock
1460 retval = -ESRCH; in __kill_pgrp_info()
1471 int error = -ESRCH; in kill_pid_info()
1480 if (likely(!p || error != -ESRCH)) in kill_pid_info()
1505 return uid_eq(cred->euid, pcred->suid) || in kill_as_cred_perm()
1506 uid_eq(cred->euid, pcred->uid) || in kill_as_cred_perm()
1507 uid_eq(cred->uid, pcred->suid) || in kill_as_cred_perm()
1508 uid_eq(cred->uid, pcred->uid); in kill_as_cred_perm()
1542 int ret = -EINVAL; in kill_pid_usb_asyncio()
1556 ret = -ESRCH; in kill_pid_usb_asyncio()
1560 ret = -EPERM; in kill_pid_usb_asyncio()
1572 ret = -ESRCH; in kill_pid_usb_asyncio()
1583 * POSIX specifies that kill(-1,sig) is unspecified, but what we have
1594 /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */ in kill_something_info()
1596 return -ESRCH; in kill_something_info()
1599 if (pid != -1) { in kill_something_info()
1601 pid ? find_vpid(-pid) : task_pgrp(current)); in kill_something_info()
1612 if (err != -EPERM) in kill_something_info()
1616 ret = count ? retval : -ESRCH; in kill_something_info()
1634 return -EINVAL; in send_sig_info()
1691 * When things go south during signal handling, we
1692 * will force a SIGSEGV. And if the signal that caused
1694 * make sure we don't even try to deliver the signal..
1821 * process if SIGTRAP is blocked, however, delivering the signal in send_sig_perf()
1823 * space if the signal was asynchronous, so it can clearly be in send_sig_perf()
1826 info.si_perf_flags = sigismember(¤t->blocked, info.si_signo) ? in send_sig_perf()
1834 * force_sig_seccomp - signals the task to allow in-process syscall emulation
1836 * @reason: filter-supplied reason code to send to userland (via si_errno)
1933 return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC); in sigqueue_alloc()
1939 spinlock_t *lock = ¤t->sighand->siglock; in sigqueue_free()
1941 BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); in sigqueue_free()
1943 * We must hold ->siglock while testing q->list in sigqueue_free()
1945 * __exit_signal()->flush_sigqueue(). in sigqueue_free()
1948 q->flags &= ~SIGQUEUE_PREALLOC; in sigqueue_free()
1953 if (!list_empty(&q->list)) in sigqueue_free()
1963 int sig = q->info.si_signo; in send_sigqueue()
1969 BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); in send_sigqueue()
1971 ret = -1; in send_sigqueue()
1977 ret = 1; /* the signal is ignored */ in send_sigqueue()
1983 if (unlikely(!list_empty(&q->list))) { in send_sigqueue()
1988 BUG_ON(q->info.si_code != SI_TIMER); in send_sigqueue()
1989 q->info.si_overrun++; in send_sigqueue()
1993 q->info.si_overrun = 0; in send_sigqueue()
1996 pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; in send_sigqueue()
1997 list_add_tail(&q->list, &pending->list); in send_sigqueue()
1998 sigaddset(&pending->signal, sig); in send_sigqueue()
2002 trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result); in send_sigqueue()
2013 WARN_ON(task->exit_state == 0); in do_notify_pidfd()
2015 wake_up_all(&pid->wait_pidfd); in do_notify_pidfd()
2023 * self-reaping.
2033 WARN_ON_ONCE(sig == -1); in do_notify_parent()
2038 WARN_ON_ONCE(!tsk->ptrace && in do_notify_parent()
2039 (tsk->group_leader != tsk || !thread_group_empty(tsk))); in do_notify_parent()
2049 if (tsk->parent_exec_id != READ_ONCE(tsk->parent->self_exec_id)) in do_notify_parent()
2068 info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent)); in do_notify_parent()
2069 info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns), in do_notify_parent()
2074 info.si_utime = nsec_to_clock_t(utime + tsk->signal->utime); in do_notify_parent()
2075 info.si_stime = nsec_to_clock_t(stime + tsk->signal->stime); in do_notify_parent()
2077 info.si_status = tsk->exit_code & 0x7f; in do_notify_parent()
2078 if (tsk->exit_code & 0x80) in do_notify_parent()
2080 else if (tsk->exit_code & 0x7f) in do_notify_parent()
2084 info.si_status = tsk->exit_code >> 8; in do_notify_parent()
2087 psig = tsk->parent->sighand; in do_notify_parent()
2088 spin_lock_irqsave(&psig->siglock, flags); in do_notify_parent()
2089 if (!tsk->ptrace && sig == SIGCHLD && in do_notify_parent()
2090 (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN || in do_notify_parent()
2091 (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) { in do_notify_parent()
2098 * signal handler, we just set this to tell do_exit that we in do_notify_parent()
2101 * blocked sys_wait4 might now return -ECHILD. in do_notify_parent()
2104 * is implementation-defined: we do (if you don't want in do_notify_parent()
2108 if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) in do_notify_parent()
2116 __send_signal_locked(sig, &info, tsk->parent, PIDTYPE_TGID, false); in do_notify_parent()
2117 __wake_up_parent(tsk, tsk->parent); in do_notify_parent()
2118 spin_unlock_irqrestore(&psig->siglock, flags); in do_notify_parent()
2124 * do_notify_parent_cldstop - notify parent of stopped/continued state change
2130 * @for_ptracer is %false, @tsk's group leader notifies to its real parent.
2131 * If %true, @tsk reports to @tsk->parent which should be the ptracer.
2146 parent = tsk->parent; in do_notify_parent_cldstop()
2148 tsk = tsk->group_leader; in do_notify_parent_cldstop()
2149 parent = tsk->real_parent; in do_notify_parent_cldstop()
2173 info.si_status = tsk->signal->group_exit_code & 0x7f; in do_notify_parent_cldstop()
2176 info.si_status = tsk->exit_code & 0x7f; in do_notify_parent_cldstop()
2182 sighand = parent->sighand; in do_notify_parent_cldstop()
2183 spin_lock_irqsave(&sighand->siglock, flags); in do_notify_parent_cldstop()
2184 if (sighand->action[SIGCHLD-1].sa.sa_handler != SIG_IGN && in do_notify_parent_cldstop()
2185 !(sighand->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP)) in do_notify_parent_cldstop()
2191 spin_unlock_irqrestore(&sighand->siglock, flags); in do_notify_parent_cldstop()
2195 * This must be called with current->sighand->siglock held.
2198 * We always set current->last_siginfo while stopped here.
2200 * being ptrace-stopped vs being job-control-stopped.
2202 * Returns the signal the ptracer requested the code resume
2204 * the stop signal remains unchanged unless clear_code.
2208 __releases(¤t->sighand->siglock) in ptrace_stop()
2209 __acquires(¤t->sighand->siglock) in ptrace_stop()
2220 * any signal bookkeeping like checking group_stop_count. in ptrace_stop()
2222 spin_unlock_irq(¤t->sighand->siglock); in ptrace_stop()
2224 spin_lock_irq(¤t->sighand->siglock); in ptrace_stop()
2230 * signal comes in. Handle previous ptrace_unlinks and fatal in ptrace_stop()
2233 if (!current->ptrace || __fatal_signal_pending(current)) in ptrace_stop()
2237 current->jobctl |= JOBCTL_TRACED; in ptrace_stop()
2242 * Also, transition to TRACED and updates to ->jobctl should be in ptrace_stop()
2259 current->ptrace_message = message; in ptrace_stop()
2260 current->last_siginfo = info; in ptrace_stop()
2261 current->exit_code = exit_code; in ptrace_stop()
2264 * If @why is CLD_STOPPED, we're trapping to participate in a group in ptrace_stop()
2268 * TASK_TRACED is entered - ignore it. in ptrace_stop()
2270 if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING)) in ptrace_stop()
2275 if (info && info->si_code >> 8 == PTRACE_EVENT_STOP) in ptrace_stop()
2281 spin_unlock_irq(¤t->sighand->siglock); in ptrace_stop()
2286 * While ptraced, there are two parents - the ptracer and in ptrace_stop()
2289 * interested in the completion of group stop. The states in ptrace_stop()
2293 if (current->ptrace) in ptrace_stop()
2295 if (gstop_done && (!current->ptrace || ptrace_reparented(current))) in ptrace_stop()
2314 * any signal-sending on another CPU that wants to examine it. in ptrace_stop()
2316 spin_lock_irq(¤t->sighand->siglock); in ptrace_stop()
2317 exit_code = current->exit_code; in ptrace_stop()
2318 current->last_siginfo = NULL; in ptrace_stop()
2319 current->ptrace_message = 0; in ptrace_stop()
2320 current->exit_code = 0; in ptrace_stop()
2323 current->jobctl &= ~(JOBCTL_LISTENING | JOBCTL_PTRACE_FROZEN); in ptrace_stop()
2356 spin_lock_irq(¤t->sighand->siglock); in ptrace_notify()
2358 spin_unlock_irq(¤t->sighand->siglock); in ptrace_notify()
2363 * do_signal_stop - handle group stop for SIGSTOP and other stop signals
2364 * @signr: signr causing group stop if initiating
2366 * If %JOBCTL_STOP_PENDING is not set yet, initiate group stop with @signr
2368 * group stop. If participated in a group stop (and thus slept), %true is
2377 * Must be called with @current->sighand->siglock held, which is released
2381 * %false if group stop is already cancelled or ptrace trap is scheduled.
2382 * %true if participated in group stop.
2385 __releases(¤t->sighand->siglock) in do_signal_stop()
2387 struct signal_struct *sig = current->signal; in do_signal_stop()
2389 if (!(current->jobctl & JOBCTL_STOP_PENDING)) { in do_signal_stop()
2393 /* signr will be recorded in task->jobctl for retries */ in do_signal_stop()
2396 if (!likely(current->jobctl & JOBCTL_STOP_DEQUEUED) || in do_signal_stop()
2397 unlikely(sig->flags & SIGNAL_GROUP_EXIT) || in do_signal_stop()
2398 unlikely(sig->group_exec_task)) in do_signal_stop()
2401 * There is no group stop already in progress. We must in do_signal_stop()
2404 * While ptraced, a task may be resumed while group stop is in do_signal_stop()
2405 * still in effect and then receive a stop signal and in do_signal_stop()
2406 * initiate another group stop. This deviates from the in do_signal_stop()
2408 * cause two group stops when !ptraced. That is why we in do_signal_stop()
2416 * an intervening stop signal is required to cause two in do_signal_stop()
2419 if (!(sig->flags & SIGNAL_STOP_STOPPED)) in do_signal_stop()
2420 sig->group_exit_code = signr; in do_signal_stop()
2422 sig->group_stop_count = 0; in do_signal_stop()
2425 sig->group_stop_count++; in do_signal_stop()
2430 * Setting state to TASK_STOPPED for a group in do_signal_stop()
2436 sig->group_stop_count++; in do_signal_stop()
2437 if (likely(!(t->ptrace & PT_SEIZED))) in do_signal_stop()
2445 if (likely(!current->ptrace)) { in do_signal_stop()
2449 * If there are no other threads in the group, or if there in do_signal_stop()
2450 * is a group stop in progress and we are the last to stop, in do_signal_stop()
2456 current->jobctl |= JOBCTL_STOPPED; in do_signal_stop()
2458 spin_unlock_irq(¤t->sighand->siglock); in do_signal_stop()
2461 * Notify the parent of the group stop completion. Because in do_signal_stop()
2464 * group stop and should always be delivered to the real in do_signal_stop()
2465 * parent of the group leader. The new ptracer will get in do_signal_stop()
2481 * While ptraced, group stop is handled by STOP trap. in do_signal_stop()
2490 * do_jobctl_trap - take care of ptrace jobctl traps
2492 * When PT_SEIZED, it's used for both group stop and explicit
2495 * the stop signal; otherwise, %SIGTRAP.
2497 * When !PT_SEIZED, it's used only for group stop trap with stop signal
2501 * Must be called with @current->sighand->siglock held, which may be
2502 * released and re-acquired before returning with intervening sleep.
2506 struct signal_struct *signal = current->signal; in do_jobctl_trap() local
2507 int signr = current->jobctl & JOBCTL_STOP_SIGMASK; in do_jobctl_trap()
2509 if (current->ptrace & PT_SEIZED) { in do_jobctl_trap()
2510 if (!signal->group_stop_count && in do_jobctl_trap()
2511 !(signal->flags & SIGNAL_STOP_STOPPED)) in do_jobctl_trap()
2523 * do_freezer_trap - handle the freezer jobctl trap
2529 * Must be called with @current->sighand->siglock held,
2533 __releases(¤t->sighand->siglock) in do_freezer_trap()
2540 if ((current->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE)) != in do_freezer_trap()
2542 spin_unlock_irq(¤t->sighand->siglock); in do_freezer_trap()
2547 * Now we're sure that there is no pending fatal signal and no in do_freezer_trap()
2549 * immediately (if there is a non-fatal signal pending), and in do_freezer_trap()
2554 spin_unlock_irq(¤t->sighand->siglock); in do_freezer_trap()
2570 current->jobctl |= JOBCTL_STOP_DEQUEUED; in ptrace_signal()
2578 * Update the siginfo structure if the signal has in ptrace_signal()
2583 if (signr != info->si_signo) { in ptrace_signal()
2585 info->si_signo = signr; in ptrace_signal()
2586 info->si_errno = 0; in ptrace_signal()
2587 info->si_code = SI_USER; in ptrace_signal()
2589 info->si_pid = task_pid_vnr(current->parent); in ptrace_signal()
2590 info->si_uid = from_kuid_munged(current_user_ns(), in ptrace_signal()
2591 task_uid(current->parent)); in ptrace_signal()
2595 /* If the (new) signal is now blocked, requeue it. */ in ptrace_signal()
2596 if (sigismember(¤t->blocked, signr) || in ptrace_signal()
2607 switch (siginfo_layout(ksig->sig, ksig->info.si_code)) { in hide_si_addr_tag_bits()
2614 ksig->info.si_addr = arch_untagged_si_addr( in hide_si_addr_tag_bits()
2615 ksig->info.si_addr, ksig->sig, ksig->info.si_code); in hide_si_addr_tag_bits()
2629 struct sighand_struct *sighand = current->sighand; in get_signal()
2630 struct signal_struct *signal = current->signal; in get_signal() local
2644 * Do this once, we can't return to user-mode if freezing() == T. in get_signal()
2651 spin_lock_irq(&sighand->siglock); in get_signal()
2658 if (unlikely(signal->flags & SIGNAL_CLD_MASK)) { in get_signal()
2661 if (signal->flags & SIGNAL_CLD_CONTINUED) in get_signal()
2666 signal->flags &= ~SIGNAL_CLD_MASK; in get_signal()
2668 spin_unlock_irq(&sighand->siglock); in get_signal()
2672 * always per-process and doesn't make whole lot of sense in get_signal()
2675 * the ptracer of the group leader too unless it's gonna be in get_signal()
2681 if (ptrace_reparented(current->group_leader)) in get_signal()
2682 do_notify_parent_cldstop(current->group_leader, in get_signal()
2694 if ((signal->flags & SIGNAL_GROUP_EXIT) || in get_signal()
2695 signal->group_exec_task) { in get_signal()
2696 ksig->info.si_signo = signr = SIGKILL; in get_signal()
2697 sigdelset(¤t->pending.signal, SIGKILL); in get_signal()
2699 &sighand->action[SIGKILL - 1]); in get_signal()
2704 if (unlikely(current->jobctl & JOBCTL_STOP_PENDING) && in get_signal()
2708 if (unlikely(current->jobctl & in get_signal()
2710 if (current->jobctl & JOBCTL_TRAP_MASK) { in get_signal()
2712 spin_unlock_irq(&sighand->siglock); in get_signal()
2713 } else if (current->jobctl & JOBCTL_TRAP_FREEZE) in get_signal()
2724 spin_unlock_irq(&sighand->siglock); in get_signal()
2732 * so that the instruction pointer in the signal stack in get_signal()
2736 signr = dequeue_synchronous_signal(&ksig->info); in get_signal()
2738 signr = dequeue_signal(current, ¤t->blocked, in get_signal()
2739 &ksig->info, &type); in get_signal()
2744 if (unlikely(current->ptrace) && (signr != SIGKILL) && in get_signal()
2745 !(sighand->action[signr -1].sa.sa_flags & SA_IMMUTABLE)) { in get_signal()
2746 signr = ptrace_signal(signr, &ksig->info, type); in get_signal()
2751 ka = &sighand->action[signr-1]; in get_signal()
2754 trace_signal_deliver(signr, &ksig->info, ka); in get_signal()
2756 if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ in get_signal()
2758 if (ka->sa.sa_handler != SIG_DFL) { in get_signal()
2760 ksig->ka = *ka; in get_signal()
2762 if (ka->sa.sa_flags & SA_ONESHOT) in get_signal()
2763 ka->sa.sa_handler = SIG_DFL; in get_signal()
2765 break; /* will return non-zero "signr" value */ in get_signal()
2769 * Now we are doing the default action for this signal. in get_signal()
2776 * Container-init gets no signals it doesn't want from same in get_signal()
2779 * Note that if global/container-init sees a sig_kernel_only() in get_signal()
2780 * signal here, the signal must have been generated internally in get_signal()
2782 * case, the signal cannot be dropped. in get_signal()
2784 if (unlikely(signal->flags & SIGNAL_UNKILLABLE) && in get_signal()
2791 * the thread group. The job control signals in get_signal()
2800 spin_unlock_irq(&sighand->siglock); in get_signal()
2807 spin_lock_irq(&sighand->siglock); in get_signal()
2810 if (likely(do_signal_stop(ksig->info.si_signo))) { in get_signal()
2823 spin_unlock_irq(&sighand->siglock); in get_signal()
2830 current->flags |= PF_SIGNALED; in get_signal()
2834 print_fatal_signal(ksig->info.si_signo); in get_signal()
2838 * other threads in the group and synchronizes with in get_signal()
2844 do_coredump(&ksig->info); in get_signal()
2852 if (current->flags & PF_IO_WORKER) in get_signal()
2858 do_group_exit(ksig->info.si_signo); in get_signal()
2861 spin_unlock_irq(&sighand->siglock); in get_signal()
2863 ksig->sig = signr; in get_signal()
2865 if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS)) in get_signal()
2868 return ksig->sig > 0; in get_signal()
2872 * signal_delivered - called after signal delivery to update blocked signals
2873 * @ksig: kernel signal struct
2874 * @stepping: nonzero if debugger single-step or block-step in use
2876 * This function should be called when a signal has successfully been
2877 * delivered. It updates the blocked signals accordingly (@ksig->ka.sa.sa_mask
2878 * is always blocked), and the signal itself is blocked unless %SA_NODEFER
2879 * is set in @ksig->ka.sa.sa_flags. Tracing is notified.
2885 /* A signal was successfully delivered, and the in signal_delivered()
2886 saved sigmask was stored on the signal frame, in signal_delivered()
2891 sigorsets(&blocked, ¤t->blocked, &ksig->ka.sa.sa_mask); in signal_delivered()
2892 if (!(ksig->ka.sa.sa_flags & SA_NODEFER)) in signal_delivered()
2893 sigaddset(&blocked, ksig->sig); in signal_delivered()
2895 if (current->sas_ss_flags & SS_AUTODISARM) in signal_delivered()
2904 force_sigsegv(ksig->sig); in signal_setup_done()
2911 * group-wide signal. Other threads should be notified now to take
2919 sigandsets(&retarget, &tsk->signal->shared_pending.signal, which); in retarget_shared_pending()
2925 if (t->flags & PF_EXITING) in retarget_shared_pending()
2928 if (!has_pending_signals(&retarget, &t->blocked)) in retarget_shared_pending()
2931 sigandsets(&retarget, &retarget, &t->blocked); in retarget_shared_pending()
2947 * @tsk is about to have PF_EXITING set - lock out users which in exit_signals()
2952 if (thread_group_empty(tsk) || (tsk->signal->flags & SIGNAL_GROUP_EXIT)) { in exit_signals()
2953 tsk->flags |= PF_EXITING; in exit_signals()
2958 spin_lock_irq(&tsk->sighand->siglock); in exit_signals()
2960 * From now this task is not visible for group-wide signals, in exit_signals()
2963 tsk->flags |= PF_EXITING; in exit_signals()
2970 unblocked = tsk->blocked; in exit_signals()
2974 if (unlikely(tsk->jobctl & JOBCTL_STOP_PENDING) && in exit_signals()
2978 spin_unlock_irq(&tsk->sighand->siglock); in exit_signals()
2981 * If group stop has completed, deliver the notification. This in exit_signals()
2982 * should always go to the real parent of the group leader. in exit_signals()
2996 * sys_restart_syscall - restart a system call
3000 struct restart_block *restart = ¤t->restart_block; in SYSCALL_DEFINE0()
3001 return restart->fn(restart); in SYSCALL_DEFINE0()
3006 return -EINTR; in do_no_restart_syscall()
3014 sigandnsets(&newblocked, newset, ¤t->blocked); in __set_task_blocked()
3017 tsk->blocked = *newset; in __set_task_blocked()
3022 * set_current_blocked - change current->blocked mask
3025 * It is wrong to change ->blocked directly, this helper should be used
3026 * to ensure the process can't miss a shared signal we are going to block.
3039 * In case the signal mask hasn't changed, there is nothing we need in __set_current_blocked()
3040 * to do. The current->blocked shouldn't be modified by other task. in __set_current_blocked()
3042 if (sigequalsets(&tsk->blocked, newset)) in __set_current_blocked()
3045 spin_lock_irq(&tsk->sighand->siglock); in __set_current_blocked()
3047 spin_unlock_irq(&tsk->sighand->siglock); in __set_current_blocked()
3054 * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel
3063 /* Lockless, only current can change ->blocked, never from irq */ in sigprocmask()
3065 *oldset = tsk->blocked; in sigprocmask()
3069 sigorsets(&newset, &tsk->blocked, set); in sigprocmask()
3072 sigandnsets(&newset, &tsk->blocked, set); in sigprocmask()
3078 return -EINVAL; in sigprocmask()
3087 * The api helps set app-provided sigmasks.
3102 return -EINVAL; in set_user_sigmask()
3104 return -EFAULT; in set_user_sigmask()
3107 current->saved_sigmask = current->blocked; in set_user_sigmask()
3122 return -EINVAL; in set_compat_user_sigmask()
3124 return -EFAULT; in set_compat_user_sigmask()
3127 current->saved_sigmask = current->blocked; in set_compat_user_sigmask()
3135 * sys_rt_sigprocmask - change the list of currently blocked signals
3138 * @oset: previous value of signal mask if non-null
3149 return -EINVAL; in SYSCALL_DEFINE4()
3151 old_set = current->blocked; in SYSCALL_DEFINE4()
3155 return -EFAULT; in SYSCALL_DEFINE4()
3165 return -EFAULT; in SYSCALL_DEFINE4()
3175 sigset_t old_set = current->blocked; in COMPAT_SYSCALL_DEFINE4()
3179 return -EINVAL; in COMPAT_SYSCALL_DEFINE4()
3185 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3198 spin_lock_irq(¤t->sighand->siglock); in do_sigpending()
3199 sigorsets(set, ¤t->pending.signal, in do_sigpending()
3200 ¤t->signal->shared_pending.signal); in do_sigpending()
3201 spin_unlock_irq(¤t->sighand->siglock); in do_sigpending()
3204 sigandsets(set, ¤t->blocked, set); in do_sigpending()
3208 * sys_rt_sigpending - examine a pending signal that has been raised
3218 return -EINVAL; in SYSCALL_DEFINE2()
3223 return -EFAULT; in SYSCALL_DEFINE2()
3235 return -EINVAL; in COMPAT_SYSCALL_DEFINE2()
3327 return -EFAULT; in copy_siginfo_to_user()
3329 return -EFAULT; in copy_siginfo_to_user()
3336 if (unlikely(!known_siginfo_layout(info->si_signo, info->si_code))) { in post_copy_siginfo_from_user()
3347 return -EFAULT; in post_copy_siginfo_from_user()
3350 return -E2BIG; in post_copy_siginfo_from_user()
3360 return -EFAULT; in __copy_siginfo_from_user()
3361 to->si_signo = signo; in __copy_siginfo_from_user()
3368 return -EFAULT; in copy_siginfo_from_user()
3374 * copy_siginfo_to_external32 - copy a kernel siginfo into a compat user siginfo
3388 to->si_signo = from->si_signo; in copy_siginfo_to_external32()
3389 to->si_errno = from->si_errno; in copy_siginfo_to_external32()
3390 to->si_code = from->si_code; in copy_siginfo_to_external32()
3391 switch(siginfo_layout(from->si_signo, from->si_code)) { in copy_siginfo_to_external32()
3393 to->si_pid = from->si_pid; in copy_siginfo_to_external32()
3394 to->si_uid = from->si_uid; in copy_siginfo_to_external32()
3397 to->si_tid = from->si_tid; in copy_siginfo_to_external32()
3398 to->si_overrun = from->si_overrun; in copy_siginfo_to_external32()
3399 to->si_int = from->si_int; in copy_siginfo_to_external32()
3402 to->si_band = from->si_band; in copy_siginfo_to_external32()
3403 to->si_fd = from->si_fd; in copy_siginfo_to_external32()
3406 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3409 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3410 to->si_trapno = from->si_trapno; in copy_siginfo_to_external32()
3413 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3414 to->si_addr_lsb = from->si_addr_lsb; in copy_siginfo_to_external32()
3417 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3418 to->si_lower = ptr_to_compat(from->si_lower); in copy_siginfo_to_external32()
3419 to->si_upper = ptr_to_compat(from->si_upper); in copy_siginfo_to_external32()
3422 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3423 to->si_pkey = from->si_pkey; in copy_siginfo_to_external32()
3426 to->si_addr = ptr_to_compat(from->si_addr); in copy_siginfo_to_external32()
3427 to->si_perf_data = from->si_perf_data; in copy_siginfo_to_external32()
3428 to->si_perf_type = from->si_perf_type; in copy_siginfo_to_external32()
3429 to->si_perf_flags = from->si_perf_flags; in copy_siginfo_to_external32()
3432 to->si_pid = from->si_pid; in copy_siginfo_to_external32()
3433 to->si_uid = from->si_uid; in copy_siginfo_to_external32()
3434 to->si_status = from->si_status; in copy_siginfo_to_external32()
3435 to->si_utime = from->si_utime; in copy_siginfo_to_external32()
3436 to->si_stime = from->si_stime; in copy_siginfo_to_external32()
3439 to->si_pid = from->si_pid; in copy_siginfo_to_external32()
3440 to->si_uid = from->si_uid; in copy_siginfo_to_external32()
3441 to->si_int = from->si_int; in copy_siginfo_to_external32()
3444 to->si_call_addr = ptr_to_compat(from->si_call_addr); in copy_siginfo_to_external32()
3445 to->si_syscall = from->si_syscall; in copy_siginfo_to_external32()
3446 to->si_arch = from->si_arch; in copy_siginfo_to_external32()
3458 return -EFAULT; in __copy_siginfo_to_user32()
3466 to->si_signo = from->si_signo; in post_copy_siginfo_from_user32()
3467 to->si_errno = from->si_errno; in post_copy_siginfo_from_user32()
3468 to->si_code = from->si_code; in post_copy_siginfo_from_user32()
3469 switch(siginfo_layout(from->si_signo, from->si_code)) { in post_copy_siginfo_from_user32()
3471 to->si_pid = from->si_pid; in post_copy_siginfo_from_user32()
3472 to->si_uid = from->si_uid; in post_copy_siginfo_from_user32()
3475 to->si_tid = from->si_tid; in post_copy_siginfo_from_user32()
3476 to->si_overrun = from->si_overrun; in post_copy_siginfo_from_user32()
3477 to->si_int = from->si_int; in post_copy_siginfo_from_user32()
3480 to->si_band = from->si_band; in post_copy_siginfo_from_user32()
3481 to->si_fd = from->si_fd; in post_copy_siginfo_from_user32()
3484 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3487 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3488 to->si_trapno = from->si_trapno; in post_copy_siginfo_from_user32()
3491 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3492 to->si_addr_lsb = from->si_addr_lsb; in post_copy_siginfo_from_user32()
3495 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3496 to->si_lower = compat_ptr(from->si_lower); in post_copy_siginfo_from_user32()
3497 to->si_upper = compat_ptr(from->si_upper); in post_copy_siginfo_from_user32()
3500 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3501 to->si_pkey = from->si_pkey; in post_copy_siginfo_from_user32()
3504 to->si_addr = compat_ptr(from->si_addr); in post_copy_siginfo_from_user32()
3505 to->si_perf_data = from->si_perf_data; in post_copy_siginfo_from_user32()
3506 to->si_perf_type = from->si_perf_type; in post_copy_siginfo_from_user32()
3507 to->si_perf_flags = from->si_perf_flags; in post_copy_siginfo_from_user32()
3510 to->si_pid = from->si_pid; in post_copy_siginfo_from_user32()
3511 to->si_uid = from->si_uid; in post_copy_siginfo_from_user32()
3512 to->si_status = from->si_status; in post_copy_siginfo_from_user32()
3515 to->si_utime = from->_sifields._sigchld_x32._utime; in post_copy_siginfo_from_user32()
3516 to->si_stime = from->_sifields._sigchld_x32._stime; in post_copy_siginfo_from_user32()
3520 to->si_utime = from->si_utime; in post_copy_siginfo_from_user32()
3521 to->si_stime = from->si_stime; in post_copy_siginfo_from_user32()
3525 to->si_pid = from->si_pid; in post_copy_siginfo_from_user32()
3526 to->si_uid = from->si_uid; in post_copy_siginfo_from_user32()
3527 to->si_int = from->si_int; in post_copy_siginfo_from_user32()
3530 to->si_call_addr = compat_ptr(from->si_call_addr); in post_copy_siginfo_from_user32()
3531 to->si_syscall = from->si_syscall; in post_copy_siginfo_from_user32()
3532 to->si_arch = from->si_arch; in post_copy_siginfo_from_user32()
3544 return -EFAULT; in __copy_siginfo_from_user32()
3556 return -EFAULT; in copy_siginfo_from_user32()
3563 * do_sigtimedwait - wait for queued signals specified in @which
3565 * @info: if non-null, the signal's siginfo is returned here
3579 return -EINVAL; in do_sigtimedwait()
3590 spin_lock_irq(&tsk->sighand->siglock); in do_sigtimedwait()
3599 tsk->real_blocked = tsk->blocked; in do_sigtimedwait()
3600 sigandsets(&tsk->blocked, &tsk->blocked, &mask); in do_sigtimedwait()
3602 spin_unlock_irq(&tsk->sighand->siglock); in do_sigtimedwait()
3605 ret = schedule_hrtimeout_range(to, tsk->timer_slack_ns, in do_sigtimedwait()
3607 spin_lock_irq(&tsk->sighand->siglock); in do_sigtimedwait()
3608 __set_task_blocked(tsk, &tsk->real_blocked); in do_sigtimedwait()
3609 sigemptyset(&tsk->real_blocked); in do_sigtimedwait()
3612 spin_unlock_irq(&tsk->sighand->siglock); in do_sigtimedwait()
3616 return ret ? -EINTR : -EAGAIN; in do_sigtimedwait()
3620 * sys_rt_sigtimedwait - synchronously wait for queued signals specified
3623 * @uinfo: if non-null, the signal's siginfo is returned here
3639 return -EINVAL; in SYSCALL_DEFINE4()
3642 return -EFAULT; in SYSCALL_DEFINE4()
3646 return -EFAULT; in SYSCALL_DEFINE4()
3653 ret = -EFAULT; in SYSCALL_DEFINE4()
3671 return -EINVAL; in SYSCALL_DEFINE4()
3674 return -EFAULT; in SYSCALL_DEFINE4()
3678 return -EFAULT; in SYSCALL_DEFINE4()
3685 ret = -EFAULT; in SYSCALL_DEFINE4()
3703 return -EINVAL; in COMPAT_SYSCALL_DEFINE4()
3706 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3710 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3717 ret = -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3734 return -EINVAL; in COMPAT_SYSCALL_DEFINE4()
3737 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3741 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3748 ret = -EFAULT; in COMPAT_SYSCALL_DEFINE4()
3759 info->si_signo = sig; in prepare_kill_siginfo()
3760 info->si_errno = 0; in prepare_kill_siginfo()
3761 info->si_code = SI_USER; in prepare_kill_siginfo()
3762 info->si_pid = task_tgid_vnr(current); in prepare_kill_siginfo()
3763 info->si_uid = from_kuid_munged(current_user_ns(), current_uid()); in prepare_kill_siginfo()
3767 * sys_kill - send a signal to a process
3769 * @sig: signal to be sent
3795 p = p->parent; in access_pidfd_pidns()
3807 * conversions here. Note, this is a stop-gap measure and should not be in copy_siginfo_from_user_any()
3829 * sys_pidfd_send_signal - Signal a process through a pidfd
3831 * @sig: signal to send
3832 * @info: signal info
3836 * kill(<positive-pid>, <signal>. It does not signal threads or process
3856 return -EINVAL; in SYSCALL_DEFINE4()
3860 return -EBADF; in SYSCALL_DEFINE4()
3869 ret = -EINVAL; in SYSCALL_DEFINE4()
3878 ret = -EINVAL; in SYSCALL_DEFINE4()
3883 ret = -EPERM; in SYSCALL_DEFINE4()
3902 int error = -ESRCH; in do_send_specific()
3909 * The null signal is a permissions and process existence in do_send_specific()
3910 * probe. No signal is actually delivered. in do_send_specific()
3916 * dies after receiving the signal. The window is tiny, in do_send_specific()
3917 * and the signal is private anyway. in do_send_specific()
3919 if (unlikely(error == -ESRCH)) in do_send_specific()
3943 * sys_tgkill - send signal to one specific thread
3944 * @tgid: the thread group ID of the thread
3946 * @sig: signal to be sent
3948 * This syscall also checks the @tgid and returns -ESRCH even if the PID
3956 return -EINVAL; in SYSCALL_DEFINE3()
3962 * sys_tkill - send signal to one specific task
3964 * @sig: signal to be sent
3966 * Send a signal to only one task, even if it's a CLONE_THREAD task.
3972 return -EINVAL; in SYSCALL_DEFINE2()
3982 if ((info->si_code >= 0 || info->si_code == SI_TKILL) && in do_rt_sigqueueinfo()
3984 return -EPERM; in do_rt_sigqueueinfo()
3991 * sys_rt_sigqueueinfo - send signal information to a signal
3993 * @sig: signal to be sent
3994 * @uinfo: signal info to be sent
4024 return -EINVAL; in do_rt_tgsigqueueinfo()
4029 if ((info->si_code >= 0 || info->si_code == SI_TKILL) && in do_rt_tgsigqueueinfo()
4031 return -EPERM; in do_rt_tgsigqueueinfo()
4066 spin_lock_irq(¤t->sighand->siglock); in kernel_sigaction()
4067 current->sighand->action[sig - 1].sa.sa_handler = action; in kernel_sigaction()
4074 flush_sigqueue_mask(&mask, ¤t->signal->shared_pending); in kernel_sigaction()
4075 flush_sigqueue_mask(&mask, ¤t->pending); in kernel_sigaction()
4078 spin_unlock_irq(¤t->sighand->siglock); in kernel_sigaction()
4094 return -EINVAL; in do_sigaction()
4096 k = &p->sighand->action[sig-1]; in do_sigaction()
4098 spin_lock_irq(&p->sighand->siglock); in do_sigaction()
4099 if (k->sa.sa_flags & SA_IMMUTABLE) { in do_sigaction()
4100 spin_unlock_irq(&p->sighand->siglock); in do_sigaction()
4101 return -EINVAL; in do_sigaction()
4114 * support for flag bits and to allow the kernel to use non-uapi bits in do_sigaction()
4118 act->sa.sa_flags &= UAPI_SA_FLAGS; in do_sigaction()
4120 oact->sa.sa_flags &= UAPI_SA_FLAGS; in do_sigaction()
4125 sigdelsetmask(&act->sa.sa_mask, in do_sigaction()
4130 * "Setting a signal action to SIG_IGN for a signal that is in do_sigaction()
4131 * pending shall cause the pending signal to be discarded, in do_sigaction()
4134 * "Setting a signal action to SIG_DFL for a signal that is in do_sigaction()
4135 * pending and whose default action is to ignore the signal in do_sigaction()
4136 * (for example, SIGCHLD), shall cause the pending signal to in do_sigaction()
4142 flush_sigqueue_mask(&mask, &p->signal->shared_pending); in do_sigaction()
4144 flush_sigqueue_mask(&mask, &t->pending); in do_sigaction()
4148 spin_unlock_irq(&p->sighand->siglock); in do_sigaction()
4154 __acquires(¤t->sighand->siglock) in sigaltstack_lock()
4156 spin_lock_irq(¤t->sighand->siglock); in sigaltstack_lock()
4160 __releases(¤t->sighand->siglock) in sigaltstack_unlock()
4162 spin_unlock_irq(¤t->sighand->siglock); in sigaltstack_unlock()
4178 oss->ss_sp = (void __user *) t->sas_ss_sp; in do_sigaltstack()
4179 oss->ss_size = t->sas_ss_size; in do_sigaltstack()
4180 oss->ss_flags = sas_ss_flags(sp) | in do_sigaltstack()
4181 (current->sas_ss_flags & SS_FLAG_BITS); in do_sigaltstack()
4185 void __user *ss_sp = ss->ss_sp; in do_sigaltstack()
4186 size_t ss_size = ss->ss_size; in do_sigaltstack()
4187 unsigned ss_flags = ss->ss_flags; in do_sigaltstack()
4191 return -EPERM; in do_sigaltstack()
4196 return -EINVAL; in do_sigaltstack()
4202 if (t->sas_ss_sp == (unsigned long)ss_sp && in do_sigaltstack()
4203 t->sas_ss_size == ss_size && in do_sigaltstack()
4204 t->sas_ss_flags == ss_flags) in do_sigaltstack()
4213 ret = -ENOMEM; in do_sigaltstack()
4215 ret = -ENOMEM; in do_sigaltstack()
4218 t->sas_ss_sp = (unsigned long) ss_sp; in do_sigaltstack()
4219 t->sas_ss_size = ss_size; in do_sigaltstack()
4220 t->sas_ss_flags = ss_flags; in do_sigaltstack()
4232 return -EFAULT; in SYSCALL_DEFINE2()
4237 err = -EFAULT; in SYSCALL_DEFINE2()
4245 return -EFAULT; in restore_altstack()
4255 int err = __put_user((void __user *)t->sas_ss_sp, &uss->ss_sp) | in __save_altstack()
4256 __put_user(t->sas_ss_flags, &uss->ss_flags) | in __save_altstack()
4257 __put_user(t->sas_ss_size, &uss->ss_size); in __save_altstack()
4271 return -EFAULT; in do_compat_sigaltstack()
4286 ret = -EFAULT; in do_compat_sigaltstack()
4301 /* squash all but -EFAULT for now */ in compat_restore_altstack()
4302 return err == -EFAULT ? err : 0; in compat_restore_altstack()
4309 err = __put_user(ptr_to_compat((void __user *)t->sas_ss_sp), in __compat_save_altstack()
4310 &uss->ss_sp) | in __compat_save_altstack()
4311 __put_user(t->sas_ss_flags, &uss->ss_flags) | in __compat_save_altstack()
4312 __put_user(t->sas_ss_size, &uss->ss_size); in __compat_save_altstack()
4320 * sys_sigpending - examine pending signals
4321 * @uset: where mask of pending signal is returned
4328 return -EINVAL; in SYSCALL_DEFINE1()
4333 return -EFAULT; in SYSCALL_DEFINE1()
4353 * sys_sigprocmask - examine and change blocked signals
4355 * @nset: signals to add or remove (if non-null)
4356 * @oset: previous value of signal mask if non-null
4368 old_set = current->blocked.sig[0]; in SYSCALL_DEFINE3()
4372 return -EFAULT; in SYSCALL_DEFINE3()
4374 new_blocked = current->blocked; in SYSCALL_DEFINE3()
4387 return -EINVAL; in SYSCALL_DEFINE3()
4395 return -EFAULT; in SYSCALL_DEFINE3()
4404 * sys_rt_sigaction - alter an action taken by a process
4405 * @sig: signal to be sent
4420 return -EINVAL; in SYSCALL_DEFINE4()
4423 return -EFAULT; in SYSCALL_DEFINE4()
4430 return -EFAULT; in SYSCALL_DEFINE4()
4448 return -EINVAL; in COMPAT_SYSCALL_DEFINE4()
4452 ret = get_user(handler, &act->sa_handler); in COMPAT_SYSCALL_DEFINE4()
4455 ret |= get_user(restorer, &act->sa_restorer); in COMPAT_SYSCALL_DEFINE4()
4458 ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask); in COMPAT_SYSCALL_DEFINE4()
4459 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags); in COMPAT_SYSCALL_DEFINE4()
4461 return -EFAULT; in COMPAT_SYSCALL_DEFINE4()
4467 &oact->sa_handler); in COMPAT_SYSCALL_DEFINE4()
4468 ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask, in COMPAT_SYSCALL_DEFINE4()
4469 sizeof(oact->sa_mask)); in COMPAT_SYSCALL_DEFINE4()
4470 ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags); in COMPAT_SYSCALL_DEFINE4()
4473 &oact->sa_restorer); in COMPAT_SYSCALL_DEFINE4()
4492 __get_user(new_ka.sa.sa_handler, &act->sa_handler) || in SYSCALL_DEFINE3()
4493 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) || in SYSCALL_DEFINE3()
4494 __get_user(new_ka.sa.sa_flags, &act->sa_flags) || in SYSCALL_DEFINE3()
4495 __get_user(mask, &act->sa_mask)) in SYSCALL_DEFINE3()
4496 return -EFAULT; in SYSCALL_DEFINE3()
4507 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || in SYSCALL_DEFINE3()
4508 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) || in SYSCALL_DEFINE3()
4509 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || in SYSCALL_DEFINE3()
4510 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) in SYSCALL_DEFINE3()
4511 return -EFAULT; in SYSCALL_DEFINE3()
4529 __get_user(handler, &act->sa_handler) || in COMPAT_SYSCALL_DEFINE3()
4530 __get_user(restorer, &act->sa_restorer) || in COMPAT_SYSCALL_DEFINE3()
4531 __get_user(new_ka.sa.sa_flags, &act->sa_flags) || in COMPAT_SYSCALL_DEFINE3()
4532 __get_user(mask, &act->sa_mask)) in COMPAT_SYSCALL_DEFINE3()
4533 return -EFAULT; in COMPAT_SYSCALL_DEFINE3()
4548 &oact->sa_handler) || in COMPAT_SYSCALL_DEFINE3()
4550 &oact->sa_restorer) || in COMPAT_SYSCALL_DEFINE3()
4551 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || in COMPAT_SYSCALL_DEFINE3()
4552 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) in COMPAT_SYSCALL_DEFINE3()
4553 return -EFAULT; in COMPAT_SYSCALL_DEFINE3()
4567 return current->blocked.sig[0]; in SYSCALL_DEFINE0()
4572 int old = current->blocked.sig[0]; in SYSCALL_DEFINE1()
4586 SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler) in SYSCALL_DEFINE2() argument
4609 return -ERESTARTNOHAND; in SYSCALL_DEFINE0()
4616 current->saved_sigmask = current->blocked; in sigsuspend()
4624 return -ERESTARTNOHAND; in sigsuspend()
4628 * sys_rt_sigsuspend - replace the signal mask for a value with the
4629 * @unewset value until a signal is received
4630 * @unewset: new signal mask value
4639 return -EINVAL; in SYSCALL_DEFINE2()
4642 return -EFAULT; in SYSCALL_DEFINE2()
4653 return -EINVAL; in COMPAT_SYSCALL_DEFINE2()
4656 return -EFAULT; in COMPAT_SYSCALL_DEFINE2()
4766 * kdb_send_sig - Allows kdb to send signals without exposing
4767 * signal internals. This function checks if the required locks are
4768 * available before calling the main signal code, to avoid kdb
4775 if (!spin_trylock(&t->sighand->siglock)) { in kdb_send_sig()
4784 spin_unlock(&t->sighand->siglock); in kdb_send_sig()
4785 kdb_printf("Process is not RUNNING, sending a signal from " in kdb_send_sig()
4788 "The signal has _not_ been sent.\n" in kdb_send_sig()
4794 spin_unlock(&t->sighand->siglock); in kdb_send_sig()
4796 kdb_printf("Fail to deliver Signal %d to process %d.\n", in kdb_send_sig()
4797 sig, t->pid); in kdb_send_sig()
4799 kdb_printf("Signal %d is sent to process %d.\n", sig, t->pid); in kdb_send_sig()