^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/kernel/signal.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 2003-06-02 Jim Houston - Concurrent Computer Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Changes to use preallocated sigqueue structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * to allow signals to be sent reliably.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sched/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sched/cputime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/coredump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/signalfd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/user_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/uprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/cn_proc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/posix-timers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/livepatch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/oom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <trace/events/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <asm/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <asm/siginfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #undef CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <trace/hooks/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * SLAB caches for signal bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct kmem_cache *sigqueue_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int print_fatal_signals __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static void __user *sig_handler(struct task_struct *t, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return t->sighand->action[sig - 1].sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline bool sig_handler_ignored(void __user *handler, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Is it explicitly or implicitly ignored? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return handler == SIG_IGN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) (handler == SIG_DFL && sig_kernel_ignore(sig));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static bool sig_task_ignored(struct task_struct *t, int sig, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void __user *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) handler = sig_handler(t, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* SIGKILL and SIGSTOP may not be sent to the global init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (unlikely(is_global_init(t) && sig_kernel_only(sig)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) handler == SIG_DFL && !(force && sig_kernel_only(sig)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Only allow kernel generated signals to this kthread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (unlikely((t->flags & PF_KTHREAD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) (handler == SIG_KTHREAD_KERNEL) && !force))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return sig_handler_ignored(handler, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static bool sig_ignored(struct task_struct *t, int sig, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * Blocked signals are never ignored, since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * signal handler may change by the time it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * unblocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * Tracers may want to know about even ignored signal unless it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * is SIGKILL which can't be reported anyway but can be ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * by SIGNAL_UNKILLABLE task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (t->ptrace && sig != SIGKILL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return sig_task_ignored(t, sig, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Re-calculate pending state from the set of locally pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * signals, globally pending signals, and blocked signals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline bool has_pending_signals(sigset_t *signal, sigset_t *blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) switch (_NSIG_WORDS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ready |= signal->sig[i] &~ blocked->sig[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) case 4: ready = signal->sig[3] &~ blocked->sig[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ready |= signal->sig[2] &~ blocked->sig[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ready |= signal->sig[1] &~ blocked->sig[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ready |= signal->sig[0] &~ blocked->sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case 2: ready = signal->sig[1] &~ blocked->sig[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ready |= signal->sig[0] &~ blocked->sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) case 1: ready = signal->sig[0] &~ blocked->sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return ready != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static bool recalc_sigpending_tsk(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if ((t->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) PENDING(&t->pending, &t->blocked) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) PENDING(&t->signal->shared_pending, &t->blocked) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) cgroup_task_frozen(t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) set_tsk_thread_flag(t, TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * We must never clear the flag in another thread, or in current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * when it's possible the current syscall is returning -ERESTART*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * So we don't clear it here, and only callers who know they should do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * This is superfluous when called on current, the wakeup is a harmless no-op.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void recalc_sigpending_and_wake(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (recalc_sigpending_tsk(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) signal_wake_up(t, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) void recalc_sigpending(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!recalc_sigpending_tsk(current) && !freezing(current) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) !klp_patch_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) clear_thread_flag(TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) EXPORT_SYMBOL(recalc_sigpending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void calculate_sigpending(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Have any signals or users of TIF_SIGPENDING been delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * until after fork?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) set_tsk_thread_flag(current, TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* Given the mask, find the first available signal that should be serviced. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define SYNCHRONOUS_MASK \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) (sigmask(SIGSEGV) | sigmask(SIGBUS) | sigmask(SIGILL) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) sigmask(SIGTRAP) | sigmask(SIGFPE) | sigmask(SIGSYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int next_signal(struct sigpending *pending, sigset_t *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) unsigned long i, *s, *m, x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int sig = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) s = pending->signal.sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) m = mask->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Handle the first word specially: it contains the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * synchronous signals that need to be dequeued first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) x = *s &~ *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (x) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (x & SYNCHRONOUS_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) x &= SYNCHRONOUS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) sig = ffz(~x) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) switch (_NSIG_WORDS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) for (i = 1; i < _NSIG_WORDS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) x = *++s &~ *++m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sig = ffz(~x) + i*_NSIG_BPW + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) x = s[1] &~ m[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) sig = ffz(~x) + _NSIG_BPW + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline void print_dropped_signal(int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!print_fatal_signals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!__ratelimit(&ratelimit_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) pr_info("%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) current->comm, current->pid, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * task_set_jobctl_pending - set jobctl pending bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @task: target task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * @mask: pending bits to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Clear @mask from @task->jobctl. @mask must be subset of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * %JOBCTL_PENDING_MASK | %JOBCTL_STOP_CONSUME | %JOBCTL_STOP_SIGMASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * %JOBCTL_TRAPPING. If stop signo is being set, the existing signo is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * cleared. If @task is already being killed or exiting, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * becomes noop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Must be called with @task->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * %true if @mask is set, %false if made noop because @task was dying.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bool task_set_jobctl_pending(struct task_struct *task, unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) BUG_ON(mask & ~(JOBCTL_PENDING_MASK | JOBCTL_STOP_CONSUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) JOBCTL_STOP_SIGMASK | JOBCTL_TRAPPING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) BUG_ON((mask & JOBCTL_TRAPPING) && !(mask & JOBCTL_PENDING_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (unlikely(fatal_signal_pending(task) || (task->flags & PF_EXITING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (mask & JOBCTL_STOP_SIGMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) task->jobctl &= ~JOBCTL_STOP_SIGMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) task->jobctl |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * task_clear_jobctl_trapping - clear jobctl trapping bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * @task: target task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * If JOBCTL_TRAPPING is set, a ptracer is waiting for us to enter TRACED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Clear it and wake up the ptracer. Note that we don't need any further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * locking. @task->siglock guarantees that @task->parent points to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * ptracer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * Must be called with @task->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void task_clear_jobctl_trapping(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (unlikely(task->jobctl & JOBCTL_TRAPPING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) task->jobctl &= ~JOBCTL_TRAPPING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) smp_mb(); /* advised by wake_up_bit() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) wake_up_bit(&task->jobctl, JOBCTL_TRAPPING_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * task_clear_jobctl_pending - clear jobctl pending bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * @task: target task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * @mask: pending bits to clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * Clear @mask from @task->jobctl. @mask must be subset of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * %JOBCTL_PENDING_MASK. If %JOBCTL_STOP_PENDING is being cleared, other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * STOP bits are cleared together.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * If clearing of @mask leaves no stop or trap pending, this function calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * task_clear_jobctl_trapping().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * Must be called with @task->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) void task_clear_jobctl_pending(struct task_struct *task, unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) BUG_ON(mask & ~JOBCTL_PENDING_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (mask & JOBCTL_STOP_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) mask |= JOBCTL_STOP_CONSUME | JOBCTL_STOP_DEQUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) task->jobctl &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!(task->jobctl & JOBCTL_PENDING_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) task_clear_jobctl_trapping(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * task_participate_group_stop - participate in a group stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * @task: task participating in a group stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * Group stop states are cleared and the group stop count is consumed if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * %JOBCTL_STOP_CONSUME was set. If the consumption completes the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * stop, the appropriate `SIGNAL_*` flags are set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * Must be called with @task->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * %true if group stop completion should be notified to the parent, %false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static bool task_participate_group_stop(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct signal_struct *sig = task->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) bool consume = task->jobctl & JOBCTL_STOP_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) task_clear_jobctl_pending(task, JOBCTL_STOP_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!consume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (!WARN_ON_ONCE(sig->group_stop_count == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) sig->group_stop_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * Tell the caller to notify completion iff we are entering into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * fresh group stop. Read comment in do_signal_stop() for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (!sig->group_stop_count && !(sig->flags & SIGNAL_STOP_STOPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) signal_set_stop_flags(sig, SIGNAL_STOP_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) void task_join_group_stop(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) unsigned long mask = current->jobctl & JOBCTL_STOP_SIGMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct signal_struct *sig = current->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (sig->group_stop_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) sig->group_stop_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) mask |= JOBCTL_STOP_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) } else if (!(sig->flags & SIGNAL_STOP_STOPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /* Have the new thread join an on-going signal group stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * allocate a new signal queue record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * - this may be called without locks if and only if t == current, otherwise an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * appropriate lock must be held to stop the target task from exiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static struct sigqueue *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct sigqueue *q = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct user_struct *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int sigpending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * Protect access to @t credentials. This can go away when all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * callers hold rcu read lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * NOTE! A pending signal will hold on to the user refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * and we get/put the refcount only when the sigpending count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * changes from/to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) user = __task_cred(t)->user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) sigpending = atomic_inc_return(&user->sigpending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (sigpending == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) get_uid(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) q = kmem_cache_alloc(sigqueue_cachep, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) print_dropped_signal(sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (unlikely(q == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (atomic_dec_and_test(&user->sigpending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) free_uid(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) INIT_LIST_HEAD(&q->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) q->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) q->user = user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static void __sigqueue_free(struct sigqueue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (q->flags & SIGQUEUE_PREALLOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (atomic_dec_and_test(&q->user->sigpending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) free_uid(q->user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) kmem_cache_free(sigqueue_cachep, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) void flush_sigqueue(struct sigpending *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct sigqueue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) sigemptyset(&queue->signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) while (!list_empty(&queue->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) q = list_entry(queue->list.next, struct sigqueue , list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) list_del_init(&q->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) __sigqueue_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * Flush all pending signals for this kthread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) void flush_signals(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) spin_lock_irqsave(&t->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) clear_tsk_thread_flag(t, TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) flush_sigqueue(&t->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) flush_sigqueue(&t->signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) spin_unlock_irqrestore(&t->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) EXPORT_SYMBOL(flush_signals);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) #ifdef CONFIG_POSIX_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static void __flush_itimer_signals(struct sigpending *pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) sigset_t signal, retain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct sigqueue *q, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) signal = pending->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) sigemptyset(&retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) list_for_each_entry_safe(q, n, &pending->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) int sig = q->info.si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (likely(q->info.si_code != SI_TIMER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) sigaddset(&retain, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) sigdelset(&signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) list_del_init(&q->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) __sigqueue_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) sigorsets(&pending->signal, &signal, &retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) void flush_itimer_signals(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) spin_lock_irqsave(&tsk->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) __flush_itimer_signals(&tsk->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) __flush_itimer_signals(&tsk->signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) void ignore_signals(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) for (i = 0; i < _NSIG; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) t->sighand->action[i].sa.sa_handler = SIG_IGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) flush_signals(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * Flush all handlers for a task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) flush_signal_handlers(struct task_struct *t, int force_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct k_sigaction *ka = &t->sighand->action[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) for (i = _NSIG ; i != 0 ; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (force_default || ka->sa.sa_handler != SIG_IGN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) ka->sa.sa_handler = SIG_DFL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) ka->sa.sa_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #ifdef __ARCH_HAS_SA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) ka->sa.sa_restorer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) sigemptyset(&ka->sa.sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ka++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) bool unhandled_signal(struct task_struct *tsk, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (is_global_init(tsk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (handler != SIG_IGN && handler != SIG_DFL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* if ptraced, let the tracer determine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return !tsk->ptrace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static void collect_signal(int sig, struct sigpending *list, kernel_siginfo_t *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) bool *resched_timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct sigqueue *q, *first = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * Collect the siginfo appropriate to this signal. Check if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * there is another siginfo for the same signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) list_for_each_entry(q, &list->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (q->info.si_signo == sig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) goto still_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) first = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) sigdelset(&list->signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) still_pending:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) list_del_init(&first->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) copy_siginfo(info, &first->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) *resched_timer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) (first->flags & SIGQUEUE_PREALLOC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) (info->si_code == SI_TIMER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) (info->si_sys_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) __sigqueue_free(first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * Ok, it wasn't in the queue. This must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * a fast-pathed signal or we must have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * out of queue space. So zero out the info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) clear_siginfo(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) info->si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) info->si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) info->si_code = SI_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) info->si_pid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) info->si_uid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) kernel_siginfo_t *info, bool *resched_timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int sig = next_signal(pending, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) collect_signal(sig, pending, info, resched_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * Dequeue a signal and return the element to the caller, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * expected to free it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * All callers have to hold the siglock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) int dequeue_signal(struct task_struct *tsk, sigset_t *mask, kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) bool resched_timer = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* We only dequeue private signals from ourselves, we don't let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * signalfd steal them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) signr = __dequeue_signal(&tsk->pending, mask, info, &resched_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (!signr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) signr = __dequeue_signal(&tsk->signal->shared_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) mask, info, &resched_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) #ifdef CONFIG_POSIX_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * itimer signal ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * itimers are process shared and we restart periodic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * itimers in the signal delivery path to prevent DoS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * attacks in the high resolution timer case. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * compliant with the old way of self-restarting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * itimers, as the SIGALRM is a legacy signal and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * queued once. Changing the restart behaviour to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * restart the timer in the signal dequeue path is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * reducing the timer noise on heavy loaded !highres
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * systems too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (unlikely(signr == SIGALRM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct hrtimer *tmr = &tsk->signal->real_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (!hrtimer_is_queued(tmr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) tsk->signal->it_real_incr != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) hrtimer_forward(tmr, tmr->base->get_time(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) tsk->signal->it_real_incr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) hrtimer_restart(tmr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (!signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (unlikely(sig_kernel_stop(signr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * Set a marker that we have dequeued a stop signal. Our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * caller might release the siglock and then the pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * stop signal it is about to process is no longer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) * pending bitmasks, but must still be cleared by a SIGCONT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) * (and overruled by a SIGKILL). So those cases clear this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * shared flag after we've set it. Note that this flag may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * remain set after the signal we return is ignored or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * handled. That doesn't matter because its only purpose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * is to alert stop-signal processing code when another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * processor has come along and cleared the flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) current->jobctl |= JOBCTL_STOP_DEQUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) #ifdef CONFIG_POSIX_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (resched_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * Release the siglock to ensure proper locking order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * of timer locks outside of siglocks. Note, we leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * irqs disabled here, since the posix-timers code is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * about to disable them again anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) spin_unlock(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) posixtimer_rearm(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) spin_lock(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /* Don't expose the si_sys_private value to userspace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) info->si_sys_private = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) EXPORT_SYMBOL_GPL(dequeue_signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static int dequeue_synchronous_signal(kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct sigpending *pending = &tsk->pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct sigqueue *q, *sync = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * Might a synchronous signal be in the queue?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!((pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * Return the first synchronous signal in the queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) list_for_each_entry(q, &pending->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /* Synchronous signals have a positive si_code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if ((q->info.si_code > SI_USER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) sync = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * Check if there is another siginfo for the same signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) list_for_each_entry_continue(q, &pending->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (q->info.si_signo == sync->info.si_signo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) goto still_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) sigdelset(&pending->signal, sync->info.si_signo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) still_pending:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) list_del_init(&sync->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) copy_siginfo(info, &sync->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) __sigqueue_free(sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return info->si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * Tell a process that it has a new active signal..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * NOTE! we rely on the previous spin_lock to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * lock interrupts for us! We can only be called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * "siglock" held, and the local interrupt must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * have been disabled when that got acquired!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * No need to set need_resched since signal event passing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * goes through ->blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) void signal_wake_up_state(struct task_struct *t, unsigned int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) set_tsk_thread_flag(t, TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * TASK_WAKEKILL also means wake it up in the stopped/traced/killable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * case. We don't check t->state here because there is a race with it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * executing another processor and just now entering stopped state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * By using wake_up_state, we ensure the process will wake up and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * handle its death signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!wake_up_state(t, state | TASK_INTERRUPTIBLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) kick_process(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * Remove signals in mask from the pending set and queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * Returns 1 if any signals were found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * All callers must be holding the siglock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static void flush_sigqueue_mask(sigset_t *mask, struct sigpending *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct sigqueue *q, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) sigset_t m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) sigandsets(&m, mask, &s->signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (sigisemptyset(&m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) sigandnsets(&s->signal, &s->signal, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) list_for_each_entry_safe(q, n, &s->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (sigismember(mask, q->info.si_signo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) list_del_init(&q->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) __sigqueue_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) static inline int is_si_special(const struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return info <= SEND_SIG_PRIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static inline bool si_fromuser(const struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return info == SEND_SIG_NOINFO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) (!is_si_special(info) && SI_FROMUSER(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * called with RCU read lock from check_kill_permission()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static bool kill_ok_by_cred(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) const struct cred *cred = current_cred();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) const struct cred *tcred = __task_cred(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return uid_eq(cred->euid, tcred->suid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) uid_eq(cred->euid, tcred->uid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) uid_eq(cred->uid, tcred->suid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) uid_eq(cred->uid, tcred->uid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) ns_capable(tcred->user_ns, CAP_KILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * Bad permissions for sending the signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * - the caller must hold the RCU read lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) static int check_kill_permission(int sig, struct kernel_siginfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct pid *sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (!valid_signal(sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!si_fromuser(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) error = audit_signal_info(sig, t); /* Let audit system see the signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (!same_thread_group(current, t) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) !kill_ok_by_cred(t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) switch (sig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) case SIGCONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) sid = task_session(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * We don't return the error if sid == NULL. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * task was unhashed, the caller must notice this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (!sid || sid == task_session(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return security_task_kill(t, info, sig, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) * ptrace_trap_notify - schedule trap to notify ptracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) * @t: tracee wanting to notify tracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * This function schedules sticky ptrace trap which is cleared on the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * TRAP_STOP to notify ptracer of an event. @t must have been seized by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * ptracer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * If @t is running, STOP trap will be taken. If trapped for STOP and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * ptracer is listening for events, tracee is woken up so that it can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * re-trap for the new event. If trapped otherwise, STOP trap will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * eventually taken without returning to userland after the existing traps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * are finished by PTRACE_CONT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * Must be called with @task->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) static void ptrace_trap_notify(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) WARN_ON_ONCE(!(t->ptrace & PT_SEIZED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) assert_spin_locked(&t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) task_set_jobctl_pending(t, JOBCTL_TRAP_NOTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ptrace_signal_wake_up(t, t->jobctl & JOBCTL_LISTENING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * Handle magic process-wide effects of stop/continue signals. Unlike
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * the signal actions, these happen immediately at signal-generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * time regardless of blocking, ignoring, or handling. This does the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) * actual continuing for SIGCONT, but not the actual stopping for stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * signals. The process stop is done as a signal action for SIG_DFL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * Returns true if the signal should be actually delivered, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * it should be dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) static bool prepare_signal(int sig, struct task_struct *p, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct signal_struct *signal = p->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct task_struct *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) sigset_t flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!(signal->flags & SIGNAL_GROUP_EXIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return sig == SIGKILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * The process is in the middle of dying, nothing to do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) } else if (sig_kernel_stop(sig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) * This is a stop signal. Remove SIGCONT from all queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) siginitset(&flush, sigmask(SIGCONT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) flush_sigqueue_mask(&flush, &signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) for_each_thread(p, t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) flush_sigqueue_mask(&flush, &t->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) } else if (sig == SIGCONT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) unsigned int why;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * Remove all stop signals from all queues, wake all threads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) siginitset(&flush, SIG_KERNEL_STOP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) flush_sigqueue_mask(&flush, &signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) for_each_thread(p, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) flush_sigqueue_mask(&flush, &t->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) task_clear_jobctl_pending(t, JOBCTL_STOP_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (likely(!(t->ptrace & PT_SEIZED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) wake_up_state(t, __TASK_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) ptrace_trap_notify(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) * Notify the parent with CLD_CONTINUED if we were stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) * If we were in the middle of a group stop, we pretend it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) * was already finished, and then continued. Since SIGCHLD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) * doesn't queue we report only CLD_STOPPED, as if the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * CLD_CONTINUED was dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) why = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (signal->flags & SIGNAL_STOP_STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) why |= SIGNAL_CLD_CONTINUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) else if (signal->group_stop_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) why |= SIGNAL_CLD_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (why) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * The first thread which returns from do_signal_stop()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * will take ->siglock, notice SIGNAL_CLD_MASK, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) * notify its parent. See get_signal().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) signal->group_stop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) signal->group_exit_code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return !sig_ignored(p, sig, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * Test if P wants to take SIG. After we've checked all threads with this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * it's equivalent to finding no threads not blocking SIG. Any threads not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * blocking SIG were ruled out because they are not running and already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * have pending signals. Such threads will dequeue from the shared queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * as soon as they're available, so putting the signal on the shared queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) * will be equivalent to sending it to one such thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) static inline bool wants_signal(int sig, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (sigismember(&p->blocked, sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (p->flags & PF_EXITING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (sig == SIGKILL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (task_is_stopped_or_traced(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return task_curr(p) || !signal_pending(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) struct signal_struct *signal = p->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct task_struct *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) * Now find a thread we can wake up to take the signal off the queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * If the main thread wants the signal, it gets first crack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) * Probably the least surprising to the average bear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (wants_signal(sig, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) t = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) else if ((type == PIDTYPE_PID) || thread_group_empty(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) * There is just one thread and it does not need to be woken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) * It will dequeue unblocked signals before it runs again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) * Otherwise try to find a suitable thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) t = signal->curr_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) while (!wants_signal(sig, t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) t = next_thread(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (t == signal->curr_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * No thread needs to be woken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * Any eligible threads will see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * the signal in the queue soon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) signal->curr_target = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * Found a killable thread. If the signal will be fatal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) * then start taking the whole group down immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (sig_fatal(p, sig) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) !(signal->flags & SIGNAL_GROUP_EXIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) !sigismember(&t->real_blocked, sig) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) (sig == SIGKILL || !p->ptrace)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * This signal will be fatal to the whole group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (!sig_kernel_coredump(sig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) * Start a group exit and wake everybody up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * This way we don't have other threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * running and doing things after a slower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) * thread has the fatal signal pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) signal->flags = SIGNAL_GROUP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) signal->group_exit_code = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) signal->group_stop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) t = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) sigaddset(&t->pending.signal, SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) signal_wake_up(t, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) } while_each_thread(p, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * The signal is already in the shared-pending queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * Tell the chosen thread to wake up and dequeue it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) signal_wake_up(t, sig == SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static inline bool legacy_queue(struct sigpending *signals, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) enum pid_type type, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct sigpending *pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct sigqueue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) int override_rlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) int ret = 0, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) assert_spin_locked(&t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) result = TRACE_SIGNAL_IGNORED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (!prepare_signal(sig, t, force))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * Short-circuit ignored signals and support queuing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) * exactly one non-rt signal, so that we can get more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * detailed information about the cause of the signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) result = TRACE_SIGNAL_ALREADY_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (legacy_queue(pending, sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) result = TRACE_SIGNAL_DELIVERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) * Skip useless siginfo allocation for SIGKILL and kernel threads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if ((sig == SIGKILL) || (t->flags & PF_KTHREAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) goto out_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) * Real-time signals must be queued if sent by sigqueue, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) * some other real-time mechanism. It is implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) * defined whether kill() does so. We attempt to do so, on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * the principle of least surprise, but since kill is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * allowed to fail with EAGAIN when low on memory we just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) * make sure at least one signal gets delivered and don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) * pass on the info struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (sig < SIGRTMIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) override_rlimit = (is_si_special(info) || info->si_code >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) override_rlimit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) q = __sigqueue_alloc(sig, t, GFP_ATOMIC, override_rlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) list_add_tail(&q->list, &pending->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) switch ((unsigned long) info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) case (unsigned long) SEND_SIG_NOINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) clear_siginfo(&q->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) q->info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) q->info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) q->info.si_code = SI_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) q->info.si_pid = task_tgid_nr_ns(current,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) task_active_pid_ns(t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) q->info.si_uid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) from_kuid_munged(task_cred_xxx(t, user_ns),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) current_uid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) case (unsigned long) SEND_SIG_PRIV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) clear_siginfo(&q->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) q->info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) q->info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) q->info.si_code = SI_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) q->info.si_pid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) q->info.si_uid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) copy_siginfo(&q->info, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) } else if (!is_si_special(info) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) sig >= SIGRTMIN && info->si_code != SI_USER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) * Queue overflow, abort. We may abort if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) * signal was rt and sent by user using something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * other than kill().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) result = TRACE_SIGNAL_OVERFLOW_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) * This is a silent loss of information. We still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) * send the signal, but the *info bits are lost.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) result = TRACE_SIGNAL_LOSE_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) out_set:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) signalfd_notify(t, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) sigaddset(&pending->signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) /* Let multiprocess signals appear after on-going forks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (type > PIDTYPE_TGID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct multiprocess_signals *delayed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) hlist_for_each_entry(delayed, &t->signal->multiprocess, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) sigset_t *signal = &delayed->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /* Can't queue both a stop and a continue signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (sig == SIGCONT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) sigdelsetmask(signal, SIG_KERNEL_STOP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) else if (sig_kernel_stop(sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) sigdelset(signal, SIGCONT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) sigaddset(signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) complete_signal(sig, t, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) trace_signal_generate(sig, info, t, type != PIDTYPE_PID, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) switch (siginfo_layout(info->si_signo, info->si_code)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) case SIL_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) case SIL_CHLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) case SIL_RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) case SIL_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) case SIL_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) case SIL_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) case SIL_FAULT_MCEERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) case SIL_FAULT_BNDERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) case SIL_FAULT_PKUERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) case SIL_SYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) static int send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) enum pid_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) bool force = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (info == SEND_SIG_NOINFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) /* Force if sent from an ancestor pid namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) force = !task_pid_nr_ns(current, task_active_pid_ns(t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) } else if (info == SEND_SIG_PRIV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /* Don't ignore kernel generated signals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) force = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) } else if (has_si_pid_and_uid(info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) /* SIGKILL and SIGSTOP is special or has ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) struct user_namespace *t_user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) t_user_ns = task_cred_xxx(t, user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (current_user_ns() != t_user_ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) kuid_t uid = make_kuid(current_user_ns(), info->si_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) info->si_uid = from_kuid_munged(t_user_ns, uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) /* A kernel generated signal? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) force = (info->si_code == SI_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) /* From an ancestor pid namespace? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) info->si_pid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) force = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) return __send_signal(sig, info, t, type, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) static void print_fatal_signal(int signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct pt_regs *regs = signal_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) pr_info("potentially unexpected fatal signal %d.\n", signr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) #if defined(__i386__) && !defined(__arch_um__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) pr_info("code at %08lx: ", regs->ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) for (i = 0; i < 16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) unsigned char insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (get_user(insn, (unsigned char *)(regs->ip + i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) pr_cont("%02x ", insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) static int __init setup_print_fatal_signals(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) get_option (&str, &print_fatal_signals);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) __setup("print-fatal-signals=", setup_print_fatal_signals);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) __group_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return send_signal(sig, info, p, PIDTYPE_TGID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) enum pid_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) int ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) trace_android_vh_do_send_sig_info(sig, current, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) if (lock_task_sighand(p, &flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) ret = send_signal(sig, info, p, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) unlock_task_sighand(p, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) * Force a signal that the process can't ignore: if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) * we unblock the signal and change any SIG_IGN to SIG_DFL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) * Note: If we unblock the signal, we always reset it to SIG_DFL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) * since we do not want to have a signal handler that was blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) * be invoked when user space had explicitly blocked it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) * We don't want to have recursive SIGSEGV's etc, for example,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) * that is why we also clear SIGNAL_UNKILLABLE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) unsigned long int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) int ret, blocked, ignored;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) struct k_sigaction *action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) int sig = info->si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) spin_lock_irqsave(&t->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) action = &t->sighand->action[sig-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) ignored = action->sa.sa_handler == SIG_IGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) blocked = sigismember(&t->blocked, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (blocked || ignored) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) action->sa.sa_handler = SIG_DFL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (blocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) sigdelset(&t->blocked, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) recalc_sigpending_and_wake(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) * Don't clear SIGNAL_UNKILLABLE for traced tasks, users won't expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) * debugging to leave init killable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (action->sa.sa_handler == SIG_DFL && !t->ptrace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) t->signal->flags &= ~SIGNAL_UNKILLABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) ret = send_signal(sig, info, t, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) spin_unlock_irqrestore(&t->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) int force_sig_info(struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return force_sig_info_to_task(info, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) * Nuke all other threads in the group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) int zap_other_threads(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) struct task_struct *t = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) p->signal->group_stop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) while_each_thread(p, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) /* Don't bother with already dead threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (t->exit_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) sigaddset(&t->pending.signal, SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) signal_wake_up(t, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct sighand_struct *sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) sighand = rcu_dereference(tsk->sighand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (unlikely(sighand == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) * This sighand can be already freed and even reused, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) * we rely on SLAB_TYPESAFE_BY_RCU and sighand_ctor() which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) * initializes ->siglock: this slab can't go away, it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) * the same object type, ->siglock can't be reinitialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) * We need to ensure that tsk->sighand is still the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) * after we take the lock, we can race with de_thread() or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) * __exit_signal(). In the latter case the next iteration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) * must see ->sighand == NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) spin_lock_irqsave(&sighand->siglock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (likely(sighand == rcu_access_pointer(tsk->sighand)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) spin_unlock_irqrestore(&sighand->siglock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) return sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) EXPORT_SYMBOL_GPL(__lock_task_sighand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) * send signal info to all the members of a group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) int group_send_sig_info(int sig, struct kernel_siginfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) struct task_struct *p, enum pid_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) ret = check_kill_permission(sig, info, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (!ret && sig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) ret = do_send_sig_info(sig, info, p, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) if (!ret && sig == SIGKILL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) bool reap = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) trace_android_vh_process_killed(current, &reap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) trace_android_vh_killed_process(current, p, &reap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) if (reap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) add_to_oom_reaper(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) * __kill_pgrp_info() sends a signal to a process group: this is what the tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) * control characters do (^C, ^Z etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * - the caller must hold at least a readlock on tasklist_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) int __kill_pgrp_info(int sig, struct kernel_siginfo *info, struct pid *pgrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) struct task_struct *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) int retval, success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) success = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) retval = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) int err = group_send_sig_info(sig, info, p, PIDTYPE_PGID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) success |= !err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) retval = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) return success ? 0 : retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) int kill_pid_info(int sig, struct kernel_siginfo *info, struct pid *pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) int error = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) struct task_struct *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) p = pid_task(pid, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) error = group_send_sig_info(sig, info, p, PIDTYPE_TGID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) if (likely(!p || error != -ESRCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) * The task was unhashed in between, try again. If it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) * is dead, pid_task() will return NULL, if we race with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) * de_thread() it will find the new leader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) static int kill_proc_info(int sig, struct kernel_siginfo *info, pid_t pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) error = kill_pid_info(sig, info, find_vpid(pid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) static inline bool kill_as_cred_perm(const struct cred *cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) struct task_struct *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) const struct cred *pcred = __task_cred(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) return uid_eq(cred->euid, pcred->suid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) uid_eq(cred->euid, pcred->uid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) uid_eq(cred->uid, pcred->suid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) uid_eq(cred->uid, pcred->uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) * The usb asyncio usage of siginfo is wrong. The glibc support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) * for asyncio which uses SI_ASYNCIO assumes the layout is SIL_RT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) * AKA after the generic fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * kernel_pid_t si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * kernel_uid32_t si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) * sigval_t si_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) * Unfortunately when usb generates SI_ASYNCIO it assumes the layout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) * after the generic fields is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) * void __user *si_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * This is a practical problem when there is a 64bit big endian kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * and a 32bit userspace. As the 32bit address will encoded in the low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) * 32bits of the pointer. Those low 32bits will be stored at higher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) * address than appear in a 32 bit pointer. So userspace will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) * see the address it was expecting for it's completions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) * There is nothing in the encoding that can allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * copy_siginfo_to_user32 to detect this confusion of formats, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) * handle this by requiring the caller of kill_pid_usb_asyncio to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) * notice when this situration takes place and to store the 32bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) * pointer in sival_int, instead of sival_addr of the sigval_t addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) * parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) int kill_pid_usb_asyncio(int sig, int errno, sigval_t addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) struct pid *pid, const struct cred *cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) struct task_struct *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (!valid_signal(sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) info.si_errno = errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) info.si_code = SI_ASYNCIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) *((sigval_t *)&info.si_pid) = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) p = pid_task(pid, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) if (!kill_as_cred_perm(cred, p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) ret = security_task_kill(p, &info, sig, cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (sig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (lock_task_sighand(p, &flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) ret = __send_signal(sig, &info, p, PIDTYPE_TGID, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) unlock_task_sighand(p, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) EXPORT_SYMBOL_GPL(kill_pid_usb_asyncio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) * kill_something_info() interprets pid in interesting ways just like kill(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) * POSIX specifies that kill(-1,sig) is unspecified, but what we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) * is probably wrong. Should make it like BSD or SYSV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) static int kill_something_info(int sig, struct kernel_siginfo *info, pid_t pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) if (pid > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) return kill_proc_info(sig, info, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) if (pid == INT_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) return -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) if (pid != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) ret = __kill_pgrp_info(sig, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) pid ? find_vpid(-pid) : task_pgrp(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) int retval = 0, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct task_struct * p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) for_each_process(p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (task_pid_vnr(p) > 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) !same_thread_group(p, current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) int err = group_send_sig_info(sig, info, p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) PIDTYPE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) ++count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (err != -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) retval = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) ret = count ? retval : -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) * These are for backward compatibility with the rest of the kernel source.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) int send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) * Make sure legacy kernel users don't send in bad values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) * (normal paths check this in check_kill_permission).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) if (!valid_signal(sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) return do_send_sig_info(sig, info, p, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) EXPORT_SYMBOL(send_sig_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) #define __si_special(priv) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) send_sig(int sig, struct task_struct *p, int priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) return send_sig_info(sig, __si_special(priv), p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) EXPORT_SYMBOL(send_sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) void force_sig(int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) info.si_code = SI_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) info.si_pid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) info.si_uid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) force_sig_info(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) EXPORT_SYMBOL(force_sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) * When things go south during signal handling, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * will force a SIGSEGV. And if the signal that caused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * the problem was already a SIGSEGV, we'll want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * make sure we don't even try to deliver the signal..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) void force_sigsegv(int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) struct task_struct *p = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) if (sig == SIGSEGV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) spin_lock_irqsave(&p->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) spin_unlock_irqrestore(&p->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) int force_sig_fault_to_task(int sig, int code, void __user *addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) ___ARCH_SI_TRAPNO(int trapno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) , struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) info.si_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) info.si_trapno = trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) #ifdef __ia64__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) info.si_imm = imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) info.si_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) info.si_isr = isr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) return force_sig_info_to_task(&info, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) int force_sig_fault(int sig, int code, void __user *addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) ___ARCH_SI_TRAPNO(int trapno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) return force_sig_fault_to_task(sig, code, addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) ___ARCH_SI_TRAPNO(trapno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) ___ARCH_SI_IA64(imm, flags, isr), current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) int send_sig_fault(int sig, int code, void __user *addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) ___ARCH_SI_TRAPNO(int trapno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) , struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) info.si_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) info.si_trapno = trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) #ifdef __ia64__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) info.si_imm = imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) info.si_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) info.si_isr = isr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) return send_sig_info(info.si_signo, &info, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) int force_sig_mceerr(int code, void __user *addr, short lsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) info.si_signo = SIGBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) info.si_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) info.si_addr_lsb = lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) return force_sig_info(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) info.si_signo = SIGBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) info.si_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) info.si_addr_lsb = lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) return send_sig_info(info.si_signo, &info, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) EXPORT_SYMBOL(send_sig_mceerr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) info.si_signo = SIGSEGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) info.si_code = SEGV_BNDERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) info.si_lower = lower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) info.si_upper = upper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) return force_sig_info(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) #ifdef SEGV_PKUERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) int force_sig_pkuerr(void __user *addr, u32 pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) info.si_signo = SIGSEGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) info.si_code = SEGV_PKUERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) info.si_pkey = pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) return force_sig_info(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) /* For the crazy architectures that include trap information in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) * the errno field, instead of an actual errno value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) int force_sig_ptrace_errno_trap(int errno, void __user *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) info.si_signo = SIGTRAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) info.si_errno = errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) info.si_code = TRAP_HWBKPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) info.si_addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) return force_sig_info(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) int kill_pgrp(struct pid *pid, int sig, int priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) ret = __kill_pgrp_info(sig, __si_special(priv), pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) EXPORT_SYMBOL(kill_pgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) int kill_pid(struct pid *pid, int sig, int priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) return kill_pid_info(sig, __si_special(priv), pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) EXPORT_SYMBOL(kill_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) * These functions support sending signals using preallocated sigqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) * structures. This is needed "because realtime applications cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) * afford to lose notifications of asynchronous events, like timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) * expirations or I/O completions". In the case of POSIX Timers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) * we allocate the sigqueue structure from the timer_create. If this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) * allocation fails we are able to report the failure to the application
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) * with an EAGAIN error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) struct sigqueue *sigqueue_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) if (q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) q->flags |= SIGQUEUE_PREALLOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) return q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) void sigqueue_free(struct sigqueue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) spinlock_t *lock = ¤t->sighand->siglock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) * We must hold ->siglock while testing q->list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) * to serialize with collect_signal() or with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) * __exit_signal()->flush_sigqueue().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) spin_lock_irqsave(lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) q->flags &= ~SIGQUEUE_PREALLOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) * If it is queued it will be freed when dequeued,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) * like the "regular" sigqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) if (!list_empty(&q->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) q = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) spin_unlock_irqrestore(lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) __sigqueue_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) int sig = q->info.si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) struct sigpending *pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct task_struct *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) int ret, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) t = pid_task(pid, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) if (!t || !likely(lock_task_sighand(t, &flags)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) ret = 1; /* the signal is ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) result = TRACE_SIGNAL_IGNORED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) if (!prepare_signal(sig, t, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) if (unlikely(!list_empty(&q->list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) * If an SI_TIMER entry is already queue just increment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) * the overrun count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) BUG_ON(q->info.si_code != SI_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) q->info.si_overrun++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) result = TRACE_SIGNAL_ALREADY_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) q->info.si_overrun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) signalfd_notify(t, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) list_add_tail(&q->list, &pending->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) sigaddset(&pending->signal, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) complete_signal(sig, t, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) result = TRACE_SIGNAL_DELIVERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) unlock_task_sighand(t, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) static void do_notify_pidfd(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) struct pid *pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) WARN_ON(task->exit_state == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) pid = task_pid(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) wake_up_all(&pid->wait_pidfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) * Let a parent know about the death of a child.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) * For a stopped/continued status change, use do_notify_parent_cldstop instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) * Returns true if our parent ignored us and so we've switched to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) * self-reaping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) bool do_notify_parent(struct task_struct *tsk, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) struct sighand_struct *psig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) bool autoreap = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) u64 utime, stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) BUG_ON(sig == -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) /* do_notify_parent_cldstop should have been called instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) BUG_ON(task_is_stopped_or_traced(tsk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) BUG_ON(!tsk->ptrace &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) (tsk->group_leader != tsk || !thread_group_empty(tsk)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) /* Wake up all pidfd waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) do_notify_pidfd(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) if (sig != SIGCHLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) * This is only possible if parent == real_parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) * Check if it has changed security domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) if (tsk->parent_exec_id != READ_ONCE(tsk->parent->self_exec_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) sig = SIGCHLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) * We are under tasklist_lock here so our parent is tied to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) * us and cannot change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) * task_active_pid_ns will always return the same pid namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) * until a task passes through release_task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) * write_lock() currently calls preempt_disable() which is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) * same as rcu_read_lock(), but according to Oleg, this is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) * correct to rely on this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) task_uid(tsk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) task_cputime(tsk, &utime, &stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) info.si_utime = nsec_to_clock_t(utime + tsk->signal->utime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) info.si_stime = nsec_to_clock_t(stime + tsk->signal->stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) info.si_status = tsk->exit_code & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (tsk->exit_code & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) info.si_code = CLD_DUMPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) else if (tsk->exit_code & 0x7f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) info.si_code = CLD_KILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) info.si_code = CLD_EXITED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) info.si_status = tsk->exit_code >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) psig = tsk->parent->sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) spin_lock_irqsave(&psig->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) if (!tsk->ptrace && sig == SIGCHLD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) * We are exiting and our parent doesn't care. POSIX.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) * defines special semantics for setting SIGCHLD to SIG_IGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) * or setting the SA_NOCLDWAIT flag: we should be reaped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) * automatically and not left for our parent's wait4 call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) * Rather than having the parent do it as a magic kind of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) * signal handler, we just set this to tell do_exit that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) * can be cleaned up without becoming a zombie. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) * we still call __wake_up_parent in this case, because a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) * blocked sys_wait4 might now return -ECHILD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) * Whether we send SIGCHLD or not for SA_NOCLDWAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) * is implementation-defined: we do (if you don't want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) * it, just use SIG_IGN instead).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) autoreap = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) sig = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) * Send with __send_signal as si_pid and si_uid are in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) * parent's namespaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) if (valid_signal(sig) && sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) __wake_up_parent(tsk, tsk->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) spin_unlock_irqrestore(&psig->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) return autoreap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) * do_notify_parent_cldstop - notify parent of stopped/continued state change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) * @tsk: task reporting the state change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) * @for_ptracer: the notification is for ptracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) * @why: CLD_{CONTINUED|STOPPED|TRAPPED} to report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) * Notify @tsk's parent that the stopped/continued state has changed. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) * @for_ptracer is %false, @tsk's group leader notifies to its real parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) * If %true, @tsk reports to @tsk->parent which should be the ptracer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) * Must be called with tasklist_lock at least read locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) static void do_notify_parent_cldstop(struct task_struct *tsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) bool for_ptracer, int why)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) struct task_struct *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) struct sighand_struct *sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) u64 utime, stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) if (for_ptracer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) parent = tsk->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) tsk = tsk->group_leader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) parent = tsk->real_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) info.si_signo = SIGCHLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) * see comment in do_notify_parent() about the following 4 lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) info.si_uid = from_kuid_munged(task_cred_xxx(parent, user_ns), task_uid(tsk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) task_cputime(tsk, &utime, &stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) info.si_utime = nsec_to_clock_t(utime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) info.si_stime = nsec_to_clock_t(stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) info.si_code = why;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) switch (why) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) case CLD_CONTINUED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) info.si_status = SIGCONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) case CLD_STOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) info.si_status = tsk->signal->group_exit_code & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) case CLD_TRAPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) info.si_status = tsk->exit_code & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) sighand = parent->sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) spin_lock_irqsave(&sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) if (sighand->action[SIGCHLD-1].sa.sa_handler != SIG_IGN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) !(sighand->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) __group_send_sig_info(SIGCHLD, &info, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) * Even if SIGCHLD is not generated, we must wake up wait4 calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) __wake_up_parent(tsk, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) spin_unlock_irqrestore(&sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) static inline bool may_ptrace_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (!likely(current->ptrace))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) * Are we in the middle of do_coredump?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) * If so and our tracer is also part of the coredump stopping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) * is a deadlock situation, and pointless because our tracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) * is dead so don't allow us to stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) * If SIGKILL was already sent before the caller unlocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) * ->siglock we must see ->core_state != NULL. Otherwise it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) * is safe to enter schedule().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) * This is almost outdated, a task with the pending SIGKILL can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) * block in TASK_TRACED. But PTRACE_EVENT_EXIT can be reported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) * after SIGKILL was already dequeued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) if (unlikely(current->mm->core_state) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) unlikely(current->mm == current->parent->mm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) * This must be called with current->sighand->siglock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) * This should be the path for all ptrace stops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) * We always set current->last_siginfo while stopped here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) * That makes it a way to test a stopped process for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) * being ptrace-stopped vs being job-control-stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) * If we actually decide not to stop at all because the tracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) * is gone, we keep current->exit_code unless clear_code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) static void ptrace_stop(int exit_code, int why, int clear_code, kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) __releases(¤t->sighand->siglock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) __acquires(¤t->sighand->siglock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) bool gstop_done = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) if (arch_ptrace_stop_needed(exit_code, info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) * The arch code has something special to do before a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) * ptrace stop. This is allowed to block, e.g. for faults
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) * on user stack pages. We can't keep the siglock while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) * calling arch_ptrace_stop, so we must release it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) * To preserve proper semantics, we must do this before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) * any signal bookkeeping like checking group_stop_count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) arch_ptrace_stop(exit_code, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) * schedule() will not sleep if there is a pending signal that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * can awaken the task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) set_special_state(TASK_TRACED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) * We're committing to trapping. TRACED should be visible before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) * TRAPPING is cleared; otherwise, the tracer might fail do_wait().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) * Also, transition to TRACED and updates to ->jobctl should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) * atomic with respect to siglock and should be done after the arch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) * hook as siglock is released and regrabbed across it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) * TRACER TRACEE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) * ptrace_attach()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) * [L] wait_on_bit(JOBCTL_TRAPPING) [S] set_special_state(TRACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) * do_wait()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) * set_current_state() smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) * ptrace_do_wait()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) * wait_task_stopped()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) * task_stopped_code()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) * [L] task_is_traced() [S] task_clear_jobctl_trapping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) current->last_siginfo = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) current->exit_code = exit_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) * If @why is CLD_STOPPED, we're trapping to participate in a group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) * stop. Do the bookkeeping. Note that if SIGCONT was delievered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) * across siglock relocks since INTERRUPT was scheduled, PENDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) * could be clear now. We act as if SIGCONT is received after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) * TASK_TRACED is entered - ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) gstop_done = task_participate_group_stop(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) /* any trap clears pending STOP trap, STOP trap clears NOTIFY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) task_clear_jobctl_pending(current, JOBCTL_TRAP_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) if (info && info->si_code >> 8 == PTRACE_EVENT_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) task_clear_jobctl_pending(current, JOBCTL_TRAP_NOTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) /* entering a trap, clear TRAPPING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) task_clear_jobctl_trapping(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) if (may_ptrace_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) * Notify parents of the stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) * While ptraced, there are two parents - the ptracer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) * the real_parent of the group_leader. The ptracer should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) * know about every stop while the real parent is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) * interested in the completion of group stop. The states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) * for the two don't interact with each other. Notify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) * separately unless they're gonna be duplicates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) do_notify_parent_cldstop(current, true, why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) if (gstop_done && ptrace_reparented(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) do_notify_parent_cldstop(current, false, why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) * Don't want to allow preemption here, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) * sys_ptrace() needs this task to be inactive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) * XXX: implement read_unlock_no_resched().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) cgroup_enter_frozen();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) preempt_enable_no_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) freezable_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) cgroup_leave_frozen(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) * By the time we got the lock, our tracer went away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) * Don't drop the lock yet, another tracer may come.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) * If @gstop_done, the ptracer went away between group stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) * completion and here. During detach, it would have set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) * JOBCTL_STOP_PENDING on us and we'll re-enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) * TASK_STOPPED in do_signal_stop() on return, so notifying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) * the real parent of the group stop completion is enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) if (gstop_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) do_notify_parent_cldstop(current, false, why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) /* tasklist protects us from ptrace_freeze_traced() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) __set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) if (clear_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) current->exit_code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) * We are back. Now reacquire the siglock before touching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) * last_siginfo, so that we are sure to have synchronized with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) * any signal-sending on another CPU that wants to examine it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) current->last_siginfo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) /* LISTENING can be set only during STOP traps, clear it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) current->jobctl &= ~JOBCTL_LISTENING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) * Queued signals ignored us while we were stopped for tracing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) * So check for any that we should take before resuming user mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) * This sets TIF_SIGPENDING, but never clears it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) recalc_sigpending_tsk(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) static void ptrace_do_notify(int signr, int exit_code, int why)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) info.si_signo = signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) info.si_code = exit_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) info.si_pid = task_pid_vnr(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) info.si_uid = from_kuid_munged(current_user_ns(), current_uid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) /* Let the debugger run. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) ptrace_stop(exit_code, why, 1, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) void ptrace_notify(int exit_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) if (unlikely(current->task_works))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) task_work_run();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) ptrace_do_notify(SIGTRAP, exit_code, CLD_TRAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) * do_signal_stop - handle group stop for SIGSTOP and other stop signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) * @signr: signr causing group stop if initiating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) * If %JOBCTL_STOP_PENDING is not set yet, initiate group stop with @signr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) * and participate in it. If already set, participate in the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) * group stop. If participated in a group stop (and thus slept), %true is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) * returned with siglock released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) * If ptraced, this function doesn't handle stop itself. Instead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) * %JOBCTL_TRAP_STOP is scheduled and %false is returned with siglock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) * untouched. The caller must ensure that INTERRUPT trap handling takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) * places afterwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) * Must be called with @current->sighand->siglock held, which is released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) * on %true return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) * %false if group stop is already cancelled or ptrace trap is scheduled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) * %true if participated in group stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) static bool do_signal_stop(int signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) __releases(¤t->sighand->siglock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) struct signal_struct *sig = current->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (!(current->jobctl & JOBCTL_STOP_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) unsigned long gstop = JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) struct task_struct *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) /* signr will be recorded in task->jobctl for retries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) WARN_ON_ONCE(signr & ~JOBCTL_STOP_SIGMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) if (!likely(current->jobctl & JOBCTL_STOP_DEQUEUED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) unlikely(signal_group_exit(sig)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) * There is no group stop already in progress. We must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) * initiate one now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) * While ptraced, a task may be resumed while group stop is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) * still in effect and then receive a stop signal and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) * initiate another group stop. This deviates from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) * usual behavior as two consecutive stop signals can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) * cause two group stops when !ptraced. That is why we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) * also check !task_is_stopped(t) below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) * The condition can be distinguished by testing whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) * SIGNAL_STOP_STOPPED is already set. Don't generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) * group_exit_code in such case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) * This is not necessary for SIGNAL_STOP_CONTINUED because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) * an intervening stop signal is required to cause two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) * continued events regardless of ptrace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) if (!(sig->flags & SIGNAL_STOP_STOPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) sig->group_exit_code = signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) sig->group_stop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) if (task_set_jobctl_pending(current, signr | gstop))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) sig->group_stop_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) t = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) while_each_thread(current, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) * Setting state to TASK_STOPPED for a group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) * stop is always done with the siglock held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) * so this check has no races.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) if (!task_is_stopped(t) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) task_set_jobctl_pending(t, signr | gstop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) sig->group_stop_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) if (likely(!(t->ptrace & PT_SEIZED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) signal_wake_up(t, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) ptrace_trap_notify(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) if (likely(!current->ptrace)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) int notify = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) * If there are no other threads in the group, or if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) * is a group stop in progress and we are the last to stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) * report to the parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) if (task_participate_group_stop(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) notify = CLD_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) set_special_state(TASK_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) * Notify the parent of the group stop completion. Because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) * we're not holding either the siglock or tasklist_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) * here, ptracer may attach inbetween; however, this is for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) * group stop and should always be delivered to the real
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) * parent of the group leader. The new ptracer will get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) * its notification when this task transitions into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) * TASK_TRACED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) if (notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) do_notify_parent_cldstop(current, false, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) /* Now we don't run again until woken by SIGCONT or SIGKILL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) cgroup_enter_frozen();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) freezable_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) * While ptraced, group stop is handled by STOP trap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) * Schedule it and let the caller deal with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) task_set_jobctl_pending(current, JOBCTL_TRAP_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) * do_jobctl_trap - take care of ptrace jobctl traps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) * When PT_SEIZED, it's used for both group stop and explicit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) * SEIZE/INTERRUPT traps. Both generate PTRACE_EVENT_STOP trap with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) * accompanying siginfo. If stopped, lower eight bits of exit_code contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) * the stop signal; otherwise, %SIGTRAP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) * When !PT_SEIZED, it's used only for group stop trap with stop signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) * number as exit_code and no siginfo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) * Must be called with @current->sighand->siglock held, which may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) * released and re-acquired before returning with intervening sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) static void do_jobctl_trap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) struct signal_struct *signal = current->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) int signr = current->jobctl & JOBCTL_STOP_SIGMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (current->ptrace & PT_SEIZED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) if (!signal->group_stop_count &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) !(signal->flags & SIGNAL_STOP_STOPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) signr = SIGTRAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) WARN_ON_ONCE(!signr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) ptrace_do_notify(signr, signr | (PTRACE_EVENT_STOP << 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) CLD_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) WARN_ON_ONCE(!signr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) ptrace_stop(signr, CLD_STOPPED, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) current->exit_code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * do_freezer_trap - handle the freezer jobctl trap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) * Puts the task into frozen state, if only the task is not about to quit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) * In this case it drops JOBCTL_TRAP_FREEZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) * CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) * Must be called with @current->sighand->siglock held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) * which is always released before returning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) static void do_freezer_trap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) __releases(¤t->sighand->siglock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) * If there are other trap bits pending except JOBCTL_TRAP_FREEZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) * let's make another loop to give it a chance to be handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) * In any case, we'll return back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) if ((current->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) JOBCTL_TRAP_FREEZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) * Now we're sure that there is no pending fatal signal and no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) * pending traps. Clear TIF_SIGPENDING to not get out of schedule()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) * immediately (if there is a non-fatal signal pending), and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) * put the task into sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) __set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) clear_thread_flag(TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) cgroup_enter_frozen();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) freezable_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) static int ptrace_signal(int signr, kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) * We do not check sig_kernel_stop(signr) but set this marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) * unconditionally because we do not know whether debugger will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) * change signr. This flag has no meaning unless we are going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) * to stop after return from ptrace_stop(). In this case it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) * be checked in do_signal_stop(), we should only stop if it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) * not cleared by SIGCONT while we were sleeping. See also the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) * comment in dequeue_signal().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) current->jobctl |= JOBCTL_STOP_DEQUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) ptrace_stop(signr, CLD_TRAPPED, 0, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) /* We're back. Did the debugger cancel the sig? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) signr = current->exit_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) if (signr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) return signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) current->exit_code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) * Update the siginfo structure if the signal has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) * changed. If the debugger wanted something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) * specific in the siginfo structure then it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) * have updated *info via PTRACE_SETSIGINFO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) if (signr != info->si_signo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) clear_siginfo(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) info->si_signo = signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) info->si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) info->si_code = SI_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) info->si_pid = task_pid_vnr(current->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) info->si_uid = from_kuid_munged(current_user_ns(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) task_uid(current->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) /* If the (new) signal is now blocked, requeue it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) if (sigismember(¤t->blocked, signr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) send_signal(signr, info, current, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) signr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) return signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) static void hide_si_addr_tag_bits(struct ksignal *ksig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) switch (siginfo_layout(ksig->sig, ksig->info.si_code)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) case SIL_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) case SIL_FAULT_MCEERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) case SIL_FAULT_BNDERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) case SIL_FAULT_PKUERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) ksig->info.si_addr = arch_untagged_si_addr(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) ksig->info.si_addr, ksig->sig, ksig->info.si_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) case SIL_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) case SIL_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) case SIL_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) case SIL_CHLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) case SIL_RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) case SIL_SYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) bool get_signal(struct ksignal *ksig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) struct sighand_struct *sighand = current->sighand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) struct signal_struct *signal = current->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) int signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) if (unlikely(uprobe_deny_signal()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) * Do this once, we can't return to user-mode if freezing() == T.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) * do_signal_stop() and ptrace_stop() do freezable_schedule() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) * thus do not need another check after return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) relock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) spin_lock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) * Make sure we can safely read ->jobctl() in task_work add. As Oleg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) * states:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) * It pairs with mb (implied by cmpxchg) before READ_ONCE. So we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) * roughly have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) * task_work_add: get_signal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) * STORE(task->task_works, new_work); STORE(task->jobctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) * mb(); mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) * LOAD(task->jobctl); LOAD(task->task_works);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) * and we can rely on STORE-MB-LOAD [ in task_work_add].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) smp_store_mb(current->jobctl, current->jobctl & ~JOBCTL_TASK_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (unlikely(current->task_works)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) task_work_run();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) * Every stopped thread goes here after wakeup. Check to see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) * we should notify the parent, prepare_signal(SIGCONT) encodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) * the CLD_ si_code into SIGNAL_CLD_MASK bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) if (unlikely(signal->flags & SIGNAL_CLD_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) int why;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) if (signal->flags & SIGNAL_CLD_CONTINUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) why = CLD_CONTINUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) why = CLD_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) signal->flags &= ~SIGNAL_CLD_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) * Notify the parent that we're continuing. This event is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) * always per-process and doesn't make whole lot of sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) * for ptracers, who shouldn't consume the state via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) * wait(2) either, but, for backward compatibility, notify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) * the ptracer of the group leader too unless it's gonna be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) * a duplicate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) do_notify_parent_cldstop(current, false, why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) if (ptrace_reparented(current->group_leader))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) do_notify_parent_cldstop(current->group_leader,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) true, why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) /* Has this task already been marked for death? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (signal_group_exit(signal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) ksig->info.si_signo = signr = SIGKILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) sigdelset(¤t->pending.signal, SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) &sighand->action[SIGKILL - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) goto fatal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) struct k_sigaction *ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) if (unlikely(current->jobctl & JOBCTL_STOP_PENDING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) do_signal_stop(0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) if (unlikely(current->jobctl &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) (JOBCTL_TRAP_MASK | JOBCTL_TRAP_FREEZE))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) if (current->jobctl & JOBCTL_TRAP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) do_jobctl_trap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) } else if (current->jobctl & JOBCTL_TRAP_FREEZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) do_freezer_trap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) * If the task is leaving the frozen state, let's update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) * cgroup counters and reset the frozen bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) if (unlikely(cgroup_task_frozen(current))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) cgroup_leave_frozen(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) * Signals generated by the execution of an instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) * need to be delivered before any other pending signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) * so that the instruction pointer in the signal stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) * frame points to the faulting instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) signr = dequeue_synchronous_signal(&ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) if (!signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) signr = dequeue_signal(current, ¤t->blocked, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) if (!signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) break; /* will return 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) if (unlikely(current->ptrace) && signr != SIGKILL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) signr = ptrace_signal(signr, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) if (!signr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) ka = &sighand->action[signr-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /* Trace actually delivered signals. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) trace_signal_deliver(signr, &ksig->info, ka);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) if (ka->sa.sa_handler != SIG_DFL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) /* Run the handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) ksig->ka = *ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) if (ka->sa.sa_flags & SA_ONESHOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) ka->sa.sa_handler = SIG_DFL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) break; /* will return non-zero "signr" value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) * Now we are doing the default action for this signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) if (sig_kernel_ignore(signr)) /* Default is nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) * Global init gets no signals it doesn't want.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) * Container-init gets no signals it doesn't want from same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) * container.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) * Note that if global/container-init sees a sig_kernel_only()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) * signal here, the signal must have been generated internally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) * or must have come from an ancestor namespace. In either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) * case, the signal cannot be dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) if (unlikely(signal->flags & SIGNAL_UNKILLABLE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) !sig_kernel_only(signr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) if (sig_kernel_stop(signr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) * The default action is to stop all threads in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) * the thread group. The job control signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) * do nothing in an orphaned pgrp, but SIGSTOP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) * always works. Note that siglock needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) * dropped during the call to is_orphaned_pgrp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) * because of lock ordering with tasklist_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) * This allows an intervening SIGCONT to be posted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) * We need to check for that and bail out if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) if (signr != SIGSTOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) /* signals can be posted during this window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) if (is_current_pgrp_orphaned())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) spin_lock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) if (likely(do_signal_stop(ksig->info.si_signo))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) /* It released the siglock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) goto relock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * We didn't actually stop, due to a race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * with SIGCONT or something like that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) fatal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) if (unlikely(cgroup_task_frozen(current)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) cgroup_leave_frozen(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) * Anything else is fatal, maybe with a core dump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) current->flags |= PF_SIGNALED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) if (sig_kernel_coredump(signr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) if (print_fatal_signals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) print_fatal_signal(ksig->info.si_signo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) proc_coredump_connector(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) * If it was able to dump core, this kills all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) * other threads in the group and synchronizes with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) * their demise. If we lost the race with another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) * thread getting here, it set group_exit_code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) * first and our do_group_exit call below will use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) * that value and ignore the one we pass it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) do_coredump(&ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) * Death signals, no core dump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) do_group_exit(ksig->info.si_signo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) /* NOTREACHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) spin_unlock_irq(&sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) ksig->sig = signr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) hide_si_addr_tag_bits(ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) return ksig->sig > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) * signal_delivered -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) * @ksig: kernel signal struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) * @stepping: nonzero if debugger single-step or block-step in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) * This function should be called when a signal has successfully been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) * delivered. It updates the blocked signals accordingly (@ksig->ka.sa.sa_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) * is always blocked, and the signal itself is blocked unless %SA_NODEFER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) * is set in @ksig->ka.sa.sa_flags. Tracing is notified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) static void signal_delivered(struct ksignal *ksig, int stepping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) sigset_t blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) /* A signal was successfully delivered, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) saved sigmask was stored on the signal frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) and will be restored by sigreturn. So we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) simply clear the restore sigmask flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) clear_restore_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) sigorsets(&blocked, ¤t->blocked, &ksig->ka.sa.sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) if (!(ksig->ka.sa.sa_flags & SA_NODEFER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) sigaddset(&blocked, ksig->sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) set_current_blocked(&blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) tracehook_signal_handler(stepping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) void signal_setup_done(int failed, struct ksignal *ksig, int stepping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) if (failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) force_sigsegv(ksig->sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) signal_delivered(ksig, stepping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) * It could be that complete_signal() picked us to notify about the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) * group-wide signal. Other threads should be notified now to take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) * the shared signals in @which since we will not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) sigset_t retarget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) struct task_struct *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) sigandsets(&retarget, &tsk->signal->shared_pending.signal, which);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) if (sigisemptyset(&retarget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) t = tsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) while_each_thread(tsk, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) if (t->flags & PF_EXITING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) if (!has_pending_signals(&retarget, &t->blocked))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) /* Remove the signals this thread can handle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) sigandsets(&retarget, &retarget, &t->blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) if (!signal_pending(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) signal_wake_up(t, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) if (sigisemptyset(&retarget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) void exit_signals(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) int group_stop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) sigset_t unblocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) * @tsk is about to have PF_EXITING set - lock out users which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) * expect stable threadgroup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) cgroup_threadgroup_change_begin(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) tsk->flags |= PF_EXITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) cgroup_threadgroup_change_end(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) spin_lock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) * From now this task is not visible for group-wide signals,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) * see wants_signal(), do_signal_stop().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) tsk->flags |= PF_EXITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) cgroup_threadgroup_change_end(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) if (!signal_pending(tsk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) unblocked = tsk->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) signotset(&unblocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) retarget_shared_pending(tsk, &unblocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) if (unlikely(tsk->jobctl & JOBCTL_STOP_PENDING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) task_participate_group_stop(tsk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) group_stop = CLD_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) spin_unlock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) * If group stop has completed, deliver the notification. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) * should always go to the real parent of the group leader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) if (unlikely(group_stop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) do_notify_parent_cldstop(tsk, false, group_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) * System call entry points.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) * sys_restart_syscall - restart a system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) SYSCALL_DEFINE0(restart_syscall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) struct restart_block *restart = ¤t->restart_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) return restart->fn(restart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) long do_no_restart_syscall(struct restart_block *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) if (signal_pending(tsk) && !thread_group_empty(tsk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) sigset_t newblocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) /* A set of now blocked but previously unblocked signals. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) sigandnsets(&newblocked, newset, ¤t->blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) retarget_shared_pending(tsk, &newblocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) tsk->blocked = *newset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) * set_current_blocked - change current->blocked mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) * @newset: new mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) * It is wrong to change ->blocked directly, this helper should be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) * to ensure the process can't miss a shared signal we are going to block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) void set_current_blocked(sigset_t *newset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) sigdelsetmask(newset, sigmask(SIGKILL) | sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) __set_current_blocked(newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) void __set_current_blocked(const sigset_t *newset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) * In case the signal mask hasn't changed, there is nothing we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) * to do. The current->blocked shouldn't be modified by other task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) if (sigequalsets(&tsk->blocked, newset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) spin_lock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) __set_task_blocked(tsk, newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) spin_unlock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) * This is also useful for kernel threads that want to temporarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) * (or permanently) block certain signals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) * interface happily blocks "unblockable" signals like SIGKILL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) * and friends.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) sigset_t newset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) /* Lockless, only current can change ->blocked, never from irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) if (oldset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) *oldset = tsk->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) switch (how) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) case SIG_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) sigorsets(&newset, &tsk->blocked, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) case SIG_UNBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) sigandnsets(&newset, &tsk->blocked, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) case SIG_SETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) newset = *set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) __set_current_blocked(&newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) EXPORT_SYMBOL(sigprocmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) * The api helps set app-provided sigmasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) * This is useful for syscalls such as ppoll, pselect, io_pgetevents and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) * epoll_pwait where a new sigmask is passed from userland for the syscalls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) * Note that it does set_restore_sigmask() in advance, so it must be always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) * paired with restore_saved_sigmask_unless() before return from syscall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) int set_user_sigmask(const sigset_t __user *umask, size_t sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) sigset_t kmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) if (!umask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) if (copy_from_user(&kmask, umask, sizeof(sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) set_restore_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) current->saved_sigmask = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) set_current_blocked(&kmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) int set_compat_user_sigmask(const compat_sigset_t __user *umask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) size_t sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) sigset_t kmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) if (!umask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) if (sigsetsize != sizeof(compat_sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) if (get_compat_sigset(&kmask, umask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) set_restore_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) current->saved_sigmask = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) set_current_blocked(&kmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) * sys_rt_sigprocmask - change the list of currently blocked signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) * @how: whether to add, remove, or set signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) * @nset: stores pending signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) * @oset: previous value of signal mask if non-null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) * @sigsetsize: size of sigset_t type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, nset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) sigset_t __user *, oset, size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) sigset_t old_set, new_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) old_set = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) if (nset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) if (copy_from_user(&new_set, nset, sizeof(sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) error = sigprocmask(how, &new_set, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) if (oset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) if (copy_to_user(oset, &old_set, sizeof(sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) COMPAT_SYSCALL_DEFINE4(rt_sigprocmask, int, how, compat_sigset_t __user *, nset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) compat_sigset_t __user *, oset, compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) sigset_t old_set = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) if (nset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) sigset_t new_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) if (get_compat_sigset(&new_set, nset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) error = sigprocmask(how, &new_set, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) static void do_sigpending(sigset_t *set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) sigorsets(set, ¤t->pending.signal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) ¤t->signal->shared_pending.signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) /* Outside the lock because only this thread touches it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) sigandsets(set, ¤t->blocked, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * sys_rt_sigpending - examine a pending signal that has been raised
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) * while blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) * @uset: stores pending signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) * @sigsetsize: size of sigset_t type or larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, uset, size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) if (sigsetsize > sizeof(*uset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) do_sigpending(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) if (copy_to_user(uset, &set, sigsetsize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) COMPAT_SYSCALL_DEFINE2(rt_sigpending, compat_sigset_t __user *, uset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) if (sigsetsize > sizeof(*uset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) do_sigpending(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) return put_compat_sigset(uset, &set, sigsetsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) unsigned char limit, layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) } sig_sicodes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) [SIGILL] = { NSIGILL, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) [SIGFPE] = { NSIGFPE, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) [SIGSEGV] = { NSIGSEGV, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) [SIGBUS] = { NSIGBUS, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) [SIGTRAP] = { NSIGTRAP, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) #if defined(SIGEMT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) [SIGEMT] = { NSIGEMT, SIL_FAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) [SIGCHLD] = { NSIGCHLD, SIL_CHLD },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) [SIGPOLL] = { NSIGPOLL, SIL_POLL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) [SIGSYS] = { NSIGSYS, SIL_SYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) static bool known_siginfo_layout(unsigned sig, int si_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) if (si_code == SI_KERNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) else if ((si_code > SI_USER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) if (sig_specific_sicodes(sig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) if (si_code <= sig_sicodes[sig].limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) else if (si_code <= NSIGPOLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) else if (si_code >= SI_DETHREAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) else if (si_code == SI_ASYNCNL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) enum siginfo_layout siginfo_layout(unsigned sig, int si_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) enum siginfo_layout layout = SIL_KILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) if ((si_code > SI_USER) && (si_code < SI_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) if ((sig < ARRAY_SIZE(sig_sicodes)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) (si_code <= sig_sicodes[sig].limit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) layout = sig_sicodes[sig].layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) /* Handle the exceptions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) if ((sig == SIGBUS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) (si_code >= BUS_MCEERR_AR) && (si_code <= BUS_MCEERR_AO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) layout = SIL_FAULT_MCEERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) else if ((sig == SIGSEGV) && (si_code == SEGV_BNDERR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) layout = SIL_FAULT_BNDERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) #ifdef SEGV_PKUERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) else if ((sig == SIGSEGV) && (si_code == SEGV_PKUERR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) layout = SIL_FAULT_PKUERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) else if (si_code <= NSIGPOLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) layout = SIL_POLL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) if (si_code == SI_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) layout = SIL_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) else if (si_code == SI_SIGIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) layout = SIL_POLL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) else if (si_code < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) layout = SIL_RT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) return layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) static inline char __user *si_expansion(const siginfo_t __user *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) return ((char __user *)info) + sizeof(struct kernel_siginfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) char __user *expansion = si_expansion(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) if (copy_to_user(to, from , sizeof(struct kernel_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) if (clear_user(expansion, SI_EXPANSION_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) static int post_copy_siginfo_from_user(kernel_siginfo_t *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) const siginfo_t __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) if (unlikely(!known_siginfo_layout(info->si_signo, info->si_code))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) char __user *expansion = si_expansion(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) char buf[SI_EXPANSION_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) * An unknown si_code might need more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) * sizeof(struct kernel_siginfo) bytes. Verify all of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) * extra bytes are 0. This guarantees copy_siginfo_to_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) * will return this data to userspace exactly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) if (copy_from_user(&buf, expansion, SI_EXPANSION_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) for (i = 0; i < SI_EXPANSION_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) if (buf[i] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) static int __copy_siginfo_from_user(int signo, kernel_siginfo_t *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) const siginfo_t __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (copy_from_user(to, from, sizeof(struct kernel_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) to->si_signo = signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) return post_copy_siginfo_from_user(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) if (copy_from_user(to, from, sizeof(struct kernel_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) return post_copy_siginfo_from_user(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) * copy_siginfo_to_external32 - copy a kernel siginfo into a compat user siginfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) * @to: compat siginfo destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) * @from: kernel siginfo source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) * Note: This function does not work properly for the SIGCHLD on x32, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) * fortunately it doesn't have to. The only valid callers for this function are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) * copy_siginfo_to_user32, which is overriden for x32 and the coredump code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) * The latter does not care because SIGCHLD will never cause a coredump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) void copy_siginfo_to_external32(struct compat_siginfo *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) const struct kernel_siginfo *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) memset(to, 0, sizeof(*to));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) to->si_signo = from->si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) to->si_errno = from->si_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) to->si_code = from->si_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) switch(siginfo_layout(from->si_signo, from->si_code)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) case SIL_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) case SIL_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) to->si_tid = from->si_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) to->si_overrun = from->si_overrun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) to->si_int = from->si_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) case SIL_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) to->si_band = from->si_band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) to->si_fd = from->si_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) case SIL_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) to->si_addr = ptr_to_compat(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) case SIL_FAULT_MCEERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) to->si_addr = ptr_to_compat(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) to->si_addr_lsb = from->si_addr_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) case SIL_FAULT_BNDERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) to->si_addr = ptr_to_compat(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) to->si_lower = ptr_to_compat(from->si_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) to->si_upper = ptr_to_compat(from->si_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) case SIL_FAULT_PKUERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) to->si_addr = ptr_to_compat(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) to->si_pkey = from->si_pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) case SIL_CHLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) to->si_status = from->si_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) to->si_utime = from->si_utime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) to->si_stime = from->si_stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) case SIL_RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) to->si_int = from->si_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) case SIL_SYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) to->si_call_addr = ptr_to_compat(from->si_call_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) to->si_syscall = from->si_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) to->si_arch = from->si_arch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) const struct kernel_siginfo *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) struct compat_siginfo new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) copy_siginfo_to_external32(&new, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) if (copy_to_user(to, &new, sizeof(struct compat_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) const struct compat_siginfo *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) clear_siginfo(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) to->si_signo = from->si_signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) to->si_errno = from->si_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) to->si_code = from->si_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) switch(siginfo_layout(from->si_signo, from->si_code)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) case SIL_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) case SIL_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) to->si_tid = from->si_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) to->si_overrun = from->si_overrun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) to->si_int = from->si_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) case SIL_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) to->si_band = from->si_band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) to->si_fd = from->si_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) case SIL_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) to->si_addr = compat_ptr(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) case SIL_FAULT_MCEERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) to->si_addr = compat_ptr(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) to->si_addr_lsb = from->si_addr_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) case SIL_FAULT_BNDERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) to->si_addr = compat_ptr(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) to->si_lower = compat_ptr(from->si_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) to->si_upper = compat_ptr(from->si_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) case SIL_FAULT_PKUERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) to->si_addr = compat_ptr(from->si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) #ifdef __ARCH_SI_TRAPNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) to->si_trapno = from->si_trapno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) to->si_pkey = from->si_pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) case SIL_CHLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) to->si_status = from->si_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) if (in_x32_syscall()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) to->si_utime = from->_sifields._sigchld_x32._utime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) to->si_stime = from->_sifields._sigchld_x32._stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) to->si_utime = from->si_utime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) to->si_stime = from->si_stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) case SIL_RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) to->si_pid = from->si_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) to->si_uid = from->si_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) to->si_int = from->si_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) case SIL_SYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) to->si_call_addr = compat_ptr(from->si_call_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) to->si_syscall = from->si_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) to->si_arch = from->si_arch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) static int __copy_siginfo_from_user32(int signo, struct kernel_siginfo *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) const struct compat_siginfo __user *ufrom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) struct compat_siginfo from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) from.si_signo = signo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) return post_copy_siginfo_from_user32(to, &from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) int copy_siginfo_from_user32(struct kernel_siginfo *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) const struct compat_siginfo __user *ufrom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) struct compat_siginfo from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) return post_copy_siginfo_from_user32(to, &from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) #endif /* CONFIG_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) * do_sigtimedwait - wait for queued signals specified in @which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) * @which: queued signals to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) * @info: if non-null, the signal's siginfo is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) * @ts: upper bound on process time suspension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) const struct timespec64 *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) ktime_t *to = NULL, timeout = KTIME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) sigset_t mask = *which;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) int sig, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) if (ts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) if (!timespec64_valid(ts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) timeout = timespec64_to_ktime(*ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) to = &timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) * Invert the set of allowed signals to get those we want to block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) sigdelsetmask(&mask, sigmask(SIGKILL) | sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) signotset(&mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) spin_lock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) sig = dequeue_signal(tsk, &mask, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) if (!sig && timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) * None ready, temporarily unblock those we're interested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) * while we are sleeping in so that we'll be awakened when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) * they arrive. Unblocking is always fine, we can avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) * set_current_blocked().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) tsk->real_blocked = tsk->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) sigandsets(&tsk->blocked, &tsk->blocked, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) spin_unlock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) __set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) ret = freezable_schedule_hrtimeout_range(to, tsk->timer_slack_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) spin_lock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) __set_task_blocked(tsk, &tsk->real_blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) sigemptyset(&tsk->real_blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) sig = dequeue_signal(tsk, &mask, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) spin_unlock_irq(&tsk->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) if (sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) return sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) return ret ? -EINTR : -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) * sys_rt_sigtimedwait - synchronously wait for queued signals specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) * in @uthese
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) * @uthese: queued signals to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) * @uinfo: if non-null, the signal's siginfo is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) * @uts: upper bound on process time suspension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) * @sigsetsize: size of sigset_t type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) siginfo_t __user *, uinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) const struct __kernel_timespec __user *, uts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) sigset_t these;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) if (copy_from_user(&these, uthese, sizeof(these)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) if (uts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) if (get_timespec64(&ts, uts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) if (ret > 0 && uinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) if (copy_siginfo_to_user(uinfo, &info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) #ifdef CONFIG_COMPAT_32BIT_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) siginfo_t __user *, uinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) const struct old_timespec32 __user *, uts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) sigset_t these;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) if (copy_from_user(&these, uthese, sizeof(these)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) if (uts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) if (get_old_timespec32(&ts, uts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) if (ret > 0 && uinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) if (copy_siginfo_to_user(uinfo, &info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) struct compat_siginfo __user *, uinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) sigset_t s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) struct timespec64 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) if (get_compat_sigset(&s, uthese))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) if (uts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) if (get_timespec64(&t, uts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) ret = do_sigtimedwait(&s, &info, uts ? &t : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) if (ret > 0 && uinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) if (copy_siginfo_to_user32(uinfo, &info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) #ifdef CONFIG_COMPAT_32BIT_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time32, compat_sigset_t __user *, uthese,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) struct compat_siginfo __user *, uinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) struct old_timespec32 __user *, uts, compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) sigset_t s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) struct timespec64 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) if (get_compat_sigset(&s, uthese))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) if (uts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) if (get_old_timespec32(&t, uts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) ret = do_sigtimedwait(&s, &info, uts ? &t : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) if (ret > 0 && uinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) if (copy_siginfo_to_user32(uinfo, &info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) clear_siginfo(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) info->si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) info->si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) info->si_code = SI_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) info->si_pid = task_tgid_vnr(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) info->si_uid = from_kuid_munged(current_user_ns(), current_uid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) * sys_kill - send a signal to a process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) * @pid: the PID of the process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) * @sig: signal to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) prepare_kill_siginfo(sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) return kill_something_info(sig, &info, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) * Verify that the signaler and signalee either are in the same pid namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) * or that the signaler's pid namespace is an ancestor of the signalee's pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) * namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) static bool access_pidfd_pidns(struct pid *pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) struct pid_namespace *active = task_active_pid_ns(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) struct pid_namespace *p = ns_of_pid(pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) if (p == active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) p = p->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) * Avoid hooking up compat syscalls and instead handle necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) * conversions here. Note, this is a stop-gap measure and should not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) * considered a generic solution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) if (in_compat_syscall())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) return copy_siginfo_from_user32(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) kinfo, (struct compat_siginfo __user *)info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) return copy_siginfo_from_user(kinfo, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) static struct pid *pidfd_to_pid(const struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) struct pid *pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) pid = pidfd_pid(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) if (!IS_ERR(pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) return pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) return tgid_pidfd_to_pid(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) * sys_pidfd_send_signal - Signal a process through a pidfd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) * @pidfd: file descriptor of the process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) * @sig: signal to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) * @info: signal info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) * @flags: future flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) * The syscall currently only signals via PIDTYPE_PID which covers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) * kill(<positive-pid>, <signal>. It does not signal threads or process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) * groups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) * In order to extend the syscall to threads and process groups the @flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) * argument should be used. In essence, the @flags argument will determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) * what is signaled and not the file descriptor itself. Put in other words,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) * grouping is a property of the flags argument not a property of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) * descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) * Return: 0 on success, negative errno on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) siginfo_t __user *, info, unsigned int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) struct fd f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) struct pid *pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) kernel_siginfo_t kinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) /* Enforce flags be set to 0 until we add an extension. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) if (flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) f = fdget(pidfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) if (!f.file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) /* Is this a pidfd? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) pid = pidfd_to_pid(f.file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) if (IS_ERR(pid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) ret = PTR_ERR(pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) if (!access_pidfd_pidns(pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) ret = copy_siginfo_from_user_any(&kinfo, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) if (unlikely(sig != kinfo.si_signo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) /* Only allow sending arbitrary signals to yourself. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) if ((task_pid(current) != pid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) prepare_kill_siginfo(sig, &kinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) ret = kill_pid_info(sig, &kinfo, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) fdput(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) struct task_struct *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) int error = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) p = find_task_by_vpid(pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) error = check_kill_permission(sig, info, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) * The null signal is a permissions and process existence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) * probe. No signal is actually delivered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) if (!error && sig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) error = do_send_sig_info(sig, info, p, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) * If lock_task_sighand() failed we pretend the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) * dies after receiving the signal. The window is tiny,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) * and the signal is private anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) if (unlikely(error == -ESRCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) static int do_tkill(pid_t tgid, pid_t pid, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) struct kernel_siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) clear_siginfo(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) info.si_signo = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) info.si_errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) info.si_code = SI_TKILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) info.si_pid = task_tgid_vnr(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) info.si_uid = from_kuid_munged(current_user_ns(), current_uid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) return do_send_specific(tgid, pid, sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) * sys_tgkill - send signal to one specific thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) * @tgid: the thread group ID of the thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) * @pid: the PID of the thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) * @sig: signal to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) * This syscall also checks the @tgid and returns -ESRCH even if the PID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) * exists but it's not belonging to the target process anymore. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) * method solves the problem of threads exiting and PIDs getting reused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) /* This is only valid for single tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) if (pid <= 0 || tgid <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) return do_tkill(tgid, pid, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) * sys_tkill - send signal to one specific task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) * @pid: the PID of the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) * @sig: signal to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) * Send a signal to only one task, even if it's a CLONE_THREAD task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) /* This is only valid for single tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) if (pid <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) return do_tkill(0, pid, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) static int do_rt_sigqueueinfo(pid_t pid, int sig, kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) /* Not even root can pretend to send signals from the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) * Nor can they impersonate a kill()/tgkill(), which adds source info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) (task_pid_vnr(current) != pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) /* POSIX.1b doesn't mention process groups. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) return kill_proc_info(sig, info, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) * sys_rt_sigqueueinfo - send signal information to a signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) * @pid: the PID of the thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) * @sig: signal to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) * @uinfo: signal info to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) siginfo_t __user *, uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) int ret = __copy_siginfo_from_user(sig, &info, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) return do_rt_sigqueueinfo(pid, sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) COMPAT_SYSCALL_DEFINE3(rt_sigqueueinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) compat_pid_t, pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) struct compat_siginfo __user *, uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) int ret = __copy_siginfo_from_user32(sig, &info, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) return do_rt_sigqueueinfo(pid, sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) /* This is only valid for single tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) if (pid <= 0 || tgid <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) /* Not even root can pretend to send signals from the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) * Nor can they impersonate a kill()/tgkill(), which adds source info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) (task_pid_vnr(current) != pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) return do_send_specific(tgid, pid, sig, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) siginfo_t __user *, uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) int ret = __copy_siginfo_from_user(sig, &info, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) compat_pid_t, tgid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) compat_pid_t, pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) struct compat_siginfo __user *, uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) kernel_siginfo_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) int ret = __copy_siginfo_from_user32(sig, &info, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) * For kthreads only, must not be used if cloned with CLONE_SIGHAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) void kernel_sigaction(int sig, __sighandler_t action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) spin_lock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) current->sighand->action[sig - 1].sa.sa_handler = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) if (action == SIG_IGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) sigset_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) sigemptyset(&mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) sigaddset(&mask, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) flush_sigqueue_mask(&mask, ¤t->signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) flush_sigqueue_mask(&mask, ¤t->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) spin_unlock_irq(¤t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) EXPORT_SYMBOL(kernel_sigaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) void __weak sigaction_compat_abi(struct k_sigaction *act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) struct k_sigaction *oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) struct task_struct *p = current, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) struct k_sigaction *k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) sigset_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) k = &p->sighand->action[sig-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) spin_lock_irq(&p->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) if (oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) *oact = *k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) * Make sure that we never accidentally claim to support SA_UNSUPPORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) * e.g. by having an architecture use the bit in their uapi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) BUILD_BUG_ON(UAPI_SA_FLAGS & SA_UNSUPPORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) * Clear unknown flag bits in order to allow userspace to detect missing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) * support for flag bits and to allow the kernel to use non-uapi bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) * internally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) if (act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) act->sa.sa_flags &= UAPI_SA_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) if (oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) oact->sa.sa_flags &= UAPI_SA_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) sigaction_compat_abi(act, oact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) sigdelsetmask(&act->sa.sa_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) sigmask(SIGKILL) | sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) *k = *act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) * POSIX 3.3.1.3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) * "Setting a signal action to SIG_IGN for a signal that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) * pending shall cause the pending signal to be discarded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) * whether or not it is blocked."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) * "Setting a signal action to SIG_DFL for a signal that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) * pending and whose default action is to ignore the signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) * (for example, SIGCHLD), shall cause the pending signal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) * be discarded, whether or not it is blocked"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) if (sig_handler_ignored(sig_handler(p, sig), sig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) sigemptyset(&mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) sigaddset(&mask, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) flush_sigqueue_mask(&mask, &p->signal->shared_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) for_each_thread(p, t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) flush_sigqueue_mask(&mask, &t->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) spin_unlock_irq(&p->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) size_t min_ss_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) struct task_struct *t = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) if (oss) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) memset(oss, 0, sizeof(stack_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) oss->ss_sp = (void __user *) t->sas_ss_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) oss->ss_size = t->sas_ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) oss->ss_flags = sas_ss_flags(sp) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) (current->sas_ss_flags & SS_FLAG_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) if (ss) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) void __user *ss_sp = ss->ss_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) size_t ss_size = ss->ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) unsigned ss_flags = ss->ss_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) int ss_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) if (unlikely(on_sig_stack(sp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) ss_mode = ss_flags & ~SS_FLAG_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) if (unlikely(ss_mode != SS_DISABLE && ss_mode != SS_ONSTACK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) ss_mode != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) if (ss_mode == SS_DISABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) ss_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) ss_sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) if (unlikely(ss_size < min_ss_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) t->sas_ss_sp = (unsigned long) ss_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) t->sas_ss_size = ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) t->sas_ss_flags = ss_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) stack_t new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) if (uss && copy_from_user(&new, uss, sizeof(stack_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) err = do_sigaltstack(uss ? &new : NULL, uoss ? &old : NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) current_user_stack_pointer(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) MINSIGSTKSZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) if (!err && uoss && copy_to_user(uoss, &old, sizeof(stack_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) int restore_altstack(const stack_t __user *uss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) stack_t new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) if (copy_from_user(&new, uss, sizeof(stack_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) (void)do_sigaltstack(&new, NULL, current_user_stack_pointer(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) MINSIGSTKSZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) /* squash all but EFAULT for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) int __save_altstack(stack_t __user *uss, unsigned long sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) struct task_struct *t = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) int err = __put_user((void __user *)t->sas_ss_sp, &uss->ss_sp) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) __put_user(t->sas_ss_flags, &uss->ss_flags) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) __put_user(t->sas_ss_size, &uss->ss_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) if (t->sas_ss_flags & SS_AUTODISARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) sas_ss_reset(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) static int do_compat_sigaltstack(const compat_stack_t __user *uss_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) compat_stack_t __user *uoss_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) stack_t uss, uoss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) if (uss_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) compat_stack_t uss32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) if (copy_from_user(&uss32, uss_ptr, sizeof(compat_stack_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) uss.ss_sp = compat_ptr(uss32.ss_sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) uss.ss_flags = uss32.ss_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) uss.ss_size = uss32.ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) compat_user_stack_pointer(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) COMPAT_MINSIGSTKSZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) if (ret >= 0 && uoss_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) compat_stack_t old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) memset(&old, 0, sizeof(old));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) old.ss_sp = ptr_to_compat(uoss.ss_sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) old.ss_flags = uoss.ss_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) old.ss_size = uoss.ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) if (copy_to_user(uoss_ptr, &old, sizeof(compat_stack_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) COMPAT_SYSCALL_DEFINE2(sigaltstack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) const compat_stack_t __user *, uss_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) compat_stack_t __user *, uoss_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) return do_compat_sigaltstack(uss_ptr, uoss_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) int compat_restore_altstack(const compat_stack_t __user *uss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) int err = do_compat_sigaltstack(uss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) /* squash all but -EFAULT for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) return err == -EFAULT ? err : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) struct task_struct *t = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) err = __put_user(ptr_to_compat((void __user *)t->sas_ss_sp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) &uss->ss_sp) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) __put_user(t->sas_ss_flags, &uss->ss_flags) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) __put_user(t->sas_ss_size, &uss->ss_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) if (t->sas_ss_flags & SS_AUTODISARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) sas_ss_reset(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) #ifdef __ARCH_WANT_SYS_SIGPENDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) * sys_sigpending - examine pending signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) * @uset: where mask of pending signal is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, uset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) if (sizeof(old_sigset_t) > sizeof(*uset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) do_sigpending(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) if (copy_to_user(uset, &set, sizeof(old_sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) do_sigpending(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) return put_user(set.sig[0], set32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) #ifdef __ARCH_WANT_SYS_SIGPROCMASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) * sys_sigprocmask - examine and change blocked signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) * @how: whether to add, remove, or set signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) * @nset: signals to add or remove (if non-null)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) * @oset: previous value of signal mask if non-null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) * Some platforms have their own version with special arguments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) * others support only sys_rt_sigprocmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, nset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) old_sigset_t __user *, oset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) old_sigset_t old_set, new_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) sigset_t new_blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) old_set = current->blocked.sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) if (nset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) if (copy_from_user(&new_set, nset, sizeof(*nset)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) new_blocked = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) switch (how) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) case SIG_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) sigaddsetmask(&new_blocked, new_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) case SIG_UNBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) sigdelsetmask(&new_blocked, new_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) case SIG_SETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) new_blocked.sig[0] = new_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) set_current_blocked(&new_blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) if (oset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) if (copy_to_user(oset, &old_set, sizeof(*oset)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) #endif /* __ARCH_WANT_SYS_SIGPROCMASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) #ifndef CONFIG_ODD_RT_SIGACTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) * sys_rt_sigaction - alter an action taken by a process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) * @sig: signal to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) * @act: new sigaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) * @oact: used to save the previous sigaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) * @sigsetsize: size of sigset_t type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) SYSCALL_DEFINE4(rt_sigaction, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) const struct sigaction __user *, act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) struct sigaction __user *, oact,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) struct k_sigaction new_sa, old_sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) if (act && copy_from_user(&new_sa.sa, act, sizeof(new_sa.sa)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) if (oact && copy_to_user(oact, &old_sa.sa, sizeof(old_sa.sa)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) COMPAT_SYSCALL_DEFINE4(rt_sigaction, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) const struct compat_sigaction __user *, act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) struct compat_sigaction __user *, oact,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) struct k_sigaction new_ka, old_ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) #ifdef __ARCH_HAS_SA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) compat_uptr_t restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) if (sigsetsize != sizeof(compat_sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) compat_uptr_t handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) ret = get_user(handler, &act->sa_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) new_ka.sa.sa_handler = compat_ptr(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) #ifdef __ARCH_HAS_SA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) ret |= get_user(restorer, &act->sa_restorer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) new_ka.sa.sa_restorer = compat_ptr(restorer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) if (!ret && oact) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) ret = put_user(ptr_to_compat(old_ka.sa.sa_handler),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) &oact->sa_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) sizeof(oact->sa_mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) #ifdef __ARCH_HAS_SA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) &oact->sa_restorer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) #endif /* !CONFIG_ODD_RT_SIGACTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) #ifdef CONFIG_OLD_SIGACTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) SYSCALL_DEFINE3(sigaction, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) const struct old_sigaction __user *, act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) struct old_sigaction __user *, oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) struct k_sigaction new_ka, old_ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) old_sigset_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) if (!access_ok(act, sizeof(*act)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) __get_user(mask, &act->sa_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) #ifdef __ARCH_HAS_KA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) new_ka.ka_restorer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) siginitset(&new_ka.sa.sa_mask, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) if (!ret && oact) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) if (!access_ok(oact, sizeof(*oact)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) #ifdef CONFIG_COMPAT_OLD_SIGACTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) COMPAT_SYSCALL_DEFINE3(sigaction, int, sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) const struct compat_old_sigaction __user *, act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) struct compat_old_sigaction __user *, oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) struct k_sigaction new_ka, old_ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) compat_old_sigset_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) compat_uptr_t handler, restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) if (!access_ok(act, sizeof(*act)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) __get_user(handler, &act->sa_handler) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) __get_user(restorer, &act->sa_restorer) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) __get_user(mask, &act->sa_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) #ifdef __ARCH_HAS_KA_RESTORER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) new_ka.ka_restorer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) new_ka.sa.sa_handler = compat_ptr(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) new_ka.sa.sa_restorer = compat_ptr(restorer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) siginitset(&new_ka.sa.sa_mask, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) if (!ret && oact) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) if (!access_ok(oact, sizeof(*oact)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) __put_user(ptr_to_compat(old_ka.sa.sa_handler),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) &oact->sa_handler) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) &oact->sa_restorer) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) #ifdef CONFIG_SGETMASK_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) * For backwards compatibility. Functionality superseded by sigprocmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) SYSCALL_DEFINE0(sgetmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) /* SMP safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) return current->blocked.sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) SYSCALL_DEFINE1(ssetmask, int, newmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) int old = current->blocked.sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) sigset_t newset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) siginitset(&newset, newmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) set_current_blocked(&newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) return old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) #endif /* CONFIG_SGETMASK_SYSCALL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) #ifdef __ARCH_WANT_SYS_SIGNAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) * For backwards compatibility. Functionality superseded by sigaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) struct k_sigaction new_sa, old_sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) new_sa.sa.sa_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) sigemptyset(&new_sa.sa.sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) ret = do_sigaction(sig, &new_sa, &old_sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) return ret ? ret : (unsigned long)old_sa.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) #endif /* __ARCH_WANT_SYS_SIGNAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) #ifdef __ARCH_WANT_SYS_PAUSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) SYSCALL_DEFINE0(pause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) while (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) __set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) return -ERESTARTNOHAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) static int sigsuspend(sigset_t *set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) current->saved_sigmask = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) set_current_blocked(set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) while (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) __set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) set_restore_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) return -ERESTARTNOHAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) * sys_rt_sigsuspend - replace the signal mask for a value with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) * @unewset value until a signal is received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) * @unewset: new signal mask value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) * @sigsetsize: size of sigset_t type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) sigset_t newset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) if (copy_from_user(&newset, unewset, sizeof(newset)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) return sigsuspend(&newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) COMPAT_SYSCALL_DEFINE2(rt_sigsuspend, compat_sigset_t __user *, unewset, compat_size_t, sigsetsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) sigset_t newset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) /* XXX: Don't preclude handling different sized sigset_t's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) if (sigsetsize != sizeof(sigset_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) if (get_compat_sigset(&newset, unewset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) return sigsuspend(&newset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) #ifdef CONFIG_OLD_SIGSUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) SYSCALL_DEFINE1(sigsuspend, old_sigset_t, mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) sigset_t blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) siginitset(&blocked, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) return sigsuspend(&blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) #ifdef CONFIG_OLD_SIGSUSPEND3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) SYSCALL_DEFINE3(sigsuspend, int, unused1, int, unused2, old_sigset_t, mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) sigset_t blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) siginitset(&blocked, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) return sigsuspend(&blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) __weak const char *arch_vma_name(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) static inline void siginfo_buildtime_checks(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) BUILD_BUG_ON(sizeof(struct siginfo) != SI_MAX_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) /* Verify the offsets in the two siginfos match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) #define CHECK_OFFSET(field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) BUILD_BUG_ON(offsetof(siginfo_t, field) != offsetof(kernel_siginfo_t, field))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) /* kill */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) CHECK_OFFSET(si_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) CHECK_OFFSET(si_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) /* timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) CHECK_OFFSET(si_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) CHECK_OFFSET(si_overrun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) CHECK_OFFSET(si_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) /* rt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) CHECK_OFFSET(si_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) CHECK_OFFSET(si_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) CHECK_OFFSET(si_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) /* sigchld */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) CHECK_OFFSET(si_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) CHECK_OFFSET(si_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) CHECK_OFFSET(si_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) CHECK_OFFSET(si_utime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) CHECK_OFFSET(si_stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) /* sigfault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) CHECK_OFFSET(si_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) CHECK_OFFSET(si_addr_lsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) CHECK_OFFSET(si_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) CHECK_OFFSET(si_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) CHECK_OFFSET(si_pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) /* sigpoll */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) CHECK_OFFSET(si_band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) CHECK_OFFSET(si_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) /* sigsys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) CHECK_OFFSET(si_call_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) CHECK_OFFSET(si_syscall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) CHECK_OFFSET(si_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) #undef CHECK_OFFSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) /* usb asyncio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) BUILD_BUG_ON(offsetof(struct siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) offsetof(struct siginfo, si_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) if (sizeof(int) == sizeof(void __user *)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) BUILD_BUG_ON(sizeof_field(struct siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) sizeof(void __user *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) BUILD_BUG_ON((sizeof_field(struct siginfo, si_pid) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) sizeof_field(struct siginfo, si_uid)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) sizeof(void __user *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) BUILD_BUG_ON(offsetofend(struct siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) offsetof(struct siginfo, si_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) BUILD_BUG_ON(offsetof(struct compat_siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) offsetof(struct compat_siginfo, si_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) sizeof(compat_uptr_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) sizeof_field(struct siginfo, si_pid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) void __init signals_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) siginfo_buildtime_checks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) #ifdef CONFIG_KGDB_KDB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) #include <linux/kdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) * kdb_send_sig - Allows kdb to send signals without exposing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) * signal internals. This function checks if the required locks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) * available before calling the main signal code, to avoid kdb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) * deadlocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) void kdb_send_sig(struct task_struct *t, int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) static struct task_struct *kdb_prev_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) int new_t, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) if (!spin_trylock(&t->sighand->siglock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) kdb_printf("Can't do kill command now.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) "The sigmask lock is held somewhere else in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) "kernel, try again later\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) new_t = kdb_prev_t != t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) kdb_prev_t = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) if (t->state != TASK_RUNNING && new_t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) spin_unlock(&t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) kdb_printf("Process is not RUNNING, sending a signal from "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) "kdb risks deadlock\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) "on the run queue locks. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) "The signal has _not_ been sent.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) "Reissue the kill command if you want to risk "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) "the deadlock.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) ret = send_signal(sig, SEND_SIG_PRIV, t, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) spin_unlock(&t->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) kdb_printf("Fail to deliver Signal %d to process %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) sig, t->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) kdb_printf("Signal %d is sent to process %d.\n", sig, t->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) #endif /* CONFIG_KGDB_KDB */