diff options
Diffstat (limited to 'kernel/signal.c')
-rw-r--r-- | kernel/signal.c | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/kernel/signal.c b/kernel/signal.c index 6705320784fd..6b982f2cf524 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -22,12 +22,14 @@ | |||
22 | #include <linux/ptrace.h> | 22 | #include <linux/ptrace.h> |
23 | #include <linux/signal.h> | 23 | #include <linux/signal.h> |
24 | #include <linux/signalfd.h> | 24 | #include <linux/signalfd.h> |
25 | #include <linux/ratelimit.h> | ||
25 | #include <linux/tracehook.h> | 26 | #include <linux/tracehook.h> |
26 | #include <linux/capability.h> | 27 | #include <linux/capability.h> |
27 | #include <linux/freezer.h> | 28 | #include <linux/freezer.h> |
28 | #include <linux/pid_namespace.h> | 29 | #include <linux/pid_namespace.h> |
29 | #include <linux/nsproxy.h> | 30 | #include <linux/nsproxy.h> |
30 | #include <trace/events/sched.h> | 31 | #define CREATE_TRACE_POINTS |
32 | #include <trace/events/signal.h> | ||
31 | 33 | ||
32 | #include <asm/param.h> | 34 | #include <asm/param.h> |
33 | #include <asm/uaccess.h> | 35 | #include <asm/uaccess.h> |
@@ -41,6 +43,8 @@ | |||
41 | 43 | ||
42 | static struct kmem_cache *sigqueue_cachep; | 44 | static struct kmem_cache *sigqueue_cachep; |
43 | 45 | ||
46 | int print_fatal_signals __read_mostly; | ||
47 | |||
44 | static void __user *sig_handler(struct task_struct *t, int sig) | 48 | static void __user *sig_handler(struct task_struct *t, int sig) |
45 | { | 49 | { |
46 | return t->sighand->action[sig - 1].sa.sa_handler; | 50 | return t->sighand->action[sig - 1].sa.sa_handler; |
@@ -159,7 +163,7 @@ int next_signal(struct sigpending *pending, sigset_t *mask) | |||
159 | { | 163 | { |
160 | unsigned long i, *s, *m, x; | 164 | unsigned long i, *s, *m, x; |
161 | int sig = 0; | 165 | int sig = 0; |
162 | 166 | ||
163 | s = pending->signal.sig; | 167 | s = pending->signal.sig; |
164 | m = mask->sig; | 168 | m = mask->sig; |
165 | switch (_NSIG_WORDS) { | 169 | switch (_NSIG_WORDS) { |
@@ -184,17 +188,31 @@ int next_signal(struct sigpending *pending, sigset_t *mask) | |||
184 | sig = ffz(~x) + 1; | 188 | sig = ffz(~x) + 1; |
185 | break; | 189 | break; |
186 | } | 190 | } |
187 | 191 | ||
188 | return sig; | 192 | return sig; |
189 | } | 193 | } |
190 | 194 | ||
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 | |||
191 | /* | 209 | /* |
192 | * allocate a new signal queue record | 210 | * allocate a new signal queue record |
193 | * - this may be called without locks if and only if t == current, otherwise an | 211 | * - this may be called without locks if and only if t == current, otherwise an |
194 | * appopriate lock must be held to stop the target task from exiting | 212 | * appopriate lock must be held to stop the target task from exiting |
195 | */ | 213 | */ |
196 | static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags, | 214 | static struct sigqueue * |
197 | int override_rlimit) | 215 | __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) |
198 | { | 216 | { |
199 | struct sigqueue *q = NULL; | 217 | struct sigqueue *q = NULL; |
200 | struct user_struct *user; | 218 | struct user_struct *user; |
@@ -207,10 +225,15 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags, | |||
207 | */ | 225 | */ |
208 | user = get_uid(__task_cred(t)->user); | 226 | user = get_uid(__task_cred(t)->user); |
209 | atomic_inc(&user->sigpending); | 227 | atomic_inc(&user->sigpending); |
228 | |||
210 | if (override_rlimit || | 229 | if (override_rlimit || |
211 | atomic_read(&user->sigpending) <= | 230 | atomic_read(&user->sigpending) <= |
212 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) | 231 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) { |
213 | q = kmem_cache_alloc(sigqueue_cachep, flags); | 232 | q = kmem_cache_alloc(sigqueue_cachep, flags); |
233 | } else { | ||
234 | print_dropped_signal(sig); | ||
235 | } | ||
236 | |||
214 | if (unlikely(q == NULL)) { | 237 | if (unlikely(q == NULL)) { |
215 | atomic_dec(&user->sigpending); | 238 | atomic_dec(&user->sigpending); |
216 | free_uid(user); | 239 | free_uid(user); |
@@ -834,7 +857,7 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, | |||
834 | struct sigqueue *q; | 857 | struct sigqueue *q; |
835 | int override_rlimit; | 858 | int override_rlimit; |
836 | 859 | ||
837 | trace_sched_signal_send(sig, t); | 860 | trace_signal_generate(sig, info, t); |
838 | 861 | ||
839 | assert_spin_locked(&t->sighand->siglock); | 862 | assert_spin_locked(&t->sighand->siglock); |
840 | 863 | ||
@@ -869,7 +892,7 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, | |||
869 | else | 892 | else |
870 | override_rlimit = 0; | 893 | override_rlimit = 0; |
871 | 894 | ||
872 | q = __sigqueue_alloc(t, GFP_ATOMIC | __GFP_NOTRACK_FALSE_POSITIVE, | 895 | q = __sigqueue_alloc(sig, t, GFP_ATOMIC | __GFP_NOTRACK_FALSE_POSITIVE, |
873 | override_rlimit); | 896 | override_rlimit); |
874 | if (q) { | 897 | if (q) { |
875 | list_add_tail(&q->list, &pending->list); | 898 | list_add_tail(&q->list, &pending->list); |
@@ -896,12 +919,21 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, | |||
896 | break; | 919 | break; |
897 | } | 920 | } |
898 | } else if (!is_si_special(info)) { | 921 | } else if (!is_si_special(info)) { |
899 | if (sig >= SIGRTMIN && info->si_code != SI_USER) | 922 | if (sig >= SIGRTMIN && info->si_code != SI_USER) { |
900 | /* | 923 | /* |
901 | * Queue overflow, abort. We may abort if the signal was rt | 924 | * Queue overflow, abort. We may abort if the |
902 | * and sent by user using something other than kill(). | 925 | * signal was rt and sent by user using something |
903 | */ | 926 | * other than kill(). |
927 | */ | ||
928 | trace_signal_overflow_fail(sig, group, info); | ||
904 | return -EAGAIN; | 929 | return -EAGAIN; |
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 | } | ||
905 | } | 937 | } |
906 | 938 | ||
907 | out_set: | 939 | out_set: |
@@ -925,8 +957,6 @@ static int send_signal(int sig, struct siginfo *info, struct task_struct *t, | |||
925 | return __send_signal(sig, info, t, group, from_ancestor_ns); | 957 | return __send_signal(sig, info, t, group, from_ancestor_ns); |
926 | } | 958 | } |
927 | 959 | ||
928 | int print_fatal_signals; | ||
929 | |||
930 | static void print_fatal_signal(struct pt_regs *regs, int signr) | 960 | static void print_fatal_signal(struct pt_regs *regs, int signr) |
931 | { | 961 | { |
932 | printk("%s/%d: potentially unexpected fatal signal %d.\n", | 962 | printk("%s/%d: potentially unexpected fatal signal %d.\n", |
@@ -1293,19 +1323,19 @@ EXPORT_SYMBOL(kill_pid); | |||
1293 | * These functions support sending signals using preallocated sigqueue | 1323 | * These functions support sending signals using preallocated sigqueue |
1294 | * structures. This is needed "because realtime applications cannot | 1324 | * structures. This is needed "because realtime applications cannot |
1295 | * afford to lose notifications of asynchronous events, like timer | 1325 | * afford to lose notifications of asynchronous events, like timer |
1296 | * expirations or I/O completions". In the case of Posix Timers | 1326 | * expirations or I/O completions". In the case of Posix Timers |
1297 | * we allocate the sigqueue structure from the timer_create. If this | 1327 | * we allocate the sigqueue structure from the timer_create. If this |
1298 | * allocation fails we are able to report the failure to the application | 1328 | * allocation fails we are able to report the failure to the application |
1299 | * with an EAGAIN error. | 1329 | * with an EAGAIN error. |
1300 | */ | 1330 | */ |
1301 | |||
1302 | struct sigqueue *sigqueue_alloc(void) | 1331 | struct sigqueue *sigqueue_alloc(void) |
1303 | { | 1332 | { |
1304 | struct sigqueue *q; | 1333 | struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0); |
1305 | 1334 | ||
1306 | if ((q = __sigqueue_alloc(current, GFP_KERNEL, 0))) | 1335 | if (q) |
1307 | q->flags |= SIGQUEUE_PREALLOC; | 1336 | q->flags |= SIGQUEUE_PREALLOC; |
1308 | return(q); | 1337 | |
1338 | return q; | ||
1309 | } | 1339 | } |
1310 | 1340 | ||
1311 | void sigqueue_free(struct sigqueue *q) | 1341 | void sigqueue_free(struct sigqueue *q) |
@@ -1839,6 +1869,9 @@ relock: | |||
1839 | ka = &sighand->action[signr-1]; | 1869 | ka = &sighand->action[signr-1]; |
1840 | } | 1870 | } |
1841 | 1871 | ||
1872 | /* Trace actually delivered signals. */ | ||
1873 | trace_signal_deliver(signr, info, ka); | ||
1874 | |||
1842 | if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ | 1875 | if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ |
1843 | continue; | 1876 | continue; |
1844 | if (ka->sa.sa_handler != SIG_DFL) { | 1877 | if (ka->sa.sa_handler != SIG_DFL) { |