Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/signal.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson |
| 7 | * |
| 8 | * 2003-06-02 Jim Houston - Concurrent Computer Corp. |
| 9 | * Changes to use preallocated sigqueue structures |
| 10 | * to allow signals to be sent reliably. |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/slab.h> |
| 14 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/tty.h> |
| 19 | #include <linux/binfmts.h> |
| 20 | #include <linux/security.h> |
| 21 | #include <linux/syscalls.h> |
| 22 | #include <linux/ptrace.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 23 | #include <linux/signal.h> |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 24 | #include <linux/signalfd.h> |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 25 | #include <linux/ratelimit.h> |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 26 | #include <linux/tracehook.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 27 | #include <linux/capability.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 28 | #include <linux/freezer.h> |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 29 | #include <linux/pid_namespace.h> |
| 30 | #include <linux/nsproxy.h> |
Masami Hiramatsu | d1eb650 | 2009-11-24 16:56:45 -0500 | [diff] [blame] | 31 | #define CREATE_TRACE_POINTS |
| 32 | #include <trace/events/signal.h> |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/param.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/unistd.h> |
| 37 | #include <asm/siginfo.h> |
Al Viro | e139606 | 2006-05-25 10:19:47 -0400 | [diff] [blame] | 38 | #include "audit.h" /* audit_signal_info() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * SLAB caches for signal bits. |
| 42 | */ |
| 43 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 44 | static struct kmem_cache *sigqueue_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 46 | int print_fatal_signals __read_mostly; |
| 47 | |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 48 | static void __user *sig_handler(struct task_struct *t, int sig) |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 49 | { |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 50 | return t->sighand->action[sig - 1].sa.sa_handler; |
| 51 | } |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 52 | |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 53 | static int sig_handler_ignored(void __user *handler, int sig) |
| 54 | { |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 55 | /* Is it explicitly or implicitly ignored? */ |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 56 | return handler == SIG_IGN || |
| 57 | (handler == SIG_DFL && sig_kernel_ignore(sig)); |
| 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 60 | static int sig_task_ignored(struct task_struct *t, int sig, |
| 61 | int from_ancestor_ns) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 63 | void __user *handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Oleg Nesterov | f008faf | 2009-04-02 16:58:02 -0700 | [diff] [blame] | 65 | handler = sig_handler(t, sig); |
| 66 | |
| 67 | if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) && |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 68 | handler == SIG_DFL && !from_ancestor_ns) |
Oleg Nesterov | f008faf | 2009-04-02 16:58:02 -0700 | [diff] [blame] | 69 | return 1; |
| 70 | |
| 71 | return sig_handler_ignored(handler, sig); |
| 72 | } |
| 73 | |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 74 | static int sig_ignored(struct task_struct *t, int sig, int from_ancestor_ns) |
Oleg Nesterov | f008faf | 2009-04-02 16:58:02 -0700 | [diff] [blame] | 75 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * Blocked signals are never ignored, since the |
| 78 | * signal handler may change by the time it is |
| 79 | * unblocked. |
| 80 | */ |
Roland McGrath | 325d22d | 2007-11-12 15:41:55 -0800 | [diff] [blame] | 81 | if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return 0; |
| 83 | |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 84 | if (!sig_task_ignored(t, sig, from_ancestor_ns)) |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | |
| 87 | /* |
| 88 | * Tracers may want to know about even ignored signals. |
| 89 | */ |
Oleg Nesterov | 43918f2 | 2009-04-02 16:58:00 -0700 | [diff] [blame] | 90 | return !tracehook_consider_ignored_signal(t, sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Re-calculate pending state from the set of locally pending |
| 95 | * signals, globally pending signals, and blocked signals. |
| 96 | */ |
| 97 | static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked) |
| 98 | { |
| 99 | unsigned long ready; |
| 100 | long i; |
| 101 | |
| 102 | switch (_NSIG_WORDS) { |
| 103 | default: |
| 104 | for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;) |
| 105 | ready |= signal->sig[i] &~ blocked->sig[i]; |
| 106 | break; |
| 107 | |
| 108 | case 4: ready = signal->sig[3] &~ blocked->sig[3]; |
| 109 | ready |= signal->sig[2] &~ blocked->sig[2]; |
| 110 | ready |= signal->sig[1] &~ blocked->sig[1]; |
| 111 | ready |= signal->sig[0] &~ blocked->sig[0]; |
| 112 | break; |
| 113 | |
| 114 | case 2: ready = signal->sig[1] &~ blocked->sig[1]; |
| 115 | ready |= signal->sig[0] &~ blocked->sig[0]; |
| 116 | break; |
| 117 | |
| 118 | case 1: ready = signal->sig[0] &~ blocked->sig[0]; |
| 119 | } |
| 120 | return ready != 0; |
| 121 | } |
| 122 | |
| 123 | #define PENDING(p,b) has_pending_signals(&(p)->signal, (b)) |
| 124 | |
Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 125 | static int recalc_sigpending_tsk(struct task_struct *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | if (t->signal->group_stop_count > 0 || |
| 128 | PENDING(&t->pending, &t->blocked) || |
Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 129 | PENDING(&t->signal->shared_pending, &t->blocked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | set_tsk_thread_flag(t, TIF_SIGPENDING); |
Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 131 | return 1; |
| 132 | } |
Roland McGrath | b74d0de | 2007-06-06 03:59:00 -0700 | [diff] [blame] | 133 | /* |
| 134 | * We must never clear the flag in another thread, or in current |
| 135 | * when it's possible the current syscall is returning -ERESTART*. |
| 136 | * So we don't clear it here, and only callers who know they should do. |
| 137 | */ |
Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up. |
| 143 | * This is superfluous when called on current, the wakeup is a harmless no-op. |
| 144 | */ |
| 145 | void recalc_sigpending_and_wake(struct task_struct *t) |
| 146 | { |
| 147 | if (recalc_sigpending_tsk(t)) |
| 148 | signal_wake_up(t, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void recalc_sigpending(void) |
| 152 | { |
Roland McGrath | b787f7b | 2008-07-25 19:45:55 -0700 | [diff] [blame] | 153 | if (unlikely(tracehook_force_sigpending())) |
| 154 | set_thread_flag(TIF_SIGPENDING); |
| 155 | else if (!recalc_sigpending_tsk(current) && !freezing(current)) |
Roland McGrath | b74d0de | 2007-06-06 03:59:00 -0700 | [diff] [blame] | 156 | clear_thread_flag(TIF_SIGPENDING); |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* Given the mask, find the first available signal that should be serviced. */ |
| 161 | |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 162 | int next_signal(struct sigpending *pending, sigset_t *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
| 164 | unsigned long i, *s, *m, x; |
| 165 | int sig = 0; |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | s = pending->signal.sig; |
| 168 | m = mask->sig; |
| 169 | switch (_NSIG_WORDS) { |
| 170 | default: |
| 171 | for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m) |
| 172 | if ((x = *s &~ *m) != 0) { |
| 173 | sig = ffz(~x) + i*_NSIG_BPW + 1; |
| 174 | break; |
| 175 | } |
| 176 | break; |
| 177 | |
| 178 | case 2: if ((x = s[0] &~ m[0]) != 0) |
| 179 | sig = 1; |
| 180 | else if ((x = s[1] &~ m[1]) != 0) |
| 181 | sig = _NSIG_BPW + 1; |
| 182 | else |
| 183 | break; |
| 184 | sig += ffz(~x); |
| 185 | break; |
| 186 | |
| 187 | case 1: if ((x = *s &~ *m) != 0) |
| 188 | sig = ffz(~x) + 1; |
| 189 | break; |
| 190 | } |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return sig; |
| 193 | } |
| 194 | |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 195 | static inline void print_dropped_signal(int sig) |
| 196 | { |
| 197 | static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10); |
| 198 | |
| 199 | if (!print_fatal_signals) |
| 200 | return; |
| 201 | |
| 202 | if (!__ratelimit(&ratelimit_state)) |
| 203 | return; |
| 204 | |
| 205 | printk(KERN_INFO "%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n", |
| 206 | current->comm, current->pid, sig); |
| 207 | } |
| 208 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 209 | /* |
| 210 | * allocate a new signal queue record |
| 211 | * - this may be called without locks if and only if t == current, otherwise an |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 212 | * appopriate lock must be held to stop the target task from exiting |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 213 | */ |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 214 | static struct sigqueue * |
| 215 | __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | struct sigqueue *q = NULL; |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 218 | struct user_struct *user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 220 | /* |
Thomas Gleixner | 7cf7db8 | 2009-12-10 00:53:21 +0000 | [diff] [blame^] | 221 | * Protect access to @t credentials. This can go away when all |
| 222 | * callers hold rcu read lock. |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 223 | */ |
Thomas Gleixner | 7cf7db8 | 2009-12-10 00:53:21 +0000 | [diff] [blame^] | 224 | rcu_read_lock(); |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 225 | user = get_uid(__task_cred(t)->user); |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 226 | atomic_inc(&user->sigpending); |
Thomas Gleixner | 7cf7db8 | 2009-12-10 00:53:21 +0000 | [diff] [blame^] | 227 | rcu_read_unlock(); |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | if (override_rlimit || |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 230 | atomic_read(&user->sigpending) <= |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 231 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | q = kmem_cache_alloc(sigqueue_cachep, flags); |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 233 | } else { |
| 234 | print_dropped_signal(sig); |
| 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | if (unlikely(q == NULL)) { |
Linus Torvalds | 10b1fbd | 2006-11-04 13:03:00 -0800 | [diff] [blame] | 238 | atomic_dec(&user->sigpending); |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 239 | free_uid(user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } else { |
| 241 | INIT_LIST_HEAD(&q->list); |
| 242 | q->flags = 0; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 243 | q->user = user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 245 | |
| 246 | return q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Andrew Morton | 514a01b | 2006-02-03 03:04:41 -0800 | [diff] [blame] | 249 | static void __sigqueue_free(struct sigqueue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | if (q->flags & SIGQUEUE_PREALLOC) |
| 252 | return; |
| 253 | atomic_dec(&q->user->sigpending); |
| 254 | free_uid(q->user); |
| 255 | kmem_cache_free(sigqueue_cachep, q); |
| 256 | } |
| 257 | |
Oleg Nesterov | 6a14c5c | 2006-03-28 16:11:18 -0800 | [diff] [blame] | 258 | void flush_sigqueue(struct sigpending *queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | struct sigqueue *q; |
| 261 | |
| 262 | sigemptyset(&queue->signal); |
| 263 | while (!list_empty(&queue->list)) { |
| 264 | q = list_entry(queue->list.next, struct sigqueue , list); |
| 265 | list_del_init(&q->list); |
| 266 | __sigqueue_free(q); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Flush all pending signals for a task. |
| 272 | */ |
David Howells | 3bcac02 | 2009-04-29 13:45:05 +0100 | [diff] [blame] | 273 | void __flush_signals(struct task_struct *t) |
| 274 | { |
| 275 | clear_tsk_thread_flag(t, TIF_SIGPENDING); |
| 276 | flush_sigqueue(&t->pending); |
| 277 | flush_sigqueue(&t->signal->shared_pending); |
| 278 | } |
| 279 | |
Oleg Nesterov | c81addc | 2006-03-28 16:11:17 -0800 | [diff] [blame] | 280 | void flush_signals(struct task_struct *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | unsigned long flags; |
| 283 | |
| 284 | spin_lock_irqsave(&t->sighand->siglock, flags); |
David Howells | 3bcac02 | 2009-04-29 13:45:05 +0100 | [diff] [blame] | 285 | __flush_signals(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
| 287 | } |
| 288 | |
Oleg Nesterov | cbaffba | 2008-05-26 20:55:42 +0400 | [diff] [blame] | 289 | static void __flush_itimer_signals(struct sigpending *pending) |
| 290 | { |
| 291 | sigset_t signal, retain; |
| 292 | struct sigqueue *q, *n; |
| 293 | |
| 294 | signal = pending->signal; |
| 295 | sigemptyset(&retain); |
| 296 | |
| 297 | list_for_each_entry_safe(q, n, &pending->list, list) { |
| 298 | int sig = q->info.si_signo; |
| 299 | |
| 300 | if (likely(q->info.si_code != SI_TIMER)) { |
| 301 | sigaddset(&retain, sig); |
| 302 | } else { |
| 303 | sigdelset(&signal, sig); |
| 304 | list_del_init(&q->list); |
| 305 | __sigqueue_free(q); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | sigorsets(&pending->signal, &signal, &retain); |
| 310 | } |
| 311 | |
| 312 | void flush_itimer_signals(void) |
| 313 | { |
| 314 | struct task_struct *tsk = current; |
| 315 | unsigned long flags; |
| 316 | |
| 317 | spin_lock_irqsave(&tsk->sighand->siglock, flags); |
| 318 | __flush_itimer_signals(&tsk->pending); |
| 319 | __flush_itimer_signals(&tsk->signal->shared_pending); |
| 320 | spin_unlock_irqrestore(&tsk->sighand->siglock, flags); |
| 321 | } |
| 322 | |
Oleg Nesterov | 10ab825 | 2007-05-09 02:34:37 -0700 | [diff] [blame] | 323 | void ignore_signals(struct task_struct *t) |
| 324 | { |
| 325 | int i; |
| 326 | |
| 327 | for (i = 0; i < _NSIG; ++i) |
| 328 | t->sighand->action[i].sa.sa_handler = SIG_IGN; |
| 329 | |
| 330 | flush_signals(t); |
| 331 | } |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | * Flush all handlers for a task. |
| 335 | */ |
| 336 | |
| 337 | void |
| 338 | flush_signal_handlers(struct task_struct *t, int force_default) |
| 339 | { |
| 340 | int i; |
| 341 | struct k_sigaction *ka = &t->sighand->action[0]; |
| 342 | for (i = _NSIG ; i != 0 ; i--) { |
| 343 | if (force_default || ka->sa.sa_handler != SIG_IGN) |
| 344 | ka->sa.sa_handler = SIG_DFL; |
| 345 | ka->sa.sa_flags = 0; |
| 346 | sigemptyset(&ka->sa.sa_mask); |
| 347 | ka++; |
| 348 | } |
| 349 | } |
| 350 | |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 351 | int unhandled_signal(struct task_struct *tsk, int sig) |
| 352 | { |
Roland McGrath | 445a91d | 2008-07-25 19:45:52 -0700 | [diff] [blame] | 353 | void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler; |
Serge E. Hallyn | b460cbc | 2007-10-18 23:39:52 -0700 | [diff] [blame] | 354 | if (is_global_init(tsk)) |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 355 | return 1; |
Roland McGrath | 445a91d | 2008-07-25 19:45:52 -0700 | [diff] [blame] | 356 | if (handler != SIG_IGN && handler != SIG_DFL) |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 357 | return 0; |
Oleg Nesterov | 43918f2 | 2009-04-02 16:58:00 -0700 | [diff] [blame] | 358 | return !tracehook_consider_fatal_signal(tsk, sig); |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* Notify the system that a driver wants to block all signals for this |
| 363 | * process, and wants to be notified if any signals at all were to be |
| 364 | * sent/acted upon. If the notifier routine returns non-zero, then the |
| 365 | * signal will be acted upon after all. If the notifier routine returns 0, |
| 366 | * then then signal will be blocked. Only one block per process is |
| 367 | * allowed. priv is a pointer to private data that the notifier routine |
| 368 | * can use to determine if the signal should be blocked or not. */ |
| 369 | |
| 370 | void |
| 371 | block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask) |
| 372 | { |
| 373 | unsigned long flags; |
| 374 | |
| 375 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 376 | current->notifier_mask = mask; |
| 377 | current->notifier_data = priv; |
| 378 | current->notifier = notifier; |
| 379 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 380 | } |
| 381 | |
| 382 | /* Notify the system that blocking has ended. */ |
| 383 | |
| 384 | void |
| 385 | unblock_all_signals(void) |
| 386 | { |
| 387 | unsigned long flags; |
| 388 | |
| 389 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 390 | current->notifier = NULL; |
| 391 | current->notifier_data = NULL; |
| 392 | recalc_sigpending(); |
| 393 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 394 | } |
| 395 | |
Oleg Nesterov | 100360f | 2008-07-25 01:47:29 -0700 | [diff] [blame] | 396 | static void collect_signal(int sig, struct sigpending *list, siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
| 398 | struct sigqueue *q, *first = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* |
| 401 | * Collect the siginfo appropriate to this signal. Check if |
| 402 | * there is another siginfo for the same signal. |
| 403 | */ |
| 404 | list_for_each_entry(q, &list->list, list) { |
| 405 | if (q->info.si_signo == sig) { |
Oleg Nesterov | d443420 | 2008-07-25 01:47:28 -0700 | [diff] [blame] | 406 | if (first) |
| 407 | goto still_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | first = q; |
| 409 | } |
| 410 | } |
Oleg Nesterov | d443420 | 2008-07-25 01:47:28 -0700 | [diff] [blame] | 411 | |
| 412 | sigdelset(&list->signal, sig); |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if (first) { |
Oleg Nesterov | d443420 | 2008-07-25 01:47:28 -0700 | [diff] [blame] | 415 | still_pending: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | list_del_init(&first->list); |
| 417 | copy_siginfo(info, &first->info); |
| 418 | __sigqueue_free(first); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* Ok, it wasn't in the queue. This must be |
| 421 | a fast-pathed signal or we must have been |
| 422 | out of queue space. So zero out the info. |
| 423 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | info->si_signo = sig; |
| 425 | info->si_errno = 0; |
| 426 | info->si_code = 0; |
| 427 | info->si_pid = 0; |
| 428 | info->si_uid = 0; |
| 429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, |
| 433 | siginfo_t *info) |
| 434 | { |
Roland McGrath | 27d91e0 | 2006-09-29 02:00:31 -0700 | [diff] [blame] | 435 | int sig = next_signal(pending, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | if (sig) { |
| 438 | if (current->notifier) { |
| 439 | if (sigismember(current->notifier_mask, sig)) { |
| 440 | if (!(current->notifier)(current->notifier_data)) { |
| 441 | clear_thread_flag(TIF_SIGPENDING); |
| 442 | return 0; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Oleg Nesterov | 100360f | 2008-07-25 01:47:29 -0700 | [diff] [blame] | 447 | collect_signal(sig, pending, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | return sig; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Dequeue a signal and return the element to the caller, which is |
| 455 | * expected to free it. |
| 456 | * |
| 457 | * All callers have to hold the siglock. |
| 458 | */ |
| 459 | int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) |
| 460 | { |
Pavel Emelyanov | c5363d0 | 2008-04-30 00:52:40 -0700 | [diff] [blame] | 461 | int signr; |
Benjamin Herrenschmidt | caec4e8 | 2007-06-12 08:16:18 +1000 | [diff] [blame] | 462 | |
| 463 | /* We only dequeue private signals from ourselves, we don't let |
| 464 | * signalfd steal them |
| 465 | */ |
Davide Libenzi | b8fceee | 2007-09-20 12:40:16 -0700 | [diff] [blame] | 466 | signr = __dequeue_signal(&tsk->pending, mask, info); |
Thomas Gleixner | 8bfd9a7 | 2007-02-16 01:28:12 -0800 | [diff] [blame] | 467 | if (!signr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | signr = __dequeue_signal(&tsk->signal->shared_pending, |
| 469 | mask, info); |
Thomas Gleixner | 8bfd9a7 | 2007-02-16 01:28:12 -0800 | [diff] [blame] | 470 | /* |
| 471 | * itimer signal ? |
| 472 | * |
| 473 | * itimers are process shared and we restart periodic |
| 474 | * itimers in the signal delivery path to prevent DoS |
| 475 | * attacks in the high resolution timer case. This is |
| 476 | * compliant with the old way of self restarting |
| 477 | * itimers, as the SIGALRM is a legacy signal and only |
| 478 | * queued once. Changing the restart behaviour to |
| 479 | * restart the timer in the signal dequeue path is |
| 480 | * reducing the timer noise on heavy loaded !highres |
| 481 | * systems too. |
| 482 | */ |
| 483 | if (unlikely(signr == SIGALRM)) { |
| 484 | struct hrtimer *tmr = &tsk->signal->real_timer; |
| 485 | |
| 486 | if (!hrtimer_is_queued(tmr) && |
| 487 | tsk->signal->it_real_incr.tv64 != 0) { |
| 488 | hrtimer_forward(tmr, tmr->base->get_time(), |
| 489 | tsk->signal->it_real_incr); |
| 490 | hrtimer_restart(tmr); |
| 491 | } |
| 492 | } |
| 493 | } |
Pavel Emelyanov | c5363d0 | 2008-04-30 00:52:40 -0700 | [diff] [blame] | 494 | |
Davide Libenzi | b8fceee | 2007-09-20 12:40:16 -0700 | [diff] [blame] | 495 | recalc_sigpending(); |
Pavel Emelyanov | c5363d0 | 2008-04-30 00:52:40 -0700 | [diff] [blame] | 496 | if (!signr) |
| 497 | return 0; |
| 498 | |
| 499 | if (unlikely(sig_kernel_stop(signr))) { |
Thomas Gleixner | 8bfd9a7 | 2007-02-16 01:28:12 -0800 | [diff] [blame] | 500 | /* |
| 501 | * Set a marker that we have dequeued a stop signal. Our |
| 502 | * caller might release the siglock and then the pending |
| 503 | * stop signal it is about to process is no longer in the |
| 504 | * pending bitmasks, but must still be cleared by a SIGCONT |
| 505 | * (and overruled by a SIGKILL). So those cases clear this |
| 506 | * shared flag after we've set it. Note that this flag may |
| 507 | * remain set after the signal we return is ignored or |
| 508 | * handled. That doesn't matter because its only purpose |
| 509 | * is to alert stop-signal processing code when another |
| 510 | * processor has come along and cleared the flag. |
| 511 | */ |
Oleg Nesterov | 92413d7 | 2008-07-25 01:47:30 -0700 | [diff] [blame] | 512 | tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; |
Thomas Gleixner | 8bfd9a7 | 2007-02-16 01:28:12 -0800 | [diff] [blame] | 513 | } |
Pavel Emelyanov | c5363d0 | 2008-04-30 00:52:40 -0700 | [diff] [blame] | 514 | if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* |
| 516 | * Release the siglock to ensure proper locking order |
| 517 | * of timer locks outside of siglocks. Note, we leave |
| 518 | * irqs disabled here, since the posix-timers code is |
| 519 | * about to disable them again anyway. |
| 520 | */ |
| 521 | spin_unlock(&tsk->sighand->siglock); |
| 522 | do_schedule_next_timer(info); |
| 523 | spin_lock(&tsk->sighand->siglock); |
| 524 | } |
| 525 | return signr; |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * Tell a process that it has a new active signal.. |
| 530 | * |
| 531 | * NOTE! we rely on the previous spin_lock to |
| 532 | * lock interrupts for us! We can only be called with |
| 533 | * "siglock" held, and the local interrupt must |
| 534 | * have been disabled when that got acquired! |
| 535 | * |
| 536 | * No need to set need_resched since signal event passing |
| 537 | * goes through ->blocked |
| 538 | */ |
| 539 | void signal_wake_up(struct task_struct *t, int resume) |
| 540 | { |
| 541 | unsigned int mask; |
| 542 | |
| 543 | set_tsk_thread_flag(t, TIF_SIGPENDING); |
| 544 | |
| 545 | /* |
Matthew Wilcox | f021a3c | 2007-12-06 11:13:16 -0500 | [diff] [blame] | 546 | * For SIGKILL, we want to wake it up in the stopped/traced/killable |
| 547 | * case. We don't check t->state here because there is a race with it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | * executing another processor and just now entering stopped state. |
| 549 | * By using wake_up_state, we ensure the process will wake up and |
| 550 | * handle its death signal. |
| 551 | */ |
| 552 | mask = TASK_INTERRUPTIBLE; |
| 553 | if (resume) |
Matthew Wilcox | f021a3c | 2007-12-06 11:13:16 -0500 | [diff] [blame] | 554 | mask |= TASK_WAKEKILL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (!wake_up_state(t, mask)) |
| 556 | kick_process(t); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Remove signals in mask from the pending set and queue. |
| 561 | * Returns 1 if any signals were found. |
| 562 | * |
| 563 | * All callers must be holding the siglock. |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 564 | * |
| 565 | * This version takes a sigset mask and looks at all signals, |
| 566 | * not just those in the first mask word. |
| 567 | */ |
| 568 | static int rm_from_queue_full(sigset_t *mask, struct sigpending *s) |
| 569 | { |
| 570 | struct sigqueue *q, *n; |
| 571 | sigset_t m; |
| 572 | |
| 573 | sigandsets(&m, mask, &s->signal); |
| 574 | if (sigisemptyset(&m)) |
| 575 | return 0; |
| 576 | |
| 577 | signandsets(&s->signal, &s->signal, mask); |
| 578 | list_for_each_entry_safe(q, n, &s->list, list) { |
| 579 | if (sigismember(mask, q->info.si_signo)) { |
| 580 | list_del_init(&q->list); |
| 581 | __sigqueue_free(q); |
| 582 | } |
| 583 | } |
| 584 | return 1; |
| 585 | } |
| 586 | /* |
| 587 | * Remove signals in mask from the pending set and queue. |
| 588 | * Returns 1 if any signals were found. |
| 589 | * |
| 590 | * All callers must be holding the siglock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | */ |
| 592 | static int rm_from_queue(unsigned long mask, struct sigpending *s) |
| 593 | { |
| 594 | struct sigqueue *q, *n; |
| 595 | |
| 596 | if (!sigtestsetmask(&s->signal, mask)) |
| 597 | return 0; |
| 598 | |
| 599 | sigdelsetmask(&s->signal, mask); |
| 600 | list_for_each_entry_safe(q, n, &s->list, list) { |
| 601 | if (q->info.si_signo < SIGRTMIN && |
| 602 | (mask & sigmask(q->info.si_signo))) { |
| 603 | list_del_init(&q->list); |
| 604 | __sigqueue_free(q); |
| 605 | } |
| 606 | } |
| 607 | return 1; |
| 608 | } |
| 609 | |
| 610 | /* |
| 611 | * Bad permissions for sending the signal |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 612 | * - the caller must hold at least the RCU read lock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | */ |
| 614 | static int check_kill_permission(int sig, struct siginfo *info, |
| 615 | struct task_struct *t) |
| 616 | { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 617 | const struct cred *cred = current_cred(), *tcred; |
Oleg Nesterov | 2e2ba22 | 2008-04-30 00:53:01 -0700 | [diff] [blame] | 618 | struct pid *sid; |
Oleg Nesterov | 3b5e9e5 | 2008-04-30 00:52:42 -0700 | [diff] [blame] | 619 | int error; |
| 620 | |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 621 | if (!valid_signal(sig)) |
Oleg Nesterov | 3b5e9e5 | 2008-04-30 00:52:42 -0700 | [diff] [blame] | 622 | return -EINVAL; |
| 623 | |
| 624 | if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info))) |
| 625 | return 0; |
| 626 | |
| 627 | error = audit_signal_info(sig, t); /* Let audit system see the signal */ |
| 628 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return error; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 630 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 631 | tcred = __task_cred(t); |
| 632 | if ((cred->euid ^ tcred->suid) && |
| 633 | (cred->euid ^ tcred->uid) && |
| 634 | (cred->uid ^ tcred->suid) && |
| 635 | (cred->uid ^ tcred->uid) && |
Oleg Nesterov | 2e2ba22 | 2008-04-30 00:53:01 -0700 | [diff] [blame] | 636 | !capable(CAP_KILL)) { |
| 637 | switch (sig) { |
| 638 | case SIGCONT: |
Oleg Nesterov | 2e2ba22 | 2008-04-30 00:53:01 -0700 | [diff] [blame] | 639 | sid = task_session(t); |
Oleg Nesterov | 2e2ba22 | 2008-04-30 00:53:01 -0700 | [diff] [blame] | 640 | /* |
| 641 | * We don't return the error if sid == NULL. The |
| 642 | * task was unhashed, the caller must notice this. |
| 643 | */ |
| 644 | if (!sid || sid == task_session(current)) |
| 645 | break; |
| 646 | default: |
| 647 | return -EPERM; |
| 648 | } |
| 649 | } |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 650 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 651 | return security_task_kill(t, info, sig, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 655 | * Handle magic process-wide effects of stop/continue signals. Unlike |
| 656 | * the signal actions, these happen immediately at signal-generation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | * time regardless of blocking, ignoring, or handling. This does the |
| 658 | * actual continuing for SIGCONT, but not the actual stopping for stop |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 659 | * signals. The process stop is done as a signal action for SIG_DFL. |
| 660 | * |
| 661 | * Returns true if the signal should be actually delivered, otherwise |
| 662 | * it should be dropped. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | */ |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 664 | static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 666 | struct signal_struct *signal = p->signal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | struct task_struct *t; |
| 668 | |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 669 | if (unlikely(signal->flags & SIGNAL_GROUP_EXIT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 671 | * The process is in the middle of dying, nothing to do. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | */ |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 673 | } else if (sig_kernel_stop(sig)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | /* |
| 675 | * This is a stop signal. Remove SIGCONT from all queues. |
| 676 | */ |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 677 | rm_from_queue(sigmask(SIGCONT), &signal->shared_pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | t = p; |
| 679 | do { |
| 680 | rm_from_queue(sigmask(SIGCONT), &t->pending); |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 681 | } while_each_thread(p, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } else if (sig == SIGCONT) { |
Oleg Nesterov | fc321d2 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 683 | unsigned int why; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* |
| 685 | * Remove all stop signals from all queues, |
| 686 | * and wake all threads. |
| 687 | */ |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 688 | rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | t = p; |
| 690 | do { |
| 691 | unsigned int state; |
| 692 | rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* |
| 694 | * If there is a handler for SIGCONT, we must make |
| 695 | * sure that no thread returns to user mode before |
| 696 | * we post the signal, in case it was the only |
| 697 | * thread eligible to run the signal handler--then |
| 698 | * it must not do anything between resuming and |
| 699 | * running the handler. With the TIF_SIGPENDING |
| 700 | * flag set, the thread will pause and acquire the |
| 701 | * siglock that we hold now and until we've queued |
Oleg Nesterov | fc321d2 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 702 | * the pending signal. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | * |
| 704 | * Wake up the stopped thread _after_ setting |
| 705 | * TIF_SIGPENDING |
| 706 | */ |
Matthew Wilcox | f021a3c | 2007-12-06 11:13:16 -0500 | [diff] [blame] | 707 | state = __TASK_STOPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if (sig_user_defined(t, SIGCONT) && !sigismember(&t->blocked, SIGCONT)) { |
| 709 | set_tsk_thread_flag(t, TIF_SIGPENDING); |
| 710 | state |= TASK_INTERRUPTIBLE; |
| 711 | } |
| 712 | wake_up_state(t, state); |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 713 | } while_each_thread(p, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Oleg Nesterov | fc321d2 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 715 | /* |
| 716 | * Notify the parent with CLD_CONTINUED if we were stopped. |
| 717 | * |
| 718 | * If we were in the middle of a group stop, we pretend it |
| 719 | * was already finished, and then continued. Since SIGCHLD |
| 720 | * doesn't queue we report only CLD_STOPPED, as if the next |
| 721 | * CLD_CONTINUED was dropped. |
| 722 | */ |
| 723 | why = 0; |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 724 | if (signal->flags & SIGNAL_STOP_STOPPED) |
Oleg Nesterov | fc321d2 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 725 | why |= SIGNAL_CLD_CONTINUED; |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 726 | else if (signal->group_stop_count) |
Oleg Nesterov | fc321d2 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 727 | why |= SIGNAL_CLD_STOPPED; |
| 728 | |
| 729 | if (why) { |
Oleg Nesterov | 021e1ae | 2008-04-30 00:53:00 -0700 | [diff] [blame] | 730 | /* |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 731 | * The first thread which returns from do_signal_stop() |
Oleg Nesterov | 021e1ae | 2008-04-30 00:53:00 -0700 | [diff] [blame] | 732 | * will take ->siglock, notice SIGNAL_CLD_MASK, and |
| 733 | * notify its parent. See get_signal_to_deliver(). |
| 734 | */ |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 735 | signal->flags = why | SIGNAL_STOP_CONTINUED; |
| 736 | signal->group_stop_count = 0; |
| 737 | signal->group_exit_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } else { |
| 739 | /* |
| 740 | * We are not stopped, but there could be a stop |
| 741 | * signal in the middle of being processed after |
| 742 | * being removed from the queue. Clear that too. |
| 743 | */ |
Oleg Nesterov | ad16a460 | 2008-04-30 00:52:46 -0700 | [diff] [blame] | 744 | signal->flags &= ~SIGNAL_STOP_DEQUEUED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 747 | |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 748 | return !sig_ignored(p, sig, from_ancestor_ns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Oleg Nesterov | 71f11dc | 2008-04-30 00:52:53 -0700 | [diff] [blame] | 751 | /* |
| 752 | * Test if P wants to take SIG. After we've checked all threads with this, |
| 753 | * it's equivalent to finding no threads not blocking SIG. Any threads not |
| 754 | * blocking SIG were ruled out because they are not running and already |
| 755 | * have pending signals. Such threads will dequeue from the shared queue |
| 756 | * as soon as they're available, so putting the signal on the shared queue |
| 757 | * will be equivalent to sending it to one such thread. |
| 758 | */ |
| 759 | static inline int wants_signal(int sig, struct task_struct *p) |
| 760 | { |
| 761 | if (sigismember(&p->blocked, sig)) |
| 762 | return 0; |
| 763 | if (p->flags & PF_EXITING) |
| 764 | return 0; |
| 765 | if (sig == SIGKILL) |
| 766 | return 1; |
| 767 | if (task_is_stopped_or_traced(p)) |
| 768 | return 0; |
| 769 | return task_curr(p) || !signal_pending(p); |
| 770 | } |
| 771 | |
Oleg Nesterov | 5fcd835 | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 772 | static void complete_signal(int sig, struct task_struct *p, int group) |
Oleg Nesterov | 71f11dc | 2008-04-30 00:52:53 -0700 | [diff] [blame] | 773 | { |
| 774 | struct signal_struct *signal = p->signal; |
| 775 | struct task_struct *t; |
| 776 | |
| 777 | /* |
| 778 | * Now find a thread we can wake up to take the signal off the queue. |
| 779 | * |
| 780 | * If the main thread wants the signal, it gets first crack. |
| 781 | * Probably the least surprising to the average bear. |
| 782 | */ |
| 783 | if (wants_signal(sig, p)) |
| 784 | t = p; |
Oleg Nesterov | 5fcd835 | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 785 | else if (!group || thread_group_empty(p)) |
Oleg Nesterov | 71f11dc | 2008-04-30 00:52:53 -0700 | [diff] [blame] | 786 | /* |
| 787 | * There is just one thread and it does not need to be woken. |
| 788 | * It will dequeue unblocked signals before it runs again. |
| 789 | */ |
| 790 | return; |
| 791 | else { |
| 792 | /* |
| 793 | * Otherwise try to find a suitable thread. |
| 794 | */ |
| 795 | t = signal->curr_target; |
| 796 | while (!wants_signal(sig, t)) { |
| 797 | t = next_thread(t); |
| 798 | if (t == signal->curr_target) |
| 799 | /* |
| 800 | * No thread needs to be woken. |
| 801 | * Any eligible threads will see |
| 802 | * the signal in the queue soon. |
| 803 | */ |
| 804 | return; |
| 805 | } |
| 806 | signal->curr_target = t; |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Found a killable thread. If the signal will be fatal, |
| 811 | * then start taking the whole group down immediately. |
| 812 | */ |
Oleg Nesterov | fae5fa4 | 2008-04-30 00:53:03 -0700 | [diff] [blame] | 813 | if (sig_fatal(p, sig) && |
| 814 | !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) && |
Oleg Nesterov | 71f11dc | 2008-04-30 00:52:53 -0700 | [diff] [blame] | 815 | !sigismember(&t->real_blocked, sig) && |
Roland McGrath | 445a91d | 2008-07-25 19:45:52 -0700 | [diff] [blame] | 816 | (sig == SIGKILL || |
Oleg Nesterov | 43918f2 | 2009-04-02 16:58:00 -0700 | [diff] [blame] | 817 | !tracehook_consider_fatal_signal(t, sig))) { |
Oleg Nesterov | 71f11dc | 2008-04-30 00:52:53 -0700 | [diff] [blame] | 818 | /* |
| 819 | * This signal will be fatal to the whole group. |
| 820 | */ |
| 821 | if (!sig_kernel_coredump(sig)) { |
| 822 | /* |
| 823 | * Start a group exit and wake everybody up. |
| 824 | * This way we don't have other threads |
| 825 | * running and doing things after a slower |
| 826 | * thread has the fatal signal pending. |
| 827 | */ |
| 828 | signal->flags = SIGNAL_GROUP_EXIT; |
| 829 | signal->group_exit_code = sig; |
| 830 | signal->group_stop_count = 0; |
| 831 | t = p; |
| 832 | do { |
| 833 | sigaddset(&t->pending.signal, SIGKILL); |
| 834 | signal_wake_up(t, 1); |
| 835 | } while_each_thread(p, t); |
| 836 | return; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | /* |
| 841 | * The signal is already in the shared-pending queue. |
| 842 | * Tell the chosen thread to wake up and dequeue it. |
| 843 | */ |
| 844 | signal_wake_up(t, sig == SIGKILL); |
| 845 | return; |
| 846 | } |
| 847 | |
Pavel Emelyanov | af7fff9 | 2008-04-30 00:52:34 -0700 | [diff] [blame] | 848 | static inline int legacy_queue(struct sigpending *signals, int sig) |
| 849 | { |
| 850 | return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); |
| 851 | } |
| 852 | |
Sukadev Bhattiprolu | 7978b56 | 2009-04-02 16:58:04 -0700 | [diff] [blame] | 853 | static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, |
| 854 | int group, int from_ancestor_ns) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 856 | struct sigpending *pending; |
Oleg Nesterov | 6e65acb | 2008-04-30 00:52:50 -0700 | [diff] [blame] | 857 | struct sigqueue *q; |
Vegard Nossum | 7a0aeb1 | 2009-05-16 11:28:33 +0200 | [diff] [blame] | 858 | int override_rlimit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Masami Hiramatsu | d1eb650 | 2009-11-24 16:56:45 -0500 | [diff] [blame] | 860 | trace_signal_generate(sig, info, t); |
Mathieu Desnoyers | 0a16b60 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 861 | |
Oleg Nesterov | 6e65acb | 2008-04-30 00:52:50 -0700 | [diff] [blame] | 862 | assert_spin_locked(&t->sighand->siglock); |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 863 | |
| 864 | if (!prepare_signal(sig, t, from_ancestor_ns)) |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 865 | return 0; |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 866 | |
| 867 | pending = group ? &t->signal->shared_pending : &t->pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* |
Pavel Emelyanov | 2acb024 | 2008-04-30 00:52:35 -0700 | [diff] [blame] | 869 | * Short-circuit ignored signals and support queuing |
| 870 | * exactly one non-rt signal, so that we can get more |
| 871 | * detailed information about the cause of the signal. |
| 872 | */ |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 873 | if (legacy_queue(pending, sig)) |
Pavel Emelyanov | 2acb024 | 2008-04-30 00:52:35 -0700 | [diff] [blame] | 874 | return 0; |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 875 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | * fast-pathed signals for kernel-internal things like SIGSTOP |
| 877 | * or SIGKILL. |
| 878 | */ |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 879 | if (info == SEND_SIG_FORCED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | goto out_set; |
| 881 | |
| 882 | /* Real-time signals must be queued if sent by sigqueue, or |
| 883 | some other real-time mechanism. It is implementation |
| 884 | defined whether kill() does so. We attempt to do so, on |
| 885 | the principle of least surprise, but since kill is not |
| 886 | allowed to fail with EAGAIN when low on memory we just |
| 887 | make sure at least one signal gets delivered and don't |
| 888 | pass on the info struct. */ |
| 889 | |
Vegard Nossum | 7a0aeb1 | 2009-05-16 11:28:33 +0200 | [diff] [blame] | 890 | if (sig < SIGRTMIN) |
| 891 | override_rlimit = (is_si_special(info) || info->si_code >= 0); |
| 892 | else |
| 893 | override_rlimit = 0; |
| 894 | |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 895 | q = __sigqueue_alloc(sig, t, GFP_ATOMIC | __GFP_NOTRACK_FALSE_POSITIVE, |
Vegard Nossum | 7a0aeb1 | 2009-05-16 11:28:33 +0200 | [diff] [blame] | 896 | override_rlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | if (q) { |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 898 | list_add_tail(&q->list, &pending->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | switch ((unsigned long) info) { |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 900 | case (unsigned long) SEND_SIG_NOINFO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | q->info.si_signo = sig; |
| 902 | q->info.si_errno = 0; |
| 903 | q->info.si_code = SI_USER; |
Sukadev Bhattiprolu | 9cd4fd1 | 2009-01-06 14:42:46 -0800 | [diff] [blame] | 904 | q->info.si_pid = task_tgid_nr_ns(current, |
Sukadev Bhattiprolu | 09bca05 | 2009-01-06 14:42:45 -0800 | [diff] [blame] | 905 | task_active_pid_ns(t)); |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 906 | q->info.si_uid = current_uid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | break; |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 908 | case (unsigned long) SEND_SIG_PRIV: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | q->info.si_signo = sig; |
| 910 | q->info.si_errno = 0; |
| 911 | q->info.si_code = SI_KERNEL; |
| 912 | q->info.si_pid = 0; |
| 913 | q->info.si_uid = 0; |
| 914 | break; |
| 915 | default: |
| 916 | copy_siginfo(&q->info, info); |
Sukadev Bhattiprolu | 6588c1e | 2009-04-02 16:58:09 -0700 | [diff] [blame] | 917 | if (from_ancestor_ns) |
| 918 | q->info.si_pid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | break; |
| 920 | } |
Oleg Nesterov | 621d312 | 2005-10-30 15:03:45 -0800 | [diff] [blame] | 921 | } else if (!is_si_special(info)) { |
Masami Hiramatsu | ba005e1 | 2009-11-24 16:56:58 -0500 | [diff] [blame] | 922 | if (sig >= SIGRTMIN && info->si_code != SI_USER) { |
| 923 | /* |
| 924 | * Queue overflow, abort. We may abort if the |
| 925 | * signal was rt and sent by user using something |
| 926 | * other than kill(). |
| 927 | */ |
| 928 | trace_signal_overflow_fail(sig, group, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | return -EAGAIN; |
Masami Hiramatsu | ba005e1 | 2009-11-24 16:56:58 -0500 | [diff] [blame] | 930 | } else { |
| 931 | /* |
| 932 | * This is a silent loss of information. We still |
| 933 | * send the signal, but the *info bits are lost. |
| 934 | */ |
| 935 | trace_signal_lose_info(sig, group, info); |
| 936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | out_set: |
Oleg Nesterov | 53c3033 | 2008-04-30 00:53:00 -0700 | [diff] [blame] | 940 | signalfd_notify(t, sig); |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 941 | sigaddset(&pending->signal, sig); |
Pavel Emelyanov | 4cd4b6d | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 942 | complete_signal(sig, t, group); |
| 943 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Sukadev Bhattiprolu | 7978b56 | 2009-04-02 16:58:04 -0700 | [diff] [blame] | 946 | static int send_signal(int sig, struct siginfo *info, struct task_struct *t, |
| 947 | int group) |
| 948 | { |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 949 | int from_ancestor_ns = 0; |
| 950 | |
| 951 | #ifdef CONFIG_PID_NS |
| 952 | if (!is_si_special(info) && SI_FROMUSER(info) && |
| 953 | task_pid_nr_ns(current, task_active_pid_ns(t)) <= 0) |
| 954 | from_ancestor_ns = 1; |
| 955 | #endif |
| 956 | |
| 957 | return __send_signal(sig, info, t, group, from_ancestor_ns); |
Sukadev Bhattiprolu | 7978b56 | 2009-04-02 16:58:04 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 960 | static void print_fatal_signal(struct pt_regs *regs, int signr) |
| 961 | { |
| 962 | printk("%s/%d: potentially unexpected fatal signal %d.\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 963 | current->comm, task_pid_nr(current), signr); |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 964 | |
Al Viro | ca5cd87 | 2007-10-29 04:31:16 +0000 | [diff] [blame] | 965 | #if defined(__i386__) && !defined(__arch_um__) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 966 | printk("code at %08lx: ", regs->ip); |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 967 | { |
| 968 | int i; |
| 969 | for (i = 0; i < 16; i++) { |
| 970 | unsigned char insn; |
| 971 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 972 | __get_user(insn, (unsigned char *)(regs->ip + i)); |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 973 | printk("%02x ", insn); |
| 974 | } |
| 975 | } |
| 976 | #endif |
| 977 | printk("\n"); |
Ed Swierk | 3a9f84d | 2009-01-26 15:33:31 -0800 | [diff] [blame] | 978 | preempt_disable(); |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 979 | show_regs(regs); |
Ed Swierk | 3a9f84d | 2009-01-26 15:33:31 -0800 | [diff] [blame] | 980 | preempt_enable(); |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | static int __init setup_print_fatal_signals(char *str) |
| 984 | { |
| 985 | get_option (&str, &print_fatal_signals); |
| 986 | |
| 987 | return 1; |
| 988 | } |
| 989 | |
| 990 | __setup("print-fatal-signals=", setup_print_fatal_signals); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Pavel Emelyanov | 4cd4b6d | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 992 | int |
| 993 | __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
| 994 | { |
| 995 | return send_signal(sig, info, p, 1); |
| 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | static int |
| 999 | specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t) |
| 1000 | { |
Pavel Emelyanov | 4cd4b6d | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 1001 | return send_signal(sig, info, t, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 1004 | int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, |
| 1005 | bool group) |
| 1006 | { |
| 1007 | unsigned long flags; |
| 1008 | int ret = -ESRCH; |
| 1009 | |
| 1010 | if (lock_task_sighand(p, &flags)) { |
| 1011 | ret = send_signal(sig, info, p, group); |
| 1012 | unlock_task_sighand(p, &flags); |
| 1013 | } |
| 1014 | |
| 1015 | return ret; |
| 1016 | } |
| 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | /* |
| 1019 | * Force a signal that the process can't ignore: if necessary |
| 1020 | * we unblock the signal and change any SIG_IGN to SIG_DFL. |
Linus Torvalds | ae74c3b | 2006-08-02 20:17:49 -0700 | [diff] [blame] | 1021 | * |
| 1022 | * Note: If we unblock the signal, we always reset it to SIG_DFL, |
| 1023 | * since we do not want to have a signal handler that was blocked |
| 1024 | * be invoked when user space had explicitly blocked it. |
| 1025 | * |
Oleg Nesterov | 80fe728 | 2008-04-30 00:53:05 -0700 | [diff] [blame] | 1026 | * We don't want to have recursive SIGSEGV's etc, for example, |
| 1027 | * that is why we also clear SIGNAL_UNKILLABLE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | int |
| 1030 | force_sig_info(int sig, struct siginfo *info, struct task_struct *t) |
| 1031 | { |
| 1032 | unsigned long int flags; |
Linus Torvalds | ae74c3b | 2006-08-02 20:17:49 -0700 | [diff] [blame] | 1033 | int ret, blocked, ignored; |
| 1034 | struct k_sigaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | spin_lock_irqsave(&t->sighand->siglock, flags); |
Linus Torvalds | ae74c3b | 2006-08-02 20:17:49 -0700 | [diff] [blame] | 1037 | action = &t->sighand->action[sig-1]; |
| 1038 | ignored = action->sa.sa_handler == SIG_IGN; |
| 1039 | blocked = sigismember(&t->blocked, sig); |
| 1040 | if (blocked || ignored) { |
| 1041 | action->sa.sa_handler = SIG_DFL; |
| 1042 | if (blocked) { |
| 1043 | sigdelset(&t->blocked, sig); |
Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 1044 | recalc_sigpending_and_wake(t); |
Linus Torvalds | ae74c3b | 2006-08-02 20:17:49 -0700 | [diff] [blame] | 1045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
Oleg Nesterov | 80fe728 | 2008-04-30 00:53:05 -0700 | [diff] [blame] | 1047 | if (action->sa.sa_handler == SIG_DFL) |
| 1048 | t->signal->flags &= ~SIGNAL_UNKILLABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | ret = specific_send_sig_info(sig, info, t); |
| 1050 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
| 1051 | |
| 1052 | return ret; |
| 1053 | } |
| 1054 | |
| 1055 | void |
| 1056 | force_sig_specific(int sig, struct task_struct *t) |
| 1057 | { |
Paul E. McKenney | b0423a0 | 2005-10-30 15:03:46 -0800 | [diff] [blame] | 1058 | force_sig_info(sig, SEND_SIG_FORCED, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | /* |
| 1062 | * Nuke all other threads in the group. |
| 1063 | */ |
| 1064 | void zap_other_threads(struct task_struct *p) |
| 1065 | { |
| 1066 | struct task_struct *t; |
| 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | p->signal->group_stop_count = 0; |
| 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | for (t = next_thread(p); t != p; t = next_thread(t)) { |
| 1071 | /* |
| 1072 | * Don't bother with already dead threads |
| 1073 | */ |
| 1074 | if (t->exit_state) |
| 1075 | continue; |
| 1076 | |
Andrea Arcangeli | 30e0fca6 | 2005-10-30 15:02:38 -0800 | [diff] [blame] | 1077 | /* SIGKILL will be handled before any pending SIGSTOP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | sigaddset(&t->pending.signal, SIGKILL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | signal_wake_up(t, 1); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Oleg Nesterov | f63ee72 | 2006-03-28 16:11:13 -0800 | [diff] [blame] | 1083 | struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags) |
| 1084 | { |
| 1085 | struct sighand_struct *sighand; |
| 1086 | |
Oleg Nesterov | 1406f2d | 2008-04-30 00:52:37 -0700 | [diff] [blame] | 1087 | rcu_read_lock(); |
Oleg Nesterov | f63ee72 | 2006-03-28 16:11:13 -0800 | [diff] [blame] | 1088 | for (;;) { |
| 1089 | sighand = rcu_dereference(tsk->sighand); |
| 1090 | if (unlikely(sighand == NULL)) |
| 1091 | break; |
| 1092 | |
| 1093 | spin_lock_irqsave(&sighand->siglock, *flags); |
| 1094 | if (likely(sighand == tsk->sighand)) |
| 1095 | break; |
| 1096 | spin_unlock_irqrestore(&sighand->siglock, *flags); |
| 1097 | } |
Oleg Nesterov | 1406f2d | 2008-04-30 00:52:37 -0700 | [diff] [blame] | 1098 | rcu_read_unlock(); |
Oleg Nesterov | f63ee72 | 2006-03-28 16:11:13 -0800 | [diff] [blame] | 1099 | |
| 1100 | return sighand; |
| 1101 | } |
| 1102 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1103 | /* |
| 1104 | * send signal info to all the members of a group |
| 1105 | * - the caller must hold the RCU read lock at least |
| 1106 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
| 1108 | { |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 1109 | int ret = check_kill_permission(sig, info, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 1111 | if (!ret && sig) |
| 1112 | ret = do_send_sig_info(sig, info, p, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
| 1117 | /* |
Pavel Emelyanov | 146a505 | 2008-02-08 04:19:22 -0800 | [diff] [blame] | 1118 | * __kill_pgrp_info() sends a signal to a process group: this is what the tty |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | * control characters do (^C, ^Z etc) |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1120 | * - the caller must hold at least a readlock on tasklist_lock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | */ |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1122 | int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
| 1124 | struct task_struct *p = NULL; |
| 1125 | int retval, success; |
| 1126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | success = 0; |
| 1128 | retval = -ESRCH; |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1129 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | int err = group_send_sig_info(sig, info, p); |
| 1131 | success |= !err; |
| 1132 | retval = err; |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1133 | } while_each_pid_task(pgrp, PIDTYPE_PGID, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | return success ? 0 : retval; |
| 1135 | } |
| 1136 | |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1137 | int kill_pid_info(int sig, struct siginfo *info, struct pid *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
Oleg Nesterov | d36174b | 2008-02-08 04:19:18 -0800 | [diff] [blame] | 1139 | int error = -ESRCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | struct task_struct *p; |
| 1141 | |
Ingo Molnar | e56d090 | 2006-01-08 01:01:37 -0800 | [diff] [blame] | 1142 | rcu_read_lock(); |
Oleg Nesterov | d36174b | 2008-02-08 04:19:18 -0800 | [diff] [blame] | 1143 | retry: |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1144 | p = pid_task(pid, PIDTYPE_PID); |
Oleg Nesterov | d36174b | 2008-02-08 04:19:18 -0800 | [diff] [blame] | 1145 | if (p) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | error = group_send_sig_info(sig, info, p); |
Oleg Nesterov | d36174b | 2008-02-08 04:19:18 -0800 | [diff] [blame] | 1147 | if (unlikely(error == -ESRCH)) |
| 1148 | /* |
| 1149 | * The task was unhashed in between, try again. |
| 1150 | * If it is dead, pid_task() will return NULL, |
| 1151 | * if we race with de_thread() it will find the |
| 1152 | * new leader. |
| 1153 | */ |
| 1154 | goto retry; |
| 1155 | } |
Ingo Molnar | e56d090 | 2006-01-08 01:01:37 -0800 | [diff] [blame] | 1156 | rcu_read_unlock(); |
Oleg Nesterov | 6ca25b5 | 2008-04-30 00:52:45 -0700 | [diff] [blame] | 1157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | return error; |
| 1159 | } |
| 1160 | |
Matthew Wilcox | c3de4b3 | 2007-02-09 08:11:47 -0700 | [diff] [blame] | 1161 | int |
| 1162 | kill_proc_info(int sig, struct siginfo *info, pid_t pid) |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1163 | { |
| 1164 | int error; |
| 1165 | rcu_read_lock(); |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1166 | error = kill_pid_info(sig, info, find_vpid(pid)); |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1167 | rcu_read_unlock(); |
| 1168 | return error; |
| 1169 | } |
| 1170 | |
Eric W. Biederman | 2425c08 | 2006-10-02 02:17:28 -0700 | [diff] [blame] | 1171 | /* like kill_pid_info(), but doesn't use uid/euid of "current" */ |
| 1172 | int kill_pid_info_as_uid(int sig, struct siginfo *info, struct pid *pid, |
David Quigley | 8f95dc5 | 2006-06-30 01:55:47 -0700 | [diff] [blame] | 1173 | uid_t uid, uid_t euid, u32 secid) |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1174 | { |
| 1175 | int ret = -EINVAL; |
| 1176 | struct task_struct *p; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1177 | const struct cred *pcred; |
Thomas Gleixner | 14d8c9f | 2009-12-10 00:53:17 +0000 | [diff] [blame] | 1178 | unsigned long flags; |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1179 | |
| 1180 | if (!valid_signal(sig)) |
| 1181 | return ret; |
| 1182 | |
Thomas Gleixner | 14d8c9f | 2009-12-10 00:53:17 +0000 | [diff] [blame] | 1183 | rcu_read_lock(); |
Eric W. Biederman | 2425c08 | 2006-10-02 02:17:28 -0700 | [diff] [blame] | 1184 | p = pid_task(pid, PIDTYPE_PID); |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1185 | if (!p) { |
| 1186 | ret = -ESRCH; |
| 1187 | goto out_unlock; |
| 1188 | } |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1189 | pcred = __task_cred(p); |
| 1190 | if ((info == SEND_SIG_NOINFO || |
| 1191 | (!is_si_special(info) && SI_FROMUSER(info))) && |
| 1192 | euid != pcred->suid && euid != pcred->uid && |
| 1193 | uid != pcred->suid && uid != pcred->uid) { |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1194 | ret = -EPERM; |
| 1195 | goto out_unlock; |
| 1196 | } |
David Quigley | 8f95dc5 | 2006-06-30 01:55:47 -0700 | [diff] [blame] | 1197 | ret = security_task_kill(p, info, sig, secid); |
| 1198 | if (ret) |
| 1199 | goto out_unlock; |
Thomas Gleixner | 14d8c9f | 2009-12-10 00:53:17 +0000 | [diff] [blame] | 1200 | |
| 1201 | if (sig) { |
| 1202 | if (lock_task_sighand(p, &flags)) { |
| 1203 | ret = __send_signal(sig, info, p, 1, 0); |
| 1204 | unlock_task_sighand(p, &flags); |
| 1205 | } else |
| 1206 | ret = -ESRCH; |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1207 | } |
| 1208 | out_unlock: |
Thomas Gleixner | 14d8c9f | 2009-12-10 00:53:17 +0000 | [diff] [blame] | 1209 | rcu_read_unlock(); |
Harald Welte | 4611383 | 2005-10-10 19:44:29 +0200 | [diff] [blame] | 1210 | return ret; |
| 1211 | } |
Eric W. Biederman | 2425c08 | 2006-10-02 02:17:28 -0700 | [diff] [blame] | 1212 | EXPORT_SYMBOL_GPL(kill_pid_info_as_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | /* |
| 1215 | * kill_something_info() interprets pid in interesting ways just like kill(2). |
| 1216 | * |
| 1217 | * POSIX specifies that kill(-1,sig) is unspecified, but what we have |
| 1218 | * is probably wrong. Should make it like BSD or SYSV. |
| 1219 | */ |
| 1220 | |
Gustavo Fernando Padovan | bc64efd | 2008-07-25 01:47:33 -0700 | [diff] [blame] | 1221 | static int kill_something_info(int sig, struct siginfo *info, pid_t pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | { |
Eric W. Biederman | 8d42db18 | 2007-02-12 00:52:55 -0800 | [diff] [blame] | 1223 | int ret; |
Pavel Emelyanov | d5df763 | 2008-02-08 04:19:22 -0800 | [diff] [blame] | 1224 | |
| 1225 | if (pid > 0) { |
| 1226 | rcu_read_lock(); |
| 1227 | ret = kill_pid_info(sig, info, find_vpid(pid)); |
| 1228 | rcu_read_unlock(); |
| 1229 | return ret; |
| 1230 | } |
| 1231 | |
| 1232 | read_lock(&tasklist_lock); |
| 1233 | if (pid != -1) { |
| 1234 | ret = __kill_pgrp_info(sig, info, |
| 1235 | pid ? find_vpid(-pid) : task_pgrp(current)); |
| 1236 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | int retval = 0, count = 0; |
| 1238 | struct task_struct * p; |
| 1239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | for_each_process(p) { |
Sukadev Bhattiprolu | d25141a | 2008-10-29 14:01:11 -0700 | [diff] [blame] | 1241 | if (task_pid_vnr(p) > 1 && |
| 1242 | !same_thread_group(p, current)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | int err = group_send_sig_info(sig, info, p); |
| 1244 | ++count; |
| 1245 | if (err != -EPERM) |
| 1246 | retval = err; |
| 1247 | } |
| 1248 | } |
Eric W. Biederman | 8d42db18 | 2007-02-12 00:52:55 -0800 | [diff] [blame] | 1249 | ret = count ? retval : -ESRCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
Pavel Emelyanov | d5df763 | 2008-02-08 04:19:22 -0800 | [diff] [blame] | 1251 | read_unlock(&tasklist_lock); |
| 1252 | |
Eric W. Biederman | 8d42db18 | 2007-02-12 00:52:55 -0800 | [diff] [blame] | 1253 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | /* |
| 1257 | * These are for backward compatibility with the rest of the kernel source. |
| 1258 | */ |
| 1259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | int |
| 1261 | send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
| 1262 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | /* |
| 1264 | * Make sure legacy kernel users don't send in bad values |
| 1265 | * (normal paths check this in check_kill_permission). |
| 1266 | */ |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 1267 | if (!valid_signal(sig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return -EINVAL; |
| 1269 | |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 1270 | return do_send_sig_info(sig, info, p, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 1273 | #define __si_special(priv) \ |
| 1274 | ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO) |
| 1275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | int |
| 1277 | send_sig(int sig, struct task_struct *p, int priv) |
| 1278 | { |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 1279 | return send_sig_info(sig, __si_special(priv), p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | void |
| 1283 | force_sig(int sig, struct task_struct *p) |
| 1284 | { |
Oleg Nesterov | b67a1b9 | 2005-10-30 15:03:44 -0800 | [diff] [blame] | 1285 | force_sig_info(sig, SEND_SIG_PRIV, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * When things go south during signal handling, we |
| 1290 | * will force a SIGSEGV. And if the signal that caused |
| 1291 | * the problem was already a SIGSEGV, we'll want to |
| 1292 | * make sure we don't even try to deliver the signal.. |
| 1293 | */ |
| 1294 | int |
| 1295 | force_sigsegv(int sig, struct task_struct *p) |
| 1296 | { |
| 1297 | if (sig == SIGSEGV) { |
| 1298 | unsigned long flags; |
| 1299 | spin_lock_irqsave(&p->sighand->siglock, flags); |
| 1300 | p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL; |
| 1301 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
| 1302 | } |
| 1303 | force_sig(SIGSEGV, p); |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1307 | int kill_pgrp(struct pid *pid, int sig, int priv) |
| 1308 | { |
Pavel Emelyanov | 146a505 | 2008-02-08 04:19:22 -0800 | [diff] [blame] | 1309 | int ret; |
| 1310 | |
| 1311 | read_lock(&tasklist_lock); |
| 1312 | ret = __kill_pgrp_info(sig, __si_special(priv), pid); |
| 1313 | read_unlock(&tasklist_lock); |
| 1314 | |
| 1315 | return ret; |
Eric W. Biederman | c4b92fc | 2006-10-02 02:17:10 -0700 | [diff] [blame] | 1316 | } |
| 1317 | EXPORT_SYMBOL(kill_pgrp); |
| 1318 | |
| 1319 | int kill_pid(struct pid *pid, int sig, int priv) |
| 1320 | { |
| 1321 | return kill_pid_info(sig, __si_special(priv), pid); |
| 1322 | } |
| 1323 | EXPORT_SYMBOL(kill_pid); |
| 1324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | /* |
| 1326 | * These functions support sending signals using preallocated sigqueue |
| 1327 | * structures. This is needed "because realtime applications cannot |
| 1328 | * afford to lose notifications of asynchronous events, like timer |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 1329 | * expirations or I/O completions". In the case of Posix Timers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | * we allocate the sigqueue structure from the timer_create. If this |
| 1331 | * allocation fails we are able to report the failure to the application |
| 1332 | * with an EAGAIN error. |
| 1333 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | struct sigqueue *sigqueue_alloc(void) |
| 1335 | { |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 1336 | struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 1338 | if (q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | q->flags |= SIGQUEUE_PREALLOC; |
Naohiro Ooiwa | f84d49b | 2009-11-09 00:46:42 +0900 | [diff] [blame] | 1340 | |
| 1341 | return q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | void sigqueue_free(struct sigqueue *q) |
| 1345 | { |
| 1346 | unsigned long flags; |
Oleg Nesterov | 60187d2 | 2007-08-30 23:56:35 -0700 | [diff] [blame] | 1347 | spinlock_t *lock = ¤t->sighand->siglock; |
| 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); |
| 1350 | /* |
Oleg Nesterov | c8e85b4f | 2008-05-26 20:55:42 +0400 | [diff] [blame] | 1351 | * We must hold ->siglock while testing q->list |
| 1352 | * to serialize with collect_signal() or with |
Oleg Nesterov | da7978b | 2008-05-23 13:04:41 -0700 | [diff] [blame] | 1353 | * __exit_signal()->flush_sigqueue(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | */ |
Oleg Nesterov | 60187d2 | 2007-08-30 23:56:35 -0700 | [diff] [blame] | 1355 | spin_lock_irqsave(lock, flags); |
Oleg Nesterov | c8e85b4f | 2008-05-26 20:55:42 +0400 | [diff] [blame] | 1356 | q->flags &= ~SIGQUEUE_PREALLOC; |
| 1357 | /* |
| 1358 | * If it is queued it will be freed when dequeued, |
| 1359 | * like the "regular" sigqueue. |
| 1360 | */ |
Oleg Nesterov | 60187d2 | 2007-08-30 23:56:35 -0700 | [diff] [blame] | 1361 | if (!list_empty(&q->list)) |
Oleg Nesterov | c8e85b4f | 2008-05-26 20:55:42 +0400 | [diff] [blame] | 1362 | q = NULL; |
Oleg Nesterov | 60187d2 | 2007-08-30 23:56:35 -0700 | [diff] [blame] | 1363 | spin_unlock_irqrestore(lock, flags); |
| 1364 | |
Oleg Nesterov | c8e85b4f | 2008-05-26 20:55:42 +0400 | [diff] [blame] | 1365 | if (q) |
| 1366 | __sigqueue_free(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Oleg Nesterov | ac5c215 | 2008-04-30 00:52:57 -0700 | [diff] [blame] | 1369 | int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1370 | { |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1371 | int sig = q->info.si_signo; |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 1372 | struct sigpending *pending; |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1373 | unsigned long flags; |
| 1374 | int ret; |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 1375 | |
Pavel Emelyanov | 4cd4b6d | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 1376 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1377 | |
| 1378 | ret = -1; |
| 1379 | if (!likely(lock_task_sighand(t, &flags))) |
| 1380 | goto ret; |
| 1381 | |
Oleg Nesterov | 7e695a5 | 2008-04-30 00:52:59 -0700 | [diff] [blame] | 1382 | ret = 1; /* the signal is ignored */ |
Sukadev Bhattiprolu | 921cf9f | 2009-04-02 16:58:05 -0700 | [diff] [blame] | 1383 | if (!prepare_signal(sig, t, 0)) |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1384 | goto out; |
| 1385 | |
| 1386 | ret = 0; |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1387 | if (unlikely(!list_empty(&q->list))) { |
| 1388 | /* |
| 1389 | * If an SI_TIMER entry is already queue just increment |
| 1390 | * the overrun count. |
| 1391 | */ |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1392 | BUG_ON(q->info.si_code != SI_TIMER); |
| 1393 | q->info.si_overrun++; |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1394 | goto out; |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1395 | } |
Oleg Nesterov | ba66129 | 2008-07-23 20:52:05 +0400 | [diff] [blame] | 1396 | q->info.si_overrun = 0; |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1397 | |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1398 | signalfd_notify(t, sig); |
Oleg Nesterov | 2ca3515 | 2008-04-30 00:52:54 -0700 | [diff] [blame] | 1399 | pending = group ? &t->signal->shared_pending : &t->pending; |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1400 | list_add_tail(&q->list, &pending->list); |
| 1401 | sigaddset(&pending->signal, sig); |
Pavel Emelyanov | 4cd4b6d | 2008-04-30 00:52:55 -0700 | [diff] [blame] | 1402 | complete_signal(sig, t, group); |
Oleg Nesterov | e62e665 | 2008-04-30 00:52:56 -0700 | [diff] [blame] | 1403 | out: |
| 1404 | unlock_task_sighand(t, &flags); |
| 1405 | ret: |
| 1406 | return ret; |
Pavel Emelyanov | 9e3bd6c | 2008-04-30 00:52:41 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | * Let a parent know about the death of a child. |
| 1411 | * For a stopped/continued status change, use do_notify_parent_cldstop instead. |
Roland McGrath | 2b2a1ff | 2008-07-25 19:45:54 -0700 | [diff] [blame] | 1412 | * |
| 1413 | * Returns -1 if our parent ignored us and so we've switched to |
| 1414 | * self-reaping, or else @sig. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | */ |
Roland McGrath | 2b2a1ff | 2008-07-25 19:45:54 -0700 | [diff] [blame] | 1416 | int do_notify_parent(struct task_struct *tsk, int sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
| 1418 | struct siginfo info; |
| 1419 | unsigned long flags; |
| 1420 | struct sighand_struct *psig; |
Roland McGrath | 1b04624 | 2008-08-19 20:37:07 -0700 | [diff] [blame] | 1421 | int ret = sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
| 1423 | BUG_ON(sig == -1); |
| 1424 | |
| 1425 | /* do_notify_parent_cldstop should have been called instead. */ |
Matthew Wilcox | e1abb39 | 2007-12-06 11:07:35 -0500 | [diff] [blame] | 1426 | BUG_ON(task_is_stopped_or_traced(tsk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
Oleg Nesterov | 5cb1144 | 2009-06-17 16:27:30 -0700 | [diff] [blame] | 1428 | BUG_ON(!task_ptrace(tsk) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | (tsk->group_leader != tsk || !thread_group_empty(tsk))); |
| 1430 | |
| 1431 | info.si_signo = sig; |
| 1432 | info.si_errno = 0; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1433 | /* |
| 1434 | * we are under tasklist_lock here so our parent is tied to |
| 1435 | * us and cannot exit and release its namespace. |
| 1436 | * |
| 1437 | * the only it can is to switch its nsproxy with sys_unshare, |
| 1438 | * bu uncharing pid namespaces is not allowed, so we'll always |
| 1439 | * see relevant namespace |
| 1440 | * |
| 1441 | * write_lock() currently calls preempt_disable() which is the |
| 1442 | * same as rcu_read_lock(), but according to Oleg, this is not |
| 1443 | * correct to rely on this |
| 1444 | */ |
| 1445 | rcu_read_lock(); |
| 1446 | info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1447 | info.si_uid = __task_cred(tsk)->uid; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1448 | rcu_read_unlock(); |
| 1449 | |
Peter Zijlstra | 32bd671 | 2009-02-05 12:24:15 +0100 | [diff] [blame] | 1450 | info.si_utime = cputime_to_clock_t(cputime_add(tsk->utime, |
| 1451 | tsk->signal->utime)); |
| 1452 | info.si_stime = cputime_to_clock_t(cputime_add(tsk->stime, |
| 1453 | tsk->signal->stime)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
| 1455 | info.si_status = tsk->exit_code & 0x7f; |
| 1456 | if (tsk->exit_code & 0x80) |
| 1457 | info.si_code = CLD_DUMPED; |
| 1458 | else if (tsk->exit_code & 0x7f) |
| 1459 | info.si_code = CLD_KILLED; |
| 1460 | else { |
| 1461 | info.si_code = CLD_EXITED; |
| 1462 | info.si_status = tsk->exit_code >> 8; |
| 1463 | } |
| 1464 | |
| 1465 | psig = tsk->parent->sighand; |
| 1466 | spin_lock_irqsave(&psig->siglock, flags); |
Oleg Nesterov | 5cb1144 | 2009-06-17 16:27:30 -0700 | [diff] [blame] | 1467 | if (!task_ptrace(tsk) && sig == SIGCHLD && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN || |
| 1469 | (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) { |
| 1470 | /* |
| 1471 | * We are exiting and our parent doesn't care. POSIX.1 |
| 1472 | * defines special semantics for setting SIGCHLD to SIG_IGN |
| 1473 | * or setting the SA_NOCLDWAIT flag: we should be reaped |
| 1474 | * automatically and not left for our parent's wait4 call. |
| 1475 | * Rather than having the parent do it as a magic kind of |
| 1476 | * signal handler, we just set this to tell do_exit that we |
| 1477 | * can be cleaned up without becoming a zombie. Note that |
| 1478 | * we still call __wake_up_parent in this case, because a |
| 1479 | * blocked sys_wait4 might now return -ECHILD. |
| 1480 | * |
| 1481 | * Whether we send SIGCHLD or not for SA_NOCLDWAIT |
| 1482 | * is implementation-defined: we do (if you don't want |
| 1483 | * it, just use SIG_IGN instead). |
| 1484 | */ |
Roland McGrath | 1b04624 | 2008-08-19 20:37:07 -0700 | [diff] [blame] | 1485 | ret = tsk->exit_signal = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) |
Roland McGrath | 2b2a1ff | 2008-07-25 19:45:54 -0700 | [diff] [blame] | 1487 | sig = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 1489 | if (valid_signal(sig) && sig > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | __group_send_sig_info(sig, &info, tsk->parent); |
| 1491 | __wake_up_parent(tsk, tsk->parent); |
| 1492 | spin_unlock_irqrestore(&psig->siglock, flags); |
Roland McGrath | 2b2a1ff | 2008-07-25 19:45:54 -0700 | [diff] [blame] | 1493 | |
Roland McGrath | 1b04624 | 2008-08-19 20:37:07 -0700 | [diff] [blame] | 1494 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Oleg Nesterov | a1d5e21 | 2006-03-28 16:11:29 -0800 | [diff] [blame] | 1497 | static void do_notify_parent_cldstop(struct task_struct *tsk, int why) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | { |
| 1499 | struct siginfo info; |
| 1500 | unsigned long flags; |
Oleg Nesterov | bc505a4 | 2005-09-06 15:17:32 -0700 | [diff] [blame] | 1501 | struct task_struct *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | struct sighand_struct *sighand; |
| 1503 | |
Oleg Nesterov | 5cb1144 | 2009-06-17 16:27:30 -0700 | [diff] [blame] | 1504 | if (task_ptrace(tsk)) |
Oleg Nesterov | bc505a4 | 2005-09-06 15:17:32 -0700 | [diff] [blame] | 1505 | parent = tsk->parent; |
| 1506 | else { |
| 1507 | tsk = tsk->group_leader; |
| 1508 | parent = tsk->real_parent; |
| 1509 | } |
| 1510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | info.si_signo = SIGCHLD; |
| 1512 | info.si_errno = 0; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1513 | /* |
| 1514 | * see comment in do_notify_parent() abot the following 3 lines |
| 1515 | */ |
| 1516 | rcu_read_lock(); |
Oleg Nesterov | d926566 | 2009-06-17 16:27:35 -0700 | [diff] [blame] | 1517 | info.si_pid = task_pid_nr_ns(tsk, parent->nsproxy->pid_ns); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1518 | info.si_uid = __task_cred(tsk)->uid; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1519 | rcu_read_unlock(); |
| 1520 | |
Michael Kerrisk | d8878ba | 2008-07-25 01:47:32 -0700 | [diff] [blame] | 1521 | info.si_utime = cputime_to_clock_t(tsk->utime); |
| 1522 | info.si_stime = cputime_to_clock_t(tsk->stime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
| 1524 | info.si_code = why; |
| 1525 | switch (why) { |
| 1526 | case CLD_CONTINUED: |
| 1527 | info.si_status = SIGCONT; |
| 1528 | break; |
| 1529 | case CLD_STOPPED: |
| 1530 | info.si_status = tsk->signal->group_exit_code & 0x7f; |
| 1531 | break; |
| 1532 | case CLD_TRAPPED: |
| 1533 | info.si_status = tsk->exit_code & 0x7f; |
| 1534 | break; |
| 1535 | default: |
| 1536 | BUG(); |
| 1537 | } |
| 1538 | |
| 1539 | sighand = parent->sighand; |
| 1540 | spin_lock_irqsave(&sighand->siglock, flags); |
| 1541 | if (sighand->action[SIGCHLD-1].sa.sa_handler != SIG_IGN && |
| 1542 | !(sighand->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP)) |
| 1543 | __group_send_sig_info(SIGCHLD, &info, parent); |
| 1544 | /* |
| 1545 | * Even if SIGCHLD is not generated, we must wake up wait4 calls. |
| 1546 | */ |
| 1547 | __wake_up_parent(tsk, parent); |
| 1548 | spin_unlock_irqrestore(&sighand->siglock, flags); |
| 1549 | } |
| 1550 | |
Oleg Nesterov | d5f70c0 | 2006-06-26 00:26:07 -0700 | [diff] [blame] | 1551 | static inline int may_ptrace_stop(void) |
| 1552 | { |
Oleg Nesterov | 5cb1144 | 2009-06-17 16:27:30 -0700 | [diff] [blame] | 1553 | if (!likely(task_ptrace(current))) |
Oleg Nesterov | d5f70c0 | 2006-06-26 00:26:07 -0700 | [diff] [blame] | 1554 | return 0; |
Oleg Nesterov | d5f70c0 | 2006-06-26 00:26:07 -0700 | [diff] [blame] | 1555 | /* |
| 1556 | * Are we in the middle of do_coredump? |
| 1557 | * If so and our tracer is also part of the coredump stopping |
| 1558 | * is a deadlock situation, and pointless because our tracer |
| 1559 | * is dead so don't allow us to stop. |
| 1560 | * If SIGKILL was already sent before the caller unlocked |
Oleg Nesterov | 999d9fc | 2008-07-25 01:47:41 -0700 | [diff] [blame] | 1561 | * ->siglock we must see ->core_state != NULL. Otherwise it |
Oleg Nesterov | d5f70c0 | 2006-06-26 00:26:07 -0700 | [diff] [blame] | 1562 | * is safe to enter schedule(). |
| 1563 | */ |
Oleg Nesterov | 999d9fc | 2008-07-25 01:47:41 -0700 | [diff] [blame] | 1564 | if (unlikely(current->mm->core_state) && |
Oleg Nesterov | d5f70c0 | 2006-06-26 00:26:07 -0700 | [diff] [blame] | 1565 | unlikely(current->mm == current->parent->mm)) |
| 1566 | return 0; |
| 1567 | |
| 1568 | return 1; |
| 1569 | } |
| 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | /* |
Roland McGrath | 1a669c2 | 2008-02-06 01:37:37 -0800 | [diff] [blame] | 1572 | * Return nonzero if there is a SIGKILL that should be waking us up. |
| 1573 | * Called with the siglock held. |
| 1574 | */ |
| 1575 | static int sigkill_pending(struct task_struct *tsk) |
| 1576 | { |
Oleg Nesterov | 3d749b9 | 2008-07-25 01:47:37 -0700 | [diff] [blame] | 1577 | return sigismember(&tsk->pending.signal, SIGKILL) || |
| 1578 | sigismember(&tsk->signal->shared_pending.signal, SIGKILL); |
Roland McGrath | 1a669c2 | 2008-02-06 01:37:37 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | * This must be called with current->sighand->siglock held. |
| 1583 | * |
| 1584 | * This should be the path for all ptrace stops. |
| 1585 | * We always set current->last_siginfo while stopped here. |
| 1586 | * That makes it a way to test a stopped process for |
| 1587 | * being ptrace-stopped vs being job-control-stopped. |
| 1588 | * |
Oleg Nesterov | 20686a3 | 2008-02-08 04:19:03 -0800 | [diff] [blame] | 1589 | * If we actually decide not to stop at all because the tracer |
| 1590 | * is gone, we keep current->exit_code unless clear_code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | */ |
Oleg Nesterov | 20686a3 | 2008-02-08 04:19:03 -0800 | [diff] [blame] | 1592 | static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | { |
Roland McGrath | 1a669c2 | 2008-02-06 01:37:37 -0800 | [diff] [blame] | 1594 | if (arch_ptrace_stop_needed(exit_code, info)) { |
| 1595 | /* |
| 1596 | * The arch code has something special to do before a |
| 1597 | * ptrace stop. This is allowed to block, e.g. for faults |
| 1598 | * on user stack pages. We can't keep the siglock while |
| 1599 | * calling arch_ptrace_stop, so we must release it now. |
| 1600 | * To preserve proper semantics, we must do this before |
| 1601 | * any signal bookkeeping like checking group_stop_count. |
| 1602 | * Meanwhile, a SIGKILL could come in before we retake the |
| 1603 | * siglock. That must prevent us from sleeping in TASK_TRACED. |
| 1604 | * So after regaining the lock, we must check for SIGKILL. |
| 1605 | */ |
| 1606 | spin_unlock_irq(¤t->sighand->siglock); |
| 1607 | arch_ptrace_stop(exit_code, info); |
| 1608 | spin_lock_irq(¤t->sighand->siglock); |
Oleg Nesterov | 3d749b9 | 2008-07-25 01:47:37 -0700 | [diff] [blame] | 1609 | if (sigkill_pending(current)) |
| 1610 | return; |
Roland McGrath | 1a669c2 | 2008-02-06 01:37:37 -0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | /* |
| 1614 | * If there is a group stop in progress, |
| 1615 | * we must participate in the bookkeeping. |
| 1616 | */ |
| 1617 | if (current->signal->group_stop_count > 0) |
| 1618 | --current->signal->group_stop_count; |
| 1619 | |
| 1620 | current->last_siginfo = info; |
| 1621 | current->exit_code = exit_code; |
| 1622 | |
| 1623 | /* Let the debugger run. */ |
Oleg Nesterov | d9ae90a | 2008-02-06 01:36:13 -0800 | [diff] [blame] | 1624 | __set_current_state(TASK_TRACED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | spin_unlock_irq(¤t->sighand->siglock); |
| 1626 | read_lock(&tasklist_lock); |
Oleg Nesterov | 3d749b9 | 2008-07-25 01:47:37 -0700 | [diff] [blame] | 1627 | if (may_ptrace_stop()) { |
Oleg Nesterov | a1d5e21 | 2006-03-28 16:11:29 -0800 | [diff] [blame] | 1628 | do_notify_parent_cldstop(current, CLD_TRAPPED); |
Miklos Szeredi | 53da1d9 | 2009-03-23 16:07:24 +0100 | [diff] [blame] | 1629 | /* |
| 1630 | * Don't want to allow preemption here, because |
| 1631 | * sys_ptrace() needs this task to be inactive. |
| 1632 | * |
| 1633 | * XXX: implement read_unlock_no_resched(). |
| 1634 | */ |
| 1635 | preempt_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | read_unlock(&tasklist_lock); |
Miklos Szeredi | 53da1d9 | 2009-03-23 16:07:24 +0100 | [diff] [blame] | 1637 | preempt_enable_no_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | schedule(); |
| 1639 | } else { |
| 1640 | /* |
| 1641 | * By the time we got the lock, our tracer went away. |
Oleg Nesterov | 6405f7f | 2008-02-08 04:19:00 -0800 | [diff] [blame] | 1642 | * Don't drop the lock yet, another tracer may come. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | */ |
Oleg Nesterov | 6405f7f | 2008-02-08 04:19:00 -0800 | [diff] [blame] | 1644 | __set_current_state(TASK_RUNNING); |
Oleg Nesterov | 20686a3 | 2008-02-08 04:19:03 -0800 | [diff] [blame] | 1645 | if (clear_code) |
| 1646 | current->exit_code = 0; |
Oleg Nesterov | 6405f7f | 2008-02-08 04:19:00 -0800 | [diff] [blame] | 1647 | read_unlock(&tasklist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /* |
Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 1651 | * While in TASK_TRACED, we were considered "frozen enough". |
| 1652 | * Now that we woke up, it's crucial if we're supposed to be |
| 1653 | * frozen that we freeze now before running anything substantial. |
| 1654 | */ |
| 1655 | try_to_freeze(); |
| 1656 | |
| 1657 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | * We are back. Now reacquire the siglock before touching |
| 1659 | * last_siginfo, so that we are sure to have synchronized with |
| 1660 | * any signal-sending on another CPU that wants to examine it. |
| 1661 | */ |
| 1662 | spin_lock_irq(¤t->sighand->siglock); |
| 1663 | current->last_siginfo = NULL; |
| 1664 | |
| 1665 | /* |
| 1666 | * Queued signals ignored us while we were stopped for tracing. |
| 1667 | * So check for any that we should take before resuming user mode. |
Roland McGrath | b74d0de | 2007-06-06 03:59:00 -0700 | [diff] [blame] | 1668 | * This sets TIF_SIGPENDING, but never clears it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | */ |
Roland McGrath | b74d0de | 2007-06-06 03:59:00 -0700 | [diff] [blame] | 1670 | recalc_sigpending_tsk(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | void ptrace_notify(int exit_code) |
| 1674 | { |
| 1675 | siginfo_t info; |
| 1676 | |
| 1677 | BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP); |
| 1678 | |
| 1679 | memset(&info, 0, sizeof info); |
| 1680 | info.si_signo = SIGTRAP; |
| 1681 | info.si_code = exit_code; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 1682 | info.si_pid = task_pid_vnr(current); |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 1683 | info.si_uid = current_uid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
| 1685 | /* Let the debugger run. */ |
| 1686 | spin_lock_irq(¤t->sighand->siglock); |
Oleg Nesterov | 20686a3 | 2008-02-08 04:19:03 -0800 | [diff] [blame] | 1687 | ptrace_stop(exit_code, 1, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | spin_unlock_irq(¤t->sighand->siglock); |
| 1689 | } |
| 1690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | /* |
| 1692 | * This performs the stopping for SIGSTOP and other stop signals. |
| 1693 | * We have to stop all threads in the thread group. |
| 1694 | * Returns nonzero if we've actually stopped and released the siglock. |
| 1695 | * Returns zero if we didn't stop and still hold the siglock. |
| 1696 | */ |
Oleg Nesterov | a122b34 | 2006-03-28 16:11:22 -0800 | [diff] [blame] | 1697 | static int do_signal_stop(int signr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | { |
| 1699 | struct signal_struct *sig = current->signal; |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1700 | int notify; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1702 | if (!sig->group_stop_count) { |
Oleg Nesterov | f558b7e | 2008-02-04 22:27:24 -0800 | [diff] [blame] | 1703 | struct task_struct *t; |
| 1704 | |
Oleg Nesterov | 2b201a9 | 2008-07-25 01:47:31 -0700 | [diff] [blame] | 1705 | if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || |
Oleg Nesterov | 573cf9a | 2008-04-30 00:52:36 -0700 | [diff] [blame] | 1706 | unlikely(signal_group_exit(sig))) |
Oleg Nesterov | f558b7e | 2008-02-04 22:27:24 -0800 | [diff] [blame] | 1707 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | * There is no group stop already in progress. |
Oleg Nesterov | a122b34 | 2006-03-28 16:11:22 -0800 | [diff] [blame] | 1710 | * We must initiate one now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | */ |
Oleg Nesterov | a122b34 | 2006-03-28 16:11:22 -0800 | [diff] [blame] | 1712 | sig->group_exit_code = signr; |
| 1713 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1714 | sig->group_stop_count = 1; |
Oleg Nesterov | a122b34 | 2006-03-28 16:11:22 -0800 | [diff] [blame] | 1715 | for (t = next_thread(current); t != current; t = next_thread(t)) |
| 1716 | /* |
| 1717 | * Setting state to TASK_STOPPED for a group |
| 1718 | * stop is always done with the siglock held, |
| 1719 | * so this check has no races. |
| 1720 | */ |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 1721 | if (!(t->flags & PF_EXITING) && |
Matthew Wilcox | e1abb39 | 2007-12-06 11:07:35 -0500 | [diff] [blame] | 1722 | !task_is_stopped_or_traced(t)) { |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1723 | sig->group_stop_count++; |
Oleg Nesterov | a122b34 | 2006-03-28 16:11:22 -0800 | [diff] [blame] | 1724 | signal_wake_up(t, 0); |
| 1725 | } |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1726 | } |
| 1727 | /* |
| 1728 | * If there are no other threads in the group, or if there is |
| 1729 | * a group stop in progress and we are the last to stop, report |
| 1730 | * to the parent. When ptraced, every thread reports itself. |
| 1731 | */ |
| 1732 | notify = sig->group_stop_count == 1 ? CLD_STOPPED : 0; |
| 1733 | notify = tracehook_notify_jctl(notify, CLD_STOPPED); |
| 1734 | /* |
| 1735 | * tracehook_notify_jctl() can drop and reacquire siglock, so |
| 1736 | * we keep ->group_stop_count != 0 before the call. If SIGCONT |
| 1737 | * or SIGKILL comes in between ->group_stop_count == 0. |
| 1738 | */ |
| 1739 | if (sig->group_stop_count) { |
| 1740 | if (!--sig->group_stop_count) |
| 1741 | sig->flags = SIGNAL_STOP_STOPPED; |
| 1742 | current->exit_code = sig->group_exit_code; |
| 1743 | __set_current_state(TASK_STOPPED); |
| 1744 | } |
| 1745 | spin_unlock_irq(¤t->sighand->siglock); |
| 1746 | |
| 1747 | if (notify) { |
| 1748 | read_lock(&tasklist_lock); |
| 1749 | do_notify_parent_cldstop(current, notify); |
| 1750 | read_unlock(&tasklist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1753 | /* Now we don't run again until woken by SIGCONT or SIGKILL */ |
| 1754 | do { |
| 1755 | schedule(); |
| 1756 | } while (try_to_freeze()); |
Oleg Nesterov | dac27f4 | 2006-03-28 16:11:28 -0800 | [diff] [blame] | 1757 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1758 | tracehook_finish_jctl(); |
| 1759 | current->exit_code = 0; |
| 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | return 1; |
| 1762 | } |
| 1763 | |
Roland McGrath | 18c98b6 | 2008-04-17 18:44:38 -0700 | [diff] [blame] | 1764 | static int ptrace_signal(int signr, siginfo_t *info, |
| 1765 | struct pt_regs *regs, void *cookie) |
| 1766 | { |
Oleg Nesterov | 5cb1144 | 2009-06-17 16:27:30 -0700 | [diff] [blame] | 1767 | if (!task_ptrace(current)) |
Roland McGrath | 18c98b6 | 2008-04-17 18:44:38 -0700 | [diff] [blame] | 1768 | return signr; |
| 1769 | |
| 1770 | ptrace_signal_deliver(regs, cookie); |
| 1771 | |
| 1772 | /* Let the debugger run. */ |
| 1773 | ptrace_stop(signr, 0, info); |
| 1774 | |
| 1775 | /* We're back. Did the debugger cancel the sig? */ |
| 1776 | signr = current->exit_code; |
| 1777 | if (signr == 0) |
| 1778 | return signr; |
| 1779 | |
| 1780 | current->exit_code = 0; |
| 1781 | |
| 1782 | /* Update the siginfo structure if the signal has |
| 1783 | changed. If the debugger wanted something |
| 1784 | specific in the siginfo structure then it should |
| 1785 | have updated *info via PTRACE_SETSIGINFO. */ |
| 1786 | if (signr != info->si_signo) { |
| 1787 | info->si_signo = signr; |
| 1788 | info->si_errno = 0; |
| 1789 | info->si_code = SI_USER; |
| 1790 | info->si_pid = task_pid_vnr(current->parent); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1791 | info->si_uid = task_uid(current->parent); |
Roland McGrath | 18c98b6 | 2008-04-17 18:44:38 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /* If the (new) signal is now blocked, requeue it. */ |
| 1795 | if (sigismember(¤t->blocked, signr)) { |
| 1796 | specific_send_sig_info(signr, info, current); |
| 1797 | signr = 0; |
| 1798 | } |
| 1799 | |
| 1800 | return signr; |
| 1801 | } |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, |
| 1804 | struct pt_regs *regs, void *cookie) |
| 1805 | { |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1806 | struct sighand_struct *sighand = current->sighand; |
| 1807 | struct signal_struct *signal = current->signal; |
| 1808 | int signr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 1810 | relock: |
| 1811 | /* |
| 1812 | * We'll jump back here after any time we were stopped in TASK_STOPPED. |
| 1813 | * While in TASK_STOPPED, we were considered "frozen enough". |
| 1814 | * Now that we woke up, it's crucial if we're supposed to be |
| 1815 | * frozen that we freeze now before running anything substantial. |
| 1816 | */ |
Rafael J. Wysocki | fc558a7 | 2006-03-23 03:00:05 -0800 | [diff] [blame] | 1817 | try_to_freeze(); |
| 1818 | |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1819 | spin_lock_irq(&sighand->siglock); |
Oleg Nesterov | 021e1ae | 2008-04-30 00:53:00 -0700 | [diff] [blame] | 1820 | /* |
| 1821 | * Every stopped thread goes here after wakeup. Check to see if |
| 1822 | * we should notify the parent, prepare_signal(SIGCONT) encodes |
| 1823 | * the CLD_ si_code into SIGNAL_CLD_MASK bits. |
| 1824 | */ |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1825 | if (unlikely(signal->flags & SIGNAL_CLD_MASK)) { |
| 1826 | int why = (signal->flags & SIGNAL_STOP_CONTINUED) |
Oleg Nesterov | e442055 | 2008-04-30 00:52:44 -0700 | [diff] [blame] | 1827 | ? CLD_CONTINUED : CLD_STOPPED; |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1828 | signal->flags &= ~SIGNAL_CLD_MASK; |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1829 | |
| 1830 | why = tracehook_notify_jctl(why, CLD_CONTINUED); |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1831 | spin_unlock_irq(&sighand->siglock); |
Oleg Nesterov | e442055 | 2008-04-30 00:52:44 -0700 | [diff] [blame] | 1832 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 1833 | if (why) { |
| 1834 | read_lock(&tasklist_lock); |
| 1835 | do_notify_parent_cldstop(current->group_leader, why); |
| 1836 | read_unlock(&tasklist_lock); |
| 1837 | } |
Oleg Nesterov | e442055 | 2008-04-30 00:52:44 -0700 | [diff] [blame] | 1838 | goto relock; |
| 1839 | } |
| 1840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | for (;;) { |
| 1842 | struct k_sigaction *ka; |
| 1843 | |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1844 | if (unlikely(signal->group_stop_count > 0) && |
Oleg Nesterov | f558b7e | 2008-02-04 22:27:24 -0800 | [diff] [blame] | 1845 | do_signal_stop(0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | goto relock; |
| 1847 | |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1848 | /* |
| 1849 | * Tracing can induce an artifical signal and choose sigaction. |
| 1850 | * The return value in @signr determines the default action, |
| 1851 | * but @info->si_signo is the signal number we will report. |
| 1852 | */ |
| 1853 | signr = tracehook_get_signal(current, regs, info, return_ka); |
| 1854 | if (unlikely(signr < 0)) |
| 1855 | goto relock; |
| 1856 | if (unlikely(signr != 0)) |
| 1857 | ka = return_ka; |
| 1858 | else { |
| 1859 | signr = dequeue_signal(current, ¤t->blocked, |
| 1860 | info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Roland McGrath | 18c98b6 | 2008-04-17 18:44:38 -0700 | [diff] [blame] | 1862 | if (!signr) |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1863 | break; /* will return 0 */ |
| 1864 | |
| 1865 | if (signr != SIGKILL) { |
| 1866 | signr = ptrace_signal(signr, info, |
| 1867 | regs, cookie); |
| 1868 | if (!signr) |
| 1869 | continue; |
| 1870 | } |
| 1871 | |
| 1872 | ka = &sighand->action[signr-1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Masami Hiramatsu | f9d4257 | 2009-11-24 16:56:51 -0500 | [diff] [blame] | 1875 | /* Trace actually delivered signals. */ |
| 1876 | trace_signal_deliver(signr, info, ka); |
| 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ |
| 1879 | continue; |
| 1880 | if (ka->sa.sa_handler != SIG_DFL) { |
| 1881 | /* Run the handler. */ |
| 1882 | *return_ka = *ka; |
| 1883 | |
| 1884 | if (ka->sa.sa_flags & SA_ONESHOT) |
| 1885 | ka->sa.sa_handler = SIG_DFL; |
| 1886 | |
| 1887 | break; /* will return non-zero "signr" value */ |
| 1888 | } |
| 1889 | |
| 1890 | /* |
| 1891 | * Now we are doing the default action for this signal. |
| 1892 | */ |
| 1893 | if (sig_kernel_ignore(signr)) /* Default is nothing. */ |
| 1894 | continue; |
| 1895 | |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 1896 | /* |
Sukadev Bhattiprolu | 0fbc26a | 2007-10-18 23:40:13 -0700 | [diff] [blame] | 1897 | * Global init gets no signals it doesn't want. |
Sukadev Bhattiprolu | b3bfa0c | 2009-04-02 16:58:08 -0700 | [diff] [blame] | 1898 | * Container-init gets no signals it doesn't want from same |
| 1899 | * container. |
| 1900 | * |
| 1901 | * Note that if global/container-init sees a sig_kernel_only() |
| 1902 | * signal here, the signal must have been generated internally |
| 1903 | * or must have come from an ancestor namespace. In either |
| 1904 | * case, the signal cannot be dropped. |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 1905 | */ |
Oleg Nesterov | fae5fa4 | 2008-04-30 00:53:03 -0700 | [diff] [blame] | 1906 | if (unlikely(signal->flags & SIGNAL_UNKILLABLE) && |
Sukadev Bhattiprolu | b3bfa0c | 2009-04-02 16:58:08 -0700 | [diff] [blame] | 1907 | !sig_kernel_only(signr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | continue; |
| 1909 | |
| 1910 | if (sig_kernel_stop(signr)) { |
| 1911 | /* |
| 1912 | * The default action is to stop all threads in |
| 1913 | * the thread group. The job control signals |
| 1914 | * do nothing in an orphaned pgrp, but SIGSTOP |
| 1915 | * always works. Note that siglock needs to be |
| 1916 | * dropped during the call to is_orphaned_pgrp() |
| 1917 | * because of lock ordering with tasklist_lock. |
| 1918 | * This allows an intervening SIGCONT to be posted. |
| 1919 | * We need to check for that and bail out if necessary. |
| 1920 | */ |
| 1921 | if (signr != SIGSTOP) { |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1922 | spin_unlock_irq(&sighand->siglock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
| 1924 | /* signals can be posted during this window */ |
| 1925 | |
Eric W. Biederman | 3e7cd6c | 2007-02-12 00:52:58 -0800 | [diff] [blame] | 1926 | if (is_current_pgrp_orphaned()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | goto relock; |
| 1928 | |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1929 | spin_lock_irq(&sighand->siglock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1932 | if (likely(do_signal_stop(info->si_signo))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | /* It released the siglock. */ |
| 1934 | goto relock; |
| 1935 | } |
| 1936 | |
| 1937 | /* |
| 1938 | * We didn't actually stop, due to a race |
| 1939 | * with SIGCONT or something like that. |
| 1940 | */ |
| 1941 | continue; |
| 1942 | } |
| 1943 | |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1944 | spin_unlock_irq(&sighand->siglock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | |
| 1946 | /* |
| 1947 | * Anything else is fatal, maybe with a core dump. |
| 1948 | */ |
| 1949 | current->flags |= PF_SIGNALED; |
Oleg Nesterov | 2dce81b | 2008-04-30 00:52:58 -0700 | [diff] [blame] | 1950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | if (sig_kernel_coredump(signr)) { |
Oleg Nesterov | 2dce81b | 2008-04-30 00:52:58 -0700 | [diff] [blame] | 1952 | if (print_fatal_signals) |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1953 | print_fatal_signal(regs, info->si_signo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | /* |
| 1955 | * If it was able to dump core, this kills all |
| 1956 | * other threads in the group and synchronizes with |
| 1957 | * their demise. If we lost the race with another |
| 1958 | * thread getting here, it set group_exit_code |
| 1959 | * first and our do_group_exit call below will use |
| 1960 | * that value and ignore the one we pass it. |
| 1961 | */ |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1962 | do_coredump(info->si_signo, info->si_signo, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /* |
| 1966 | * Death signals, no core dump. |
| 1967 | */ |
Roland McGrath | 7bcf6a2 | 2008-07-25 19:45:53 -0700 | [diff] [blame] | 1968 | do_group_exit(info->si_signo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | /* NOTREACHED */ |
| 1970 | } |
Oleg Nesterov | f6b76d4 | 2008-04-30 00:52:47 -0700 | [diff] [blame] | 1971 | spin_unlock_irq(&sighand->siglock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | return signr; |
| 1973 | } |
| 1974 | |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 1975 | void exit_signals(struct task_struct *tsk) |
| 1976 | { |
| 1977 | int group_stop = 0; |
Oleg Nesterov | 5dee170 | 2008-02-08 04:19:13 -0800 | [diff] [blame] | 1978 | struct task_struct *t; |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 1979 | |
Oleg Nesterov | 5dee170 | 2008-02-08 04:19:13 -0800 | [diff] [blame] | 1980 | if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) { |
| 1981 | tsk->flags |= PF_EXITING; |
| 1982 | return; |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Oleg Nesterov | 5dee170 | 2008-02-08 04:19:13 -0800 | [diff] [blame] | 1985 | spin_lock_irq(&tsk->sighand->siglock); |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 1986 | /* |
| 1987 | * From now this task is not visible for group-wide signals, |
| 1988 | * see wants_signal(), do_signal_stop(). |
| 1989 | */ |
| 1990 | tsk->flags |= PF_EXITING; |
Oleg Nesterov | 5dee170 | 2008-02-08 04:19:13 -0800 | [diff] [blame] | 1991 | if (!signal_pending(tsk)) |
| 1992 | goto out; |
| 1993 | |
| 1994 | /* It could be that __group_complete_signal() choose us to |
| 1995 | * notify about group-wide signal. Another thread should be |
| 1996 | * woken now to take the signal since we will not. |
| 1997 | */ |
| 1998 | for (t = tsk; (t = next_thread(t)) != tsk; ) |
| 1999 | if (!signal_pending(t) && !(t->flags & PF_EXITING)) |
| 2000 | recalc_sigpending_and_wake(t); |
| 2001 | |
| 2002 | if (unlikely(tsk->signal->group_stop_count) && |
| 2003 | !--tsk->signal->group_stop_count) { |
| 2004 | tsk->signal->flags = SIGNAL_STOP_STOPPED; |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 2005 | group_stop = tracehook_notify_jctl(CLD_STOPPED, CLD_STOPPED); |
Oleg Nesterov | 5dee170 | 2008-02-08 04:19:13 -0800 | [diff] [blame] | 2006 | } |
| 2007 | out: |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 2008 | spin_unlock_irq(&tsk->sighand->siglock); |
| 2009 | |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 2010 | if (unlikely(group_stop)) { |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 2011 | read_lock(&tasklist_lock); |
Roland McGrath | ae6d2ed | 2009-09-23 15:56:53 -0700 | [diff] [blame] | 2012 | do_notify_parent_cldstop(tsk, group_stop); |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 2013 | read_unlock(&tasklist_lock); |
| 2014 | } |
| 2015 | } |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | EXPORT_SYMBOL(recalc_sigpending); |
| 2018 | EXPORT_SYMBOL_GPL(dequeue_signal); |
| 2019 | EXPORT_SYMBOL(flush_signals); |
| 2020 | EXPORT_SYMBOL(force_sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | EXPORT_SYMBOL(send_sig); |
| 2022 | EXPORT_SYMBOL(send_sig_info); |
| 2023 | EXPORT_SYMBOL(sigprocmask); |
| 2024 | EXPORT_SYMBOL(block_all_signals); |
| 2025 | EXPORT_SYMBOL(unblock_all_signals); |
| 2026 | |
| 2027 | |
| 2028 | /* |
| 2029 | * System call entry points. |
| 2030 | */ |
| 2031 | |
Heiko Carstens | 754fe8d | 2009-01-14 14:14:09 +0100 | [diff] [blame] | 2032 | SYSCALL_DEFINE0(restart_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | { |
| 2034 | struct restart_block *restart = ¤t_thread_info()->restart_block; |
| 2035 | return restart->fn(restart); |
| 2036 | } |
| 2037 | |
| 2038 | long do_no_restart_syscall(struct restart_block *param) |
| 2039 | { |
| 2040 | return -EINTR; |
| 2041 | } |
| 2042 | |
| 2043 | /* |
| 2044 | * We don't need to get the kernel lock - this is all local to this |
| 2045 | * particular thread.. (and that's good, because this is _heavily_ |
| 2046 | * used by various programs) |
| 2047 | */ |
| 2048 | |
| 2049 | /* |
| 2050 | * This is also useful for kernel threads that want to temporarily |
| 2051 | * (or permanently) block certain signals. |
| 2052 | * |
| 2053 | * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel |
| 2054 | * interface happily blocks "unblockable" signals like SIGKILL |
| 2055 | * and friends. |
| 2056 | */ |
| 2057 | int sigprocmask(int how, sigset_t *set, sigset_t *oldset) |
| 2058 | { |
| 2059 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
| 2061 | spin_lock_irq(¤t->sighand->siglock); |
Oleg Nesterov | a26fd33 | 2006-03-23 03:00:49 -0800 | [diff] [blame] | 2062 | if (oldset) |
| 2063 | *oldset = current->blocked; |
| 2064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | error = 0; |
| 2066 | switch (how) { |
| 2067 | case SIG_BLOCK: |
| 2068 | sigorsets(¤t->blocked, ¤t->blocked, set); |
| 2069 | break; |
| 2070 | case SIG_UNBLOCK: |
| 2071 | signandsets(¤t->blocked, ¤t->blocked, set); |
| 2072 | break; |
| 2073 | case SIG_SETMASK: |
| 2074 | current->blocked = *set; |
| 2075 | break; |
| 2076 | default: |
| 2077 | error = -EINVAL; |
| 2078 | } |
| 2079 | recalc_sigpending(); |
| 2080 | spin_unlock_irq(¤t->sighand->siglock); |
Oleg Nesterov | a26fd33 | 2006-03-23 03:00:49 -0800 | [diff] [blame] | 2081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | return error; |
| 2083 | } |
| 2084 | |
Heiko Carstens | 17da2bd | 2009-01-14 14:14:10 +0100 | [diff] [blame] | 2085 | SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, set, |
| 2086 | sigset_t __user *, oset, size_t, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
| 2088 | int error = -EINVAL; |
| 2089 | sigset_t old_set, new_set; |
| 2090 | |
| 2091 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 2092 | if (sigsetsize != sizeof(sigset_t)) |
| 2093 | goto out; |
| 2094 | |
| 2095 | if (set) { |
| 2096 | error = -EFAULT; |
| 2097 | if (copy_from_user(&new_set, set, sizeof(*set))) |
| 2098 | goto out; |
| 2099 | sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
| 2100 | |
| 2101 | error = sigprocmask(how, &new_set, &old_set); |
| 2102 | if (error) |
| 2103 | goto out; |
| 2104 | if (oset) |
| 2105 | goto set_old; |
| 2106 | } else if (oset) { |
| 2107 | spin_lock_irq(¤t->sighand->siglock); |
| 2108 | old_set = current->blocked; |
| 2109 | spin_unlock_irq(¤t->sighand->siglock); |
| 2110 | |
| 2111 | set_old: |
| 2112 | error = -EFAULT; |
| 2113 | if (copy_to_user(oset, &old_set, sizeof(*oset))) |
| 2114 | goto out; |
| 2115 | } |
| 2116 | error = 0; |
| 2117 | out: |
| 2118 | return error; |
| 2119 | } |
| 2120 | |
| 2121 | long do_sigpending(void __user *set, unsigned long sigsetsize) |
| 2122 | { |
| 2123 | long error = -EINVAL; |
| 2124 | sigset_t pending; |
| 2125 | |
| 2126 | if (sigsetsize > sizeof(sigset_t)) |
| 2127 | goto out; |
| 2128 | |
| 2129 | spin_lock_irq(¤t->sighand->siglock); |
| 2130 | sigorsets(&pending, ¤t->pending.signal, |
| 2131 | ¤t->signal->shared_pending.signal); |
| 2132 | spin_unlock_irq(¤t->sighand->siglock); |
| 2133 | |
| 2134 | /* Outside the lock because only this thread touches it. */ |
| 2135 | sigandsets(&pending, ¤t->blocked, &pending); |
| 2136 | |
| 2137 | error = -EFAULT; |
| 2138 | if (!copy_to_user(set, &pending, sigsetsize)) |
| 2139 | error = 0; |
| 2140 | |
| 2141 | out: |
| 2142 | return error; |
| 2143 | } |
| 2144 | |
Heiko Carstens | 17da2bd | 2009-01-14 14:14:10 +0100 | [diff] [blame] | 2145 | SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | { |
| 2147 | return do_sigpending(set, sigsetsize); |
| 2148 | } |
| 2149 | |
| 2150 | #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER |
| 2151 | |
| 2152 | int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from) |
| 2153 | { |
| 2154 | int err; |
| 2155 | |
| 2156 | if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t))) |
| 2157 | return -EFAULT; |
| 2158 | if (from->si_code < 0) |
| 2159 | return __copy_to_user(to, from, sizeof(siginfo_t)) |
| 2160 | ? -EFAULT : 0; |
| 2161 | /* |
| 2162 | * If you change siginfo_t structure, please be sure |
| 2163 | * this code is fixed accordingly. |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 2164 | * Please remember to update the signalfd_copyinfo() function |
| 2165 | * inside fs/signalfd.c too, in case siginfo_t changes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | * It should never copy any pad contained in the structure |
| 2167 | * to avoid security leaks, but must copy the generic |
| 2168 | * 3 ints plus the relevant union member. |
| 2169 | */ |
| 2170 | err = __put_user(from->si_signo, &to->si_signo); |
| 2171 | err |= __put_user(from->si_errno, &to->si_errno); |
| 2172 | err |= __put_user((short)from->si_code, &to->si_code); |
| 2173 | switch (from->si_code & __SI_MASK) { |
| 2174 | case __SI_KILL: |
| 2175 | err |= __put_user(from->si_pid, &to->si_pid); |
| 2176 | err |= __put_user(from->si_uid, &to->si_uid); |
| 2177 | break; |
| 2178 | case __SI_TIMER: |
| 2179 | err |= __put_user(from->si_tid, &to->si_tid); |
| 2180 | err |= __put_user(from->si_overrun, &to->si_overrun); |
| 2181 | err |= __put_user(from->si_ptr, &to->si_ptr); |
| 2182 | break; |
| 2183 | case __SI_POLL: |
| 2184 | err |= __put_user(from->si_band, &to->si_band); |
| 2185 | err |= __put_user(from->si_fd, &to->si_fd); |
| 2186 | break; |
| 2187 | case __SI_FAULT: |
| 2188 | err |= __put_user(from->si_addr, &to->si_addr); |
| 2189 | #ifdef __ARCH_SI_TRAPNO |
| 2190 | err |= __put_user(from->si_trapno, &to->si_trapno); |
| 2191 | #endif |
| 2192 | break; |
| 2193 | case __SI_CHLD: |
| 2194 | err |= __put_user(from->si_pid, &to->si_pid); |
| 2195 | err |= __put_user(from->si_uid, &to->si_uid); |
| 2196 | err |= __put_user(from->si_status, &to->si_status); |
| 2197 | err |= __put_user(from->si_utime, &to->si_utime); |
| 2198 | err |= __put_user(from->si_stime, &to->si_stime); |
| 2199 | break; |
| 2200 | case __SI_RT: /* This is not generated by the kernel as of now. */ |
| 2201 | case __SI_MESGQ: /* But this is */ |
| 2202 | err |= __put_user(from->si_pid, &to->si_pid); |
| 2203 | err |= __put_user(from->si_uid, &to->si_uid); |
| 2204 | err |= __put_user(from->si_ptr, &to->si_ptr); |
| 2205 | break; |
| 2206 | default: /* this is just in case for now ... */ |
| 2207 | err |= __put_user(from->si_pid, &to->si_pid); |
| 2208 | err |= __put_user(from->si_uid, &to->si_uid); |
| 2209 | break; |
| 2210 | } |
| 2211 | return err; |
| 2212 | } |
| 2213 | |
| 2214 | #endif |
| 2215 | |
Heiko Carstens | 17da2bd | 2009-01-14 14:14:10 +0100 | [diff] [blame] | 2216 | SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, |
| 2217 | siginfo_t __user *, uinfo, const struct timespec __user *, uts, |
| 2218 | size_t, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
| 2220 | int ret, sig; |
| 2221 | sigset_t these; |
| 2222 | struct timespec ts; |
| 2223 | siginfo_t info; |
| 2224 | long timeout = 0; |
| 2225 | |
| 2226 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 2227 | if (sigsetsize != sizeof(sigset_t)) |
| 2228 | return -EINVAL; |
| 2229 | |
| 2230 | if (copy_from_user(&these, uthese, sizeof(these))) |
| 2231 | return -EFAULT; |
| 2232 | |
| 2233 | /* |
| 2234 | * Invert the set of allowed signals to get those we |
| 2235 | * want to block. |
| 2236 | */ |
| 2237 | sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
| 2238 | signotset(&these); |
| 2239 | |
| 2240 | if (uts) { |
| 2241 | if (copy_from_user(&ts, uts, sizeof(ts))) |
| 2242 | return -EFAULT; |
| 2243 | if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0 |
| 2244 | || ts.tv_sec < 0) |
| 2245 | return -EINVAL; |
| 2246 | } |
| 2247 | |
| 2248 | spin_lock_irq(¤t->sighand->siglock); |
| 2249 | sig = dequeue_signal(current, &these, &info); |
| 2250 | if (!sig) { |
| 2251 | timeout = MAX_SCHEDULE_TIMEOUT; |
| 2252 | if (uts) |
| 2253 | timeout = (timespec_to_jiffies(&ts) |
| 2254 | + (ts.tv_sec || ts.tv_nsec)); |
| 2255 | |
| 2256 | if (timeout) { |
| 2257 | /* None ready -- temporarily unblock those we're |
| 2258 | * interested while we are sleeping in so that we'll |
| 2259 | * be awakened when they arrive. */ |
| 2260 | current->real_blocked = current->blocked; |
| 2261 | sigandsets(¤t->blocked, ¤t->blocked, &these); |
| 2262 | recalc_sigpending(); |
| 2263 | spin_unlock_irq(¤t->sighand->siglock); |
| 2264 | |
Nishanth Aravamudan | 75bcc8c | 2005-09-10 00:27:24 -0700 | [diff] [blame] | 2265 | timeout = schedule_timeout_interruptible(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | spin_lock_irq(¤t->sighand->siglock); |
| 2268 | sig = dequeue_signal(current, &these, &info); |
| 2269 | current->blocked = current->real_blocked; |
| 2270 | siginitset(¤t->real_blocked, 0); |
| 2271 | recalc_sigpending(); |
| 2272 | } |
| 2273 | } |
| 2274 | spin_unlock_irq(¤t->sighand->siglock); |
| 2275 | |
| 2276 | if (sig) { |
| 2277 | ret = sig; |
| 2278 | if (uinfo) { |
| 2279 | if (copy_siginfo_to_user(uinfo, &info)) |
| 2280 | ret = -EFAULT; |
| 2281 | } |
| 2282 | } else { |
| 2283 | ret = -EAGAIN; |
| 2284 | if (timeout) |
| 2285 | ret = -EINTR; |
| 2286 | } |
| 2287 | |
| 2288 | return ret; |
| 2289 | } |
| 2290 | |
Heiko Carstens | 17da2bd | 2009-01-14 14:14:10 +0100 | [diff] [blame] | 2291 | SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | { |
| 2293 | struct siginfo info; |
| 2294 | |
| 2295 | info.si_signo = sig; |
| 2296 | info.si_errno = 0; |
| 2297 | info.si_code = SI_USER; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 2298 | info.si_pid = task_tgid_vnr(current); |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 2299 | info.si_uid = current_uid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | |
| 2301 | return kill_something_info(sig, &info, pid); |
| 2302 | } |
| 2303 | |
Thomas Gleixner | 30b4ae8 | 2009-04-04 21:01:01 +0000 | [diff] [blame] | 2304 | static int |
| 2305 | do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info) |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2306 | { |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2307 | struct task_struct *p; |
Thomas Gleixner | 30b4ae8 | 2009-04-04 21:01:01 +0000 | [diff] [blame] | 2308 | int error = -ESRCH; |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2309 | |
Oleg Nesterov | 3547ff3 | 2008-04-30 00:52:51 -0700 | [diff] [blame] | 2310 | rcu_read_lock(); |
Pavel Emelyanov | 228ebcb | 2007-10-18 23:40:16 -0700 | [diff] [blame] | 2311 | p = find_task_by_vpid(pid); |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 2312 | if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) { |
Thomas Gleixner | 30b4ae8 | 2009-04-04 21:01:01 +0000 | [diff] [blame] | 2313 | error = check_kill_permission(sig, info, p); |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2314 | /* |
| 2315 | * The null signal is a permissions and process existence |
| 2316 | * probe. No signal is actually delivered. |
| 2317 | */ |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 2318 | if (!error && sig) { |
| 2319 | error = do_send_sig_info(sig, info, p, false); |
| 2320 | /* |
| 2321 | * If lock_task_sighand() failed we pretend the task |
| 2322 | * dies after receiving the signal. The window is tiny, |
| 2323 | * and the signal is private anyway. |
| 2324 | */ |
| 2325 | if (unlikely(error == -ESRCH)) |
| 2326 | error = 0; |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2327 | } |
| 2328 | } |
Oleg Nesterov | 3547ff3 | 2008-04-30 00:52:51 -0700 | [diff] [blame] | 2329 | rcu_read_unlock(); |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2330 | |
| 2331 | return error; |
| 2332 | } |
| 2333 | |
Thomas Gleixner | 30b4ae8 | 2009-04-04 21:01:01 +0000 | [diff] [blame] | 2334 | static int do_tkill(pid_t tgid, pid_t pid, int sig) |
| 2335 | { |
| 2336 | struct siginfo info; |
| 2337 | |
| 2338 | info.si_signo = sig; |
| 2339 | info.si_errno = 0; |
| 2340 | info.si_code = SI_TKILL; |
| 2341 | info.si_pid = task_tgid_vnr(current); |
| 2342 | info.si_uid = current_uid(); |
| 2343 | |
| 2344 | return do_send_specific(tgid, pid, sig, &info); |
| 2345 | } |
| 2346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | /** |
| 2348 | * sys_tgkill - send signal to one specific thread |
| 2349 | * @tgid: the thread group ID of the thread |
| 2350 | * @pid: the PID of the thread |
| 2351 | * @sig: signal to be sent |
| 2352 | * |
Robert P. J. Day | 72fd4a3 | 2007-02-10 01:45:59 -0800 | [diff] [blame] | 2353 | * This syscall also checks the @tgid and returns -ESRCH even if the PID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | * exists but it's not belonging to the target process anymore. This |
| 2355 | * method solves the problem of threads exiting and PIDs getting reused. |
| 2356 | */ |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2357 | SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | /* This is only valid for single tasks */ |
| 2360 | if (pid <= 0 || tgid <= 0) |
| 2361 | return -EINVAL; |
| 2362 | |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2363 | return do_tkill(tgid, pid, sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | /* |
| 2367 | * Send a signal to only one task, even if it's a CLONE_THREAD task. |
| 2368 | */ |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2369 | SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | /* This is only valid for single tasks */ |
| 2372 | if (pid <= 0) |
| 2373 | return -EINVAL; |
| 2374 | |
Vadim Lobanov | 6dd69f1 | 2005-10-30 15:02:18 -0800 | [diff] [blame] | 2375 | return do_tkill(0, pid, sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2378 | SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, |
| 2379 | siginfo_t __user *, uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | { |
| 2381 | siginfo_t info; |
| 2382 | |
| 2383 | if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
| 2384 | return -EFAULT; |
| 2385 | |
| 2386 | /* Not even root can pretend to send signals from the kernel. |
| 2387 | Nor can they impersonate a kill(), which adds source info. */ |
| 2388 | if (info.si_code >= 0) |
| 2389 | return -EPERM; |
| 2390 | info.si_signo = sig; |
| 2391 | |
| 2392 | /* POSIX.1b doesn't mention process groups. */ |
| 2393 | return kill_proc_info(sig, &info, pid); |
| 2394 | } |
| 2395 | |
Thomas Gleixner | 62ab450 | 2009-04-04 21:01:06 +0000 | [diff] [blame] | 2396 | long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info) |
| 2397 | { |
| 2398 | /* This is only valid for single tasks */ |
| 2399 | if (pid <= 0 || tgid <= 0) |
| 2400 | return -EINVAL; |
| 2401 | |
| 2402 | /* Not even root can pretend to send signals from the kernel. |
| 2403 | Nor can they impersonate a kill(), which adds source info. */ |
| 2404 | if (info->si_code >= 0) |
| 2405 | return -EPERM; |
| 2406 | info->si_signo = sig; |
| 2407 | |
| 2408 | return do_send_specific(tgid, pid, sig, info); |
| 2409 | } |
| 2410 | |
| 2411 | SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig, |
| 2412 | siginfo_t __user *, uinfo) |
| 2413 | { |
| 2414 | siginfo_t info; |
| 2415 | |
| 2416 | if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
| 2417 | return -EFAULT; |
| 2418 | |
| 2419 | return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); |
| 2420 | } |
| 2421 | |
Oleg Nesterov | 88531f7 | 2006-03-28 16:11:24 -0800 | [diff] [blame] | 2422 | int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | { |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 2424 | struct task_struct *t = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | struct k_sigaction *k; |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 2426 | sigset_t mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 2428 | if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return -EINVAL; |
| 2430 | |
Pavel Emelyanov | 93585ee | 2008-04-30 00:52:39 -0700 | [diff] [blame] | 2431 | k = &t->sighand->action[sig-1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | |
| 2433 | spin_lock_irq(¤t->sighand->siglock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | if (oact) |
| 2435 | *oact = *k; |
| 2436 | |
| 2437 | if (act) { |
Oleg Nesterov | 9ac95f2 | 2006-02-09 22:41:50 +0300 | [diff] [blame] | 2438 | sigdelsetmask(&act->sa.sa_mask, |
| 2439 | sigmask(SIGKILL) | sigmask(SIGSTOP)); |
Oleg Nesterov | 88531f7 | 2006-03-28 16:11:24 -0800 | [diff] [blame] | 2440 | *k = *act; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | /* |
| 2442 | * POSIX 3.3.1.3: |
| 2443 | * "Setting a signal action to SIG_IGN for a signal that is |
| 2444 | * pending shall cause the pending signal to be discarded, |
| 2445 | * whether or not it is blocked." |
| 2446 | * |
| 2447 | * "Setting a signal action to SIG_DFL for a signal that is |
| 2448 | * pending and whose default action is to ignore the signal |
| 2449 | * (for example, SIGCHLD), shall cause the pending signal to |
| 2450 | * be discarded, whether or not it is blocked" |
| 2451 | */ |
Roland McGrath | 35de254 | 2008-07-25 19:45:51 -0700 | [diff] [blame] | 2452 | if (sig_handler_ignored(sig_handler(t, sig), sig)) { |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 2453 | sigemptyset(&mask); |
| 2454 | sigaddset(&mask, sig); |
| 2455 | rm_from_queue_full(&mask, &t->signal->shared_pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | do { |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 2457 | rm_from_queue_full(&mask, &t->pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | t = next_thread(t); |
| 2459 | } while (t != current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | spin_unlock_irq(¤t->sighand->siglock); |
| 2464 | return 0; |
| 2465 | } |
| 2466 | |
| 2467 | int |
| 2468 | do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long sp) |
| 2469 | { |
| 2470 | stack_t oss; |
| 2471 | int error; |
| 2472 | |
Linus Torvalds | 0083fc2 | 2009-08-01 10:34:56 -0700 | [diff] [blame] | 2473 | oss.ss_sp = (void __user *) current->sas_ss_sp; |
| 2474 | oss.ss_size = current->sas_ss_size; |
| 2475 | oss.ss_flags = sas_ss_flags(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | |
| 2477 | if (uss) { |
| 2478 | void __user *ss_sp; |
| 2479 | size_t ss_size; |
| 2480 | int ss_flags; |
| 2481 | |
| 2482 | error = -EFAULT; |
Linus Torvalds | 0dd8486 | 2009-08-01 11:18:56 -0700 | [diff] [blame] | 2483 | if (!access_ok(VERIFY_READ, uss, sizeof(*uss))) |
| 2484 | goto out; |
| 2485 | error = __get_user(ss_sp, &uss->ss_sp) | |
| 2486 | __get_user(ss_flags, &uss->ss_flags) | |
| 2487 | __get_user(ss_size, &uss->ss_size); |
| 2488 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | goto out; |
| 2490 | |
| 2491 | error = -EPERM; |
| 2492 | if (on_sig_stack(sp)) |
| 2493 | goto out; |
| 2494 | |
| 2495 | error = -EINVAL; |
| 2496 | /* |
| 2497 | * |
| 2498 | * Note - this code used to test ss_flags incorrectly |
| 2499 | * old code may have been written using ss_flags==0 |
| 2500 | * to mean ss_flags==SS_ONSTACK (as this was the only |
| 2501 | * way that worked) - this fix preserves that older |
| 2502 | * mechanism |
| 2503 | */ |
| 2504 | if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0) |
| 2505 | goto out; |
| 2506 | |
| 2507 | if (ss_flags == SS_DISABLE) { |
| 2508 | ss_size = 0; |
| 2509 | ss_sp = NULL; |
| 2510 | } else { |
| 2511 | error = -ENOMEM; |
| 2512 | if (ss_size < MINSIGSTKSZ) |
| 2513 | goto out; |
| 2514 | } |
| 2515 | |
| 2516 | current->sas_ss_sp = (unsigned long) ss_sp; |
| 2517 | current->sas_ss_size = ss_size; |
| 2518 | } |
| 2519 | |
Linus Torvalds | 0083fc2 | 2009-08-01 10:34:56 -0700 | [diff] [blame] | 2520 | error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | if (uoss) { |
| 2522 | error = -EFAULT; |
Linus Torvalds | 0083fc2 | 2009-08-01 10:34:56 -0700 | [diff] [blame] | 2523 | if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | goto out; |
Linus Torvalds | 0083fc2 | 2009-08-01 10:34:56 -0700 | [diff] [blame] | 2525 | error = __put_user(oss.ss_sp, &uoss->ss_sp) | |
| 2526 | __put_user(oss.ss_size, &uoss->ss_size) | |
| 2527 | __put_user(oss.ss_flags, &uoss->ss_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | out: |
| 2531 | return error; |
| 2532 | } |
| 2533 | |
| 2534 | #ifdef __ARCH_WANT_SYS_SIGPENDING |
| 2535 | |
Heiko Carstens | b290ebe | 2009-01-14 14:14:06 +0100 | [diff] [blame] | 2536 | SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | { |
| 2538 | return do_sigpending(set, sizeof(*set)); |
| 2539 | } |
| 2540 | |
| 2541 | #endif |
| 2542 | |
| 2543 | #ifdef __ARCH_WANT_SYS_SIGPROCMASK |
| 2544 | /* Some platforms have their own version with special arguments others |
| 2545 | support only sys_rt_sigprocmask. */ |
| 2546 | |
Heiko Carstens | b290ebe | 2009-01-14 14:14:06 +0100 | [diff] [blame] | 2547 | SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set, |
| 2548 | old_sigset_t __user *, oset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | { |
| 2550 | int error; |
| 2551 | old_sigset_t old_set, new_set; |
| 2552 | |
| 2553 | if (set) { |
| 2554 | error = -EFAULT; |
| 2555 | if (copy_from_user(&new_set, set, sizeof(*set))) |
| 2556 | goto out; |
| 2557 | new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP)); |
| 2558 | |
| 2559 | spin_lock_irq(¤t->sighand->siglock); |
| 2560 | old_set = current->blocked.sig[0]; |
| 2561 | |
| 2562 | error = 0; |
| 2563 | switch (how) { |
| 2564 | default: |
| 2565 | error = -EINVAL; |
| 2566 | break; |
| 2567 | case SIG_BLOCK: |
| 2568 | sigaddsetmask(¤t->blocked, new_set); |
| 2569 | break; |
| 2570 | case SIG_UNBLOCK: |
| 2571 | sigdelsetmask(¤t->blocked, new_set); |
| 2572 | break; |
| 2573 | case SIG_SETMASK: |
| 2574 | current->blocked.sig[0] = new_set; |
| 2575 | break; |
| 2576 | } |
| 2577 | |
| 2578 | recalc_sigpending(); |
| 2579 | spin_unlock_irq(¤t->sighand->siglock); |
| 2580 | if (error) |
| 2581 | goto out; |
| 2582 | if (oset) |
| 2583 | goto set_old; |
| 2584 | } else if (oset) { |
| 2585 | old_set = current->blocked.sig[0]; |
| 2586 | set_old: |
| 2587 | error = -EFAULT; |
| 2588 | if (copy_to_user(oset, &old_set, sizeof(*oset))) |
| 2589 | goto out; |
| 2590 | } |
| 2591 | error = 0; |
| 2592 | out: |
| 2593 | return error; |
| 2594 | } |
| 2595 | #endif /* __ARCH_WANT_SYS_SIGPROCMASK */ |
| 2596 | |
| 2597 | #ifdef __ARCH_WANT_SYS_RT_SIGACTION |
Heiko Carstens | d4e8204 | 2009-01-14 14:14:34 +0100 | [diff] [blame] | 2598 | SYSCALL_DEFINE4(rt_sigaction, int, sig, |
| 2599 | const struct sigaction __user *, act, |
| 2600 | struct sigaction __user *, oact, |
| 2601 | size_t, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | { |
| 2603 | struct k_sigaction new_sa, old_sa; |
| 2604 | int ret = -EINVAL; |
| 2605 | |
| 2606 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 2607 | if (sigsetsize != sizeof(sigset_t)) |
| 2608 | goto out; |
| 2609 | |
| 2610 | if (act) { |
| 2611 | if (copy_from_user(&new_sa.sa, act, sizeof(new_sa.sa))) |
| 2612 | return -EFAULT; |
| 2613 | } |
| 2614 | |
| 2615 | ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL); |
| 2616 | |
| 2617 | if (!ret && oact) { |
| 2618 | if (copy_to_user(oact, &old_sa.sa, sizeof(old_sa.sa))) |
| 2619 | return -EFAULT; |
| 2620 | } |
| 2621 | out: |
| 2622 | return ret; |
| 2623 | } |
| 2624 | #endif /* __ARCH_WANT_SYS_RT_SIGACTION */ |
| 2625 | |
| 2626 | #ifdef __ARCH_WANT_SYS_SGETMASK |
| 2627 | |
| 2628 | /* |
| 2629 | * For backwards compatibility. Functionality superseded by sigprocmask. |
| 2630 | */ |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2631 | SYSCALL_DEFINE0(sgetmask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | { |
| 2633 | /* SMP safe */ |
| 2634 | return current->blocked.sig[0]; |
| 2635 | } |
| 2636 | |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2637 | SYSCALL_DEFINE1(ssetmask, int, newmask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | { |
| 2639 | int old; |
| 2640 | |
| 2641 | spin_lock_irq(¤t->sighand->siglock); |
| 2642 | old = current->blocked.sig[0]; |
| 2643 | |
| 2644 | siginitset(¤t->blocked, newmask & ~(sigmask(SIGKILL)| |
| 2645 | sigmask(SIGSTOP))); |
| 2646 | recalc_sigpending(); |
| 2647 | spin_unlock_irq(¤t->sighand->siglock); |
| 2648 | |
| 2649 | return old; |
| 2650 | } |
| 2651 | #endif /* __ARCH_WANT_SGETMASK */ |
| 2652 | |
| 2653 | #ifdef __ARCH_WANT_SYS_SIGNAL |
| 2654 | /* |
| 2655 | * For backwards compatibility. Functionality superseded by sigaction. |
| 2656 | */ |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2657 | SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | { |
| 2659 | struct k_sigaction new_sa, old_sa; |
| 2660 | int ret; |
| 2661 | |
| 2662 | new_sa.sa.sa_handler = handler; |
| 2663 | new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK; |
Oleg Nesterov | c70d3d70 | 2006-02-09 22:41:41 +0300 | [diff] [blame] | 2664 | sigemptyset(&new_sa.sa.sa_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
| 2666 | ret = do_sigaction(sig, &new_sa, &old_sa); |
| 2667 | |
| 2668 | return ret ? ret : (unsigned long)old_sa.sa.sa_handler; |
| 2669 | } |
| 2670 | #endif /* __ARCH_WANT_SYS_SIGNAL */ |
| 2671 | |
| 2672 | #ifdef __ARCH_WANT_SYS_PAUSE |
| 2673 | |
Heiko Carstens | a5f8fa9 | 2009-01-14 14:14:11 +0100 | [diff] [blame] | 2674 | SYSCALL_DEFINE0(pause) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | { |
| 2676 | current->state = TASK_INTERRUPTIBLE; |
| 2677 | schedule(); |
| 2678 | return -ERESTARTNOHAND; |
| 2679 | } |
| 2680 | |
| 2681 | #endif |
| 2682 | |
David Woodhouse | 150256d | 2006-01-18 17:43:57 -0800 | [diff] [blame] | 2683 | #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND |
Heiko Carstens | d4e8204 | 2009-01-14 14:14:34 +0100 | [diff] [blame] | 2684 | SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize) |
David Woodhouse | 150256d | 2006-01-18 17:43:57 -0800 | [diff] [blame] | 2685 | { |
| 2686 | sigset_t newset; |
| 2687 | |
| 2688 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 2689 | if (sigsetsize != sizeof(sigset_t)) |
| 2690 | return -EINVAL; |
| 2691 | |
| 2692 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
| 2693 | return -EFAULT; |
| 2694 | sigdelsetmask(&newset, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
| 2695 | |
| 2696 | spin_lock_irq(¤t->sighand->siglock); |
| 2697 | current->saved_sigmask = current->blocked; |
| 2698 | current->blocked = newset; |
| 2699 | recalc_sigpending(); |
| 2700 | spin_unlock_irq(¤t->sighand->siglock); |
| 2701 | |
| 2702 | current->state = TASK_INTERRUPTIBLE; |
| 2703 | schedule(); |
Roland McGrath | 4e4c22c | 2008-04-30 00:53:06 -0700 | [diff] [blame] | 2704 | set_restore_sigmask(); |
David Woodhouse | 150256d | 2006-01-18 17:43:57 -0800 | [diff] [blame] | 2705 | return -ERESTARTNOHAND; |
| 2706 | } |
| 2707 | #endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */ |
| 2708 | |
David Howells | f269fdd | 2006-09-27 01:50:23 -0700 | [diff] [blame] | 2709 | __attribute__((weak)) const char *arch_vma_name(struct vm_area_struct *vma) |
| 2710 | { |
| 2711 | return NULL; |
| 2712 | } |
| 2713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | void __init signals_init(void) |
| 2715 | { |
Christoph Lameter | 0a31bd5 | 2007-05-06 14:49:57 -0700 | [diff] [blame] | 2716 | sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } |