aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/signal.c')
-rw-r--r--kernel/signal.c153
1 files changed, 110 insertions, 43 deletions
diff --git a/kernel/signal.c b/kernel/signal.c
index f486d10f3b8e..29e233fd7a0f 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -226,7 +226,7 @@ static inline void print_dropped_signal(int sig)
226/* 226/*
227 * allocate a new signal queue record 227 * allocate a new signal queue record
228 * - this may be called without locks if and only if t == current, otherwise an 228 * - this may be called without locks if and only if t == current, otherwise an
229 * appopriate lock must be held to stop the target task from exiting 229 * appropriate lock must be held to stop the target task from exiting
230 */ 230 */
231static struct sigqueue * 231static struct sigqueue *
232__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) 232__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
@@ -375,15 +375,15 @@ int unhandled_signal(struct task_struct *tsk, int sig)
375 return !tracehook_consider_fatal_signal(tsk, sig); 375 return !tracehook_consider_fatal_signal(tsk, sig);
376} 376}
377 377
378 378/*
379/* Notify the system that a driver wants to block all signals for this 379 * Notify the system that a driver wants to block all signals for this
380 * process, and wants to be notified if any signals at all were to be 380 * process, and wants to be notified if any signals at all were to be
381 * sent/acted upon. If the notifier routine returns non-zero, then the 381 * sent/acted upon. If the notifier routine returns non-zero, then the
382 * signal will be acted upon after all. If the notifier routine returns 0, 382 * signal will be acted upon after all. If the notifier routine returns 0,
383 * then then signal will be blocked. Only one block per process is 383 * then then signal will be blocked. Only one block per process is
384 * allowed. priv is a pointer to private data that the notifier routine 384 * allowed. priv is a pointer to private data that the notifier routine
385 * can use to determine if the signal should be blocked or not. */ 385 * can use to determine if the signal should be blocked or not.
386 386 */
387void 387void
388block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask) 388block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask)
389{ 389{
@@ -434,9 +434,10 @@ still_pending:
434 copy_siginfo(info, &first->info); 434 copy_siginfo(info, &first->info);
435 __sigqueue_free(first); 435 __sigqueue_free(first);
436 } else { 436 } else {
437 /* Ok, it wasn't in the queue. This must be 437 /*
438 a fast-pathed signal or we must have been 438 * Ok, it wasn't in the queue. This must be
439 out of queue space. So zero out the info. 439 * a fast-pathed signal or we must have been
440 * out of queue space. So zero out the info.
440 */ 441 */
441 info->si_signo = sig; 442 info->si_signo = sig;
442 info->si_errno = 0; 443 info->si_errno = 0;
@@ -468,7 +469,7 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
468} 469}
469 470
470/* 471/*
471 * Dequeue a signal and return the element to the caller, which is 472 * Dequeue a signal and return the element to the caller, which is
472 * expected to free it. 473 * expected to free it.
473 * 474 *
474 * All callers have to hold the siglock. 475 * All callers have to hold the siglock.
@@ -490,7 +491,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
490 * itimers are process shared and we restart periodic 491 * itimers are process shared and we restart periodic
491 * itimers in the signal delivery path to prevent DoS 492 * itimers in the signal delivery path to prevent DoS
492 * attacks in the high resolution timer case. This is 493 * attacks in the high resolution timer case. This is
493 * compliant with the old way of self restarting 494 * compliant with the old way of self-restarting
494 * itimers, as the SIGALRM is a legacy signal and only 495 * itimers, as the SIGALRM is a legacy signal and only
495 * queued once. Changing the restart behaviour to 496 * queued once. Changing the restart behaviour to
496 * restart the timer in the signal dequeue path is 497 * restart the timer in the signal dequeue path is
@@ -923,14 +924,15 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t,
923 if (info == SEND_SIG_FORCED) 924 if (info == SEND_SIG_FORCED)
924 goto out_set; 925 goto out_set;
925 926
926 /* Real-time signals must be queued if sent by sigqueue, or 927 /*
927 some other real-time mechanism. It is implementation 928 * Real-time signals must be queued if sent by sigqueue, or
928 defined whether kill() does so. We attempt to do so, on 929 * some other real-time mechanism. It is implementation
929 the principle of least surprise, but since kill is not 930 * defined whether kill() does so. We attempt to do so, on
930 allowed to fail with EAGAIN when low on memory we just 931 * the principle of least surprise, but since kill is not
931 make sure at least one signal gets delivered and don't 932 * allowed to fail with EAGAIN when low on memory we just
932 pass on the info struct. */ 933 * make sure at least one signal gets delivered and don't
933 934 * pass on the info struct.
935 */
934 if (sig < SIGRTMIN) 936 if (sig < SIGRTMIN)
935 override_rlimit = (is_si_special(info) || info->si_code >= 0); 937 override_rlimit = (is_si_special(info) || info->si_code >= 0);
936 else 938 else
@@ -1201,8 +1203,7 @@ retry:
1201 return error; 1203 return error;
1202} 1204}
1203 1205
1204int 1206int kill_proc_info(int sig, struct siginfo *info, pid_t pid)
1205kill_proc_info(int sig, struct siginfo *info, pid_t pid)
1206{ 1207{
1207 int error; 1208 int error;
1208 rcu_read_lock(); 1209 rcu_read_lock();
@@ -1299,8 +1300,7 @@ static int kill_something_info(int sig, struct siginfo *info, pid_t pid)
1299 * These are for backward compatibility with the rest of the kernel source. 1300 * These are for backward compatibility with the rest of the kernel source.
1300 */ 1301 */
1301 1302
1302int 1303int send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
1303send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
1304{ 1304{
1305 /* 1305 /*
1306 * Make sure legacy kernel users don't send in bad values 1306 * Make sure legacy kernel users don't send in bad values
@@ -1368,7 +1368,7 @@ EXPORT_SYMBOL(kill_pid);
1368 * These functions support sending signals using preallocated sigqueue 1368 * These functions support sending signals using preallocated sigqueue
1369 * structures. This is needed "because realtime applications cannot 1369 * structures. This is needed "because realtime applications cannot
1370 * afford to lose notifications of asynchronous events, like timer 1370 * afford to lose notifications of asynchronous events, like timer
1371 * expirations or I/O completions". In the case of Posix Timers 1371 * expirations or I/O completions". In the case of POSIX Timers
1372 * we allocate the sigqueue structure from the timer_create. If this 1372 * we allocate the sigqueue structure from the timer_create. If this
1373 * allocation fails we are able to report the failure to the application 1373 * allocation fails we are able to report the failure to the application
1374 * with an EAGAIN error. 1374 * with an EAGAIN error.
@@ -1553,7 +1553,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
1553 info.si_signo = SIGCHLD; 1553 info.si_signo = SIGCHLD;
1554 info.si_errno = 0; 1554 info.si_errno = 0;
1555 /* 1555 /*
1556 * see comment in do_notify_parent() abot the following 3 lines 1556 * see comment in do_notify_parent() about the following 4 lines
1557 */ 1557 */
1558 rcu_read_lock(); 1558 rcu_read_lock();
1559 info.si_pid = task_pid_nr_ns(tsk, parent->nsproxy->pid_ns); 1559 info.si_pid = task_pid_nr_ns(tsk, parent->nsproxy->pid_ns);
@@ -1611,7 +1611,7 @@ static inline int may_ptrace_stop(void)
1611} 1611}
1612 1612
1613/* 1613/*
1614 * Return nonzero if there is a SIGKILL that should be waking us up. 1614 * Return non-zero if there is a SIGKILL that should be waking us up.
1615 * Called with the siglock held. 1615 * Called with the siglock held.
1616 */ 1616 */
1617static int sigkill_pending(struct task_struct *tsk) 1617static int sigkill_pending(struct task_struct *tsk)
@@ -1735,7 +1735,7 @@ void ptrace_notify(int exit_code)
1735/* 1735/*
1736 * This performs the stopping for SIGSTOP and other stop signals. 1736 * This performs the stopping for SIGSTOP and other stop signals.
1737 * We have to stop all threads in the thread group. 1737 * We have to stop all threads in the thread group.
1738 * Returns nonzero if we've actually stopped and released the siglock. 1738 * Returns non-zero if we've actually stopped and released the siglock.
1739 * Returns zero if we didn't stop and still hold the siglock. 1739 * Returns zero if we didn't stop and still hold the siglock.
1740 */ 1740 */
1741static int do_signal_stop(int signr) 1741static int do_signal_stop(int signr)
@@ -1823,10 +1823,12 @@ static int ptrace_signal(int signr, siginfo_t *info,
1823 1823
1824 current->exit_code = 0; 1824 current->exit_code = 0;
1825 1825
1826 /* Update the siginfo structure if the signal has 1826 /*
1827 changed. If the debugger wanted something 1827 * Update the siginfo structure if the signal has
1828 specific in the siginfo structure then it should 1828 * changed. If the debugger wanted something
1829 have updated *info via PTRACE_SETSIGINFO. */ 1829 * specific in the siginfo structure then it should
1830 * have updated *info via PTRACE_SETSIGINFO.
1831 */
1830 if (signr != info->si_signo) { 1832 if (signr != info->si_signo) {
1831 info->si_signo = signr; 1833 info->si_signo = signr;
1832 info->si_errno = 0; 1834 info->si_errno = 0;
@@ -2034,7 +2036,8 @@ void exit_signals(struct task_struct *tsk)
2034 if (!signal_pending(tsk)) 2036 if (!signal_pending(tsk))
2035 goto out; 2037 goto out;
2036 2038
2037 /* It could be that __group_complete_signal() choose us to 2039 /*
2040 * It could be that __group_complete_signal() choose us to
2038 * notify about group-wide signal. Another thread should be 2041 * notify about group-wide signal. Another thread should be
2039 * woken now to take the signal since we will not. 2042 * woken now to take the signal since we will not.
2040 */ 2043 */
@@ -2072,6 +2075,9 @@ EXPORT_SYMBOL(unblock_all_signals);
2072 * System call entry points. 2075 * System call entry points.
2073 */ 2076 */
2074 2077
2078/**
2079 * sys_restart_syscall - restart a system call
2080 */
2075SYSCALL_DEFINE0(restart_syscall) 2081SYSCALL_DEFINE0(restart_syscall)
2076{ 2082{
2077 struct restart_block *restart = &current_thread_info()->restart_block; 2083 struct restart_block *restart = &current_thread_info()->restart_block;
@@ -2125,6 +2131,13 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
2125 return error; 2131 return error;
2126} 2132}
2127 2133
2134/**
2135 * sys_rt_sigprocmask - change the list of currently blocked signals
2136 * @how: whether to add, remove, or set signals
2137 * @set: stores pending signals
2138 * @oset: previous value of signal mask if non-null
2139 * @sigsetsize: size of sigset_t type
2140 */
2128SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, set, 2141SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, set,
2129 sigset_t __user *, oset, size_t, sigsetsize) 2142 sigset_t __user *, oset, size_t, sigsetsize)
2130{ 2143{
@@ -2183,8 +2196,14 @@ long do_sigpending(void __user *set, unsigned long sigsetsize)
2183 2196
2184out: 2197out:
2185 return error; 2198 return error;
2186} 2199}
2187 2200
2201/**
2202 * sys_rt_sigpending - examine a pending signal that has been raised
2203 * while blocked
2204 * @set: stores pending signals
2205 * @sigsetsize: size of sigset_t type or larger
2206 */
2188SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize) 2207SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize)
2189{ 2208{
2190 return do_sigpending(set, sigsetsize); 2209 return do_sigpending(set, sigsetsize);
@@ -2233,9 +2252,9 @@ int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from)
2233 err |= __put_user(from->si_trapno, &to->si_trapno); 2252 err |= __put_user(from->si_trapno, &to->si_trapno);
2234#endif 2253#endif
2235#ifdef BUS_MCEERR_AO 2254#ifdef BUS_MCEERR_AO
2236 /* 2255 /*
2237 * Other callers might not initialize the si_lsb field, 2256 * Other callers might not initialize the si_lsb field,
2238 * so check explicitely for the right codes here. 2257 * so check explicitly for the right codes here.
2239 */ 2258 */
2240 if (from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO) 2259 if (from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO)
2241 err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb); 2260 err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
@@ -2264,6 +2283,14 @@ int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from)
2264 2283
2265#endif 2284#endif
2266 2285
2286/**
2287 * sys_rt_sigtimedwait - synchronously wait for queued signals specified
2288 * in @uthese
2289 * @uthese: queued signals to wait for
2290 * @uinfo: if non-null, the signal's siginfo is returned here
2291 * @uts: upper bound on process time suspension
2292 * @sigsetsize: size of sigset_t type
2293 */
2267SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, 2294SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
2268 siginfo_t __user *, uinfo, const struct timespec __user *, uts, 2295 siginfo_t __user *, uinfo, const struct timespec __user *, uts,
2269 size_t, sigsetsize) 2296 size_t, sigsetsize)
@@ -2280,7 +2307,7 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
2280 2307
2281 if (copy_from_user(&these, uthese, sizeof(these))) 2308 if (copy_from_user(&these, uthese, sizeof(these)))
2282 return -EFAULT; 2309 return -EFAULT;
2283 2310
2284 /* 2311 /*
2285 * Invert the set of allowed signals to get those we 2312 * Invert the set of allowed signals to get those we
2286 * want to block. 2313 * want to block.
@@ -2305,9 +2332,11 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
2305 + (ts.tv_sec || ts.tv_nsec)); 2332 + (ts.tv_sec || ts.tv_nsec));
2306 2333
2307 if (timeout) { 2334 if (timeout) {
2308 /* None ready -- temporarily unblock those we're 2335 /*
2336 * None ready -- temporarily unblock those we're
2309 * interested while we are sleeping in so that we'll 2337 * interested while we are sleeping in so that we'll
2310 * be awakened when they arrive. */ 2338 * be awakened when they arrive.
2339 */
2311 current->real_blocked = current->blocked; 2340 current->real_blocked = current->blocked;
2312 sigandsets(&current->blocked, &current->blocked, &these); 2341 sigandsets(&current->blocked, &current->blocked, &these);
2313 recalc_sigpending(); 2342 recalc_sigpending();
@@ -2339,6 +2368,11 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
2339 return ret; 2368 return ret;
2340} 2369}
2341 2370
2371/**
2372 * sys_kill - send a signal to a process
2373 * @pid: the PID of the process
2374 * @sig: signal to be sent
2375 */
2342SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) 2376SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
2343{ 2377{
2344 struct siginfo info; 2378 struct siginfo info;
@@ -2414,7 +2448,11 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig)
2414 return do_tkill(tgid, pid, sig); 2448 return do_tkill(tgid, pid, sig);
2415} 2449}
2416 2450
2417/* 2451/**
2452 * sys_tkill - send signal to one specific task
2453 * @pid: the PID of the task
2454 * @sig: signal to be sent
2455 *
2418 * Send a signal to only one task, even if it's a CLONE_THREAD task. 2456 * Send a signal to only one task, even if it's a CLONE_THREAD task.
2419 */ 2457 */
2420SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) 2458SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig)
@@ -2426,6 +2464,12 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig)
2426 return do_tkill(0, pid, sig); 2464 return do_tkill(0, pid, sig);
2427} 2465}
2428 2466
2467/**
2468 * sys_rt_sigqueueinfo - send signal information to a signal
2469 * @pid: the PID of the thread
2470 * @sig: signal to be sent
2471 * @uinfo: signal info to be sent
2472 */
2429SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, 2473SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
2430 siginfo_t __user *, uinfo) 2474 siginfo_t __user *, uinfo)
2431{ 2475{
@@ -2553,12 +2597,11 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s
2553 2597
2554 error = -EINVAL; 2598 error = -EINVAL;
2555 /* 2599 /*
2556 * 2600 * Note - this code used to test ss_flags incorrectly:
2557 * Note - this code used to test ss_flags incorrectly
2558 * old code may have been written using ss_flags==0 2601 * old code may have been written using ss_flags==0
2559 * to mean ss_flags==SS_ONSTACK (as this was the only 2602 * to mean ss_flags==SS_ONSTACK (as this was the only
2560 * way that worked) - this fix preserves that older 2603 * way that worked) - this fix preserves that older
2561 * mechanism 2604 * mechanism.
2562 */ 2605 */
2563 if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0) 2606 if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0)
2564 goto out; 2607 goto out;
@@ -2592,6 +2635,10 @@ out:
2592 2635
2593#ifdef __ARCH_WANT_SYS_SIGPENDING 2636#ifdef __ARCH_WANT_SYS_SIGPENDING
2594 2637
2638/**
2639 * sys_sigpending - examine pending signals
2640 * @set: where mask of pending signal is returned
2641 */
2595SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set) 2642SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set)
2596{ 2643{
2597 return do_sigpending(set, sizeof(*set)); 2644 return do_sigpending(set, sizeof(*set));
@@ -2600,8 +2647,15 @@ SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set)
2600#endif 2647#endif
2601 2648
2602#ifdef __ARCH_WANT_SYS_SIGPROCMASK 2649#ifdef __ARCH_WANT_SYS_SIGPROCMASK
2603/* Some platforms have their own version with special arguments others 2650/**
2604 support only sys_rt_sigprocmask. */ 2651 * sys_sigprocmask - examine and change blocked signals
2652 * @how: whether to add, remove, or set signals
2653 * @set: signals to add or remove (if non-null)
2654 * @oset: previous value of signal mask if non-null
2655 *
2656 * Some platforms have their own version with special arguments;
2657 * others support only sys_rt_sigprocmask.
2658 */
2605 2659
2606SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set, 2660SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set,
2607 old_sigset_t __user *, oset) 2661 old_sigset_t __user *, oset)
@@ -2654,6 +2708,13 @@ out:
2654#endif /* __ARCH_WANT_SYS_SIGPROCMASK */ 2708#endif /* __ARCH_WANT_SYS_SIGPROCMASK */
2655 2709
2656#ifdef __ARCH_WANT_SYS_RT_SIGACTION 2710#ifdef __ARCH_WANT_SYS_RT_SIGACTION
2711/**
2712 * sys_rt_sigaction - alter an action taken by a process
2713 * @sig: signal to be sent
2714 * @act: the thread group ID of the thread
2715 * @oact: the PID of the thread
2716 * @sigsetsize: size of sigset_t type
2717 */
2657SYSCALL_DEFINE4(rt_sigaction, int, sig, 2718SYSCALL_DEFINE4(rt_sigaction, int, sig,
2658 const struct sigaction __user *, act, 2719 const struct sigaction __user *, act,
2659 struct sigaction __user *, oact, 2720 struct sigaction __user *, oact,
@@ -2740,6 +2801,12 @@ SYSCALL_DEFINE0(pause)
2740#endif 2801#endif
2741 2802
2742#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND 2803#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
2804/**
2805 * sys_rt_sigsuspend - replace the signal mask for a value with the
2806 * @unewset value until a signal is received
2807 * @unewset: new signal mask value
2808 * @sigsetsize: size of sigset_t type
2809 */
2743SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize) 2810SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize)
2744{ 2811{
2745 sigset_t newset; 2812 sigset_t newset;