Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 3 | * Copyright 2010 Tilera Corporation. All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation, version 2. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 12 | * NON INFRINGEMENT. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/sched.h> |
Ingo Molnar | b17b015 | 2017-02-08 18:51:35 +0100 | [diff] [blame] | 17 | #include <linux/sched/debug.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 18 | #include <linux/sched/task_stack.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 19 | #include <linux/mm.h> |
| 20 | #include <linux/smp.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/signal.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/wait.h> |
| 25 | #include <linux/unistd.h> |
| 26 | #include <linux/stddef.h> |
| 27 | #include <linux/personality.h> |
| 28 | #include <linux/suspend.h> |
| 29 | #include <linux/ptrace.h> |
| 30 | #include <linux/elf.h> |
| 31 | #include <linux/compat.h> |
| 32 | #include <linux/syscalls.h> |
| 33 | #include <linux/uaccess.h> |
| 34 | #include <asm/processor.h> |
| 35 | #include <asm/ucontext.h> |
| 36 | #include <asm/sigframe.h> |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 37 | #include <asm/syscalls.h> |
Chris Metcalf | 4a556f4 | 2013-08-07 15:33:32 -0400 | [diff] [blame] | 38 | #include <asm/vdso.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 39 | #include <arch/interrupts.h> |
| 40 | |
| 41 | #define DEBUG_SIG 0 |
| 42 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 43 | /* |
| 44 | * Do a signal return; undo the signal stack. |
| 45 | */ |
| 46 | |
| 47 | int restore_sigcontext(struct pt_regs *regs, |
Chris Metcalf | 81711ce | 2010-12-14 16:07:25 -0500 | [diff] [blame] | 48 | struct sigcontext __user *sc) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 49 | { |
Chen Gang | 01f7ae0 | 2014-11-02 10:13:11 +0800 | [diff] [blame] | 50 | int err; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 51 | |
| 52 | /* Always make any pending restarted system calls return -EINTR */ |
Andy Lutomirski | f56141e | 2015-02-12 15:01:14 -0800 | [diff] [blame] | 53 | current->restart_block.fn = do_no_restart_syscall; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 54 | |
Chris Metcalf | 74fca9d | 2010-09-15 11:16:08 -0400 | [diff] [blame] | 55 | /* |
| 56 | * Enforce that sigcontext is like pt_regs, and doesn't mess |
| 57 | * up our stack alignment rules. |
| 58 | */ |
| 59 | BUILD_BUG_ON(sizeof(struct sigcontext) != sizeof(struct pt_regs)); |
| 60 | BUILD_BUG_ON(sizeof(struct sigcontext) % 8 != 0); |
Chen Gang | 01f7ae0 | 2014-11-02 10:13:11 +0800 | [diff] [blame] | 61 | err = __copy_from_user(regs, sc, sizeof(*regs)); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 62 | |
Chris Metcalf | 1deb9c5 | 2010-10-28 15:47:06 -0400 | [diff] [blame] | 63 | /* Ensure that the PL is always set to USER_PL. */ |
| 64 | regs->ex1 = PL_ICS_EX1(USER_PL, EX1_ICS(regs->ex1)); |
| 65 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 66 | regs->faultnum = INT_SWINT_1_SIGRETURN; |
| 67 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 68 | return err; |
| 69 | } |
| 70 | |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 71 | void signal_fault(const char *type, struct pt_regs *regs, |
| 72 | void __user *frame, int sig) |
| 73 | { |
| 74 | trace_unhandled_signal(type, regs, (unsigned long)frame, SIGSEGV); |
| 75 | force_sigsegv(sig, current); |
| 76 | } |
| 77 | |
Chris Metcalf | 81711ce | 2010-12-14 16:07:25 -0500 | [diff] [blame] | 78 | /* The assembly shim for this function arranges to ignore the return value. */ |
Chris Metcalf | 6b14e41 | 2012-10-23 13:30:54 -0400 | [diff] [blame] | 79 | SYSCALL_DEFINE0(rt_sigreturn) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 80 | { |
Chris Metcalf | 6b14e41 | 2012-10-23 13:30:54 -0400 | [diff] [blame] | 81 | struct pt_regs *regs = current_pt_regs(); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 82 | struct rt_sigframe __user *frame = |
| 83 | (struct rt_sigframe __user *)(regs->sp); |
| 84 | sigset_t set; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 85 | |
| 86 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 87 | goto badframe; |
| 88 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 89 | goto badframe; |
| 90 | |
Matt Fleming | ad09233 | 2012-02-14 11:41:06 +0000 | [diff] [blame] | 91 | set_current_blocked(&set); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 92 | |
Chris Metcalf | 81711ce | 2010-12-14 16:07:25 -0500 | [diff] [blame] | 93 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 94 | goto badframe; |
| 95 | |
Al Viro | 47669ab | 2012-12-23 03:50:34 -0500 | [diff] [blame] | 96 | if (restore_altstack(&frame->uc.uc_stack)) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 97 | goto badframe; |
| 98 | |
Chris Metcalf | 81711ce | 2010-12-14 16:07:25 -0500 | [diff] [blame] | 99 | return 0; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 100 | |
| 101 | badframe: |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 102 | signal_fault("bad sigreturn frame", regs, frame, 0); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Set up a signal frame. |
| 108 | */ |
| 109 | |
| 110 | int setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs) |
| 111 | { |
Chen Gang | 01f7ae0 | 2014-11-02 10:13:11 +0800 | [diff] [blame] | 112 | return __copy_to_user(sc, regs, sizeof(*regs)); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Determine which stack to use.. |
| 117 | */ |
| 118 | static inline void __user *get_sigframe(struct k_sigaction *ka, |
| 119 | struct pt_regs *regs, |
| 120 | size_t frame_size) |
| 121 | { |
| 122 | unsigned long sp; |
| 123 | |
| 124 | /* Default to using normal stack */ |
| 125 | sp = regs->sp; |
| 126 | |
| 127 | /* |
| 128 | * If we are on the alternate signal stack and would overflow |
| 129 | * it, don't. Return an always-bogus address instead so we |
| 130 | * will die with SIGSEGV. |
| 131 | */ |
| 132 | if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size))) |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 133 | return (void __user __force *)-1UL; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 134 | |
| 135 | /* This is the X/Open sanctioned signal stack switching. */ |
| 136 | if (ka->sa.sa_flags & SA_ONSTACK) { |
| 137 | if (sas_ss_flags(sp) == 0) |
| 138 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 139 | } |
| 140 | |
| 141 | sp -= frame_size; |
| 142 | /* |
| 143 | * Align the stack pointer according to the TILE ABI, |
| 144 | * i.e. so that on function entry (sp & 15) == 0. |
| 145 | */ |
| 146 | sp &= -16UL; |
| 147 | return (void __user *) sp; |
| 148 | } |
| 149 | |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 150 | static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, |
| 151 | struct pt_regs *regs) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 152 | { |
| 153 | unsigned long restorer; |
| 154 | struct rt_sigframe __user *frame; |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 155 | int err = 0, sig = ksig->sig; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 156 | |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 157 | frame = get_sigframe(&ksig->ka, regs, sizeof(*frame)); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 158 | |
| 159 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 160 | goto err; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 161 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 162 | /* Always write at least the signal number for the stack backtracer. */ |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 163 | if (ksig->ka.sa.sa_flags & SA_SIGINFO) { |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 164 | /* At sigreturn time, restore the callee-save registers too. */ |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 165 | err |= copy_siginfo_to_user(&frame->info, &ksig->info); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 166 | regs->flags |= PT_FLAGS_RESTORE_REGS; |
| 167 | } else { |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 168 | err |= __put_user(ksig->info.si_signo, &frame->info.si_signo); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* Create the ucontext. */ |
| 172 | err |= __clear_user(&frame->save_area, sizeof(frame->save_area)); |
| 173 | err |= __put_user(0, &frame->uc.uc_flags); |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 174 | err |= __put_user(NULL, &frame->uc.uc_link); |
Al Viro | 47669ab | 2012-12-23 03:50:34 -0500 | [diff] [blame] | 175 | err |= __save_altstack(&frame->uc.uc_stack, regs->sp); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 176 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs); |
| 177 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 178 | if (err) |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 179 | goto err; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 180 | |
Chris Metcalf | 4a556f4 | 2013-08-07 15:33:32 -0400 | [diff] [blame] | 181 | restorer = VDSO_SYM(&__vdso_rt_sigreturn); |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 182 | if (ksig->ka.sa.sa_flags & SA_RESTORER) |
| 183 | restorer = (unsigned long) ksig->ka.sa.sa_restorer; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Set up registers for signal handler. |
| 187 | * Registers that we don't modify keep the value they had from |
| 188 | * user-space at the time we took the signal. |
Chris Metcalf | 74fca9d | 2010-09-15 11:16:08 -0400 | [diff] [blame] | 189 | * We always pass siginfo and mcontext, regardless of SA_SIGINFO, |
| 190 | * since some things rely on this (e.g. glibc's debug/segfault.c). |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 191 | */ |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 192 | regs->pc = (unsigned long) ksig->ka.sa.sa_handler; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 193 | regs->ex1 = PL_ICS_EX1(USER_PL, 1); /* set crit sec in handler */ |
| 194 | regs->sp = (unsigned long) frame; |
| 195 | regs->lr = restorer; |
Richard Weinberger | 89f191b | 2014-07-13 17:40:49 +0200 | [diff] [blame] | 196 | regs->regs[0] = (unsigned long) sig; |
Chris Metcalf | 74fca9d | 2010-09-15 11:16:08 -0400 | [diff] [blame] | 197 | regs->regs[1] = (unsigned long) &frame->info; |
| 198 | regs->regs[2] = (unsigned long) &frame->uc; |
| 199 | regs->flags |= PT_FLAGS_CALLER_SAVES; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 200 | return 0; |
| 201 | |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 202 | err: |
| 203 | trace_unhandled_signal("bad sigreturn frame", regs, |
| 204 | (unsigned long)frame, SIGSEGV); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 205 | return -EFAULT; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * OK, we're invoking a handler |
| 210 | */ |
| 211 | |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 212 | static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 213 | { |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 214 | sigset_t *oldset = sigmask_to_save(); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 215 | int ret; |
| 216 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 217 | /* Are we from a system call? */ |
| 218 | if (regs->faultnum == INT_SWINT_1) { |
| 219 | /* If so, check system call restarting.. */ |
| 220 | switch (regs->regs[0]) { |
| 221 | case -ERESTART_RESTARTBLOCK: |
| 222 | case -ERESTARTNOHAND: |
| 223 | regs->regs[0] = -EINTR; |
| 224 | break; |
| 225 | |
| 226 | case -ERESTARTSYS: |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 227 | if (!(ksig->ka.sa.sa_flags & SA_RESTART)) { |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 228 | regs->regs[0] = -EINTR; |
| 229 | break; |
| 230 | } |
| 231 | /* fallthrough */ |
| 232 | case -ERESTARTNOINTR: |
| 233 | /* Reload caller-saves to restore r0..r5 and r10. */ |
| 234 | regs->flags |= PT_FLAGS_CALLER_SAVES; |
| 235 | regs->regs[0] = regs->orig_r0; |
| 236 | regs->pc -= 8; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /* Set up the stack frame */ |
| 241 | #ifdef CONFIG_COMPAT |
| 242 | if (is_compat_task()) |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 243 | ret = compat_setup_rt_frame(ksig, oldset, regs); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 244 | else |
| 245 | #endif |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 246 | ret = setup_rt_frame(ksig, oldset, regs); |
| 247 | |
| 248 | signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP)); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 253 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 254 | * mistake. |
| 255 | */ |
| 256 | void do_signal(struct pt_regs *regs) |
| 257 | { |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 258 | struct ksignal ksig; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * i386 will check if we're coming from kernel mode and bail out |
| 262 | * here. In my experience this just turns weird crashes into |
| 263 | * weird spin-hangs. But if we find a case where this seems |
| 264 | * helpful, we can reinstate the check on "!user_mode(regs)". |
| 265 | */ |
| 266 | |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 267 | if (get_signal(&ksig)) { |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 268 | /* Whee! Actually deliver the signal. */ |
Richard Weinberger | b3707c7 | 2013-10-07 15:01:08 +0200 | [diff] [blame] | 269 | handle_signal(&ksig, regs); |
Chris Metcalf | 34a89d2 | 2010-10-28 15:03:30 -0400 | [diff] [blame] | 270 | goto done; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* Did we come from a system call? */ |
| 274 | if (regs->faultnum == INT_SWINT_1) { |
| 275 | /* Restart the system call - no handlers present */ |
| 276 | switch (regs->regs[0]) { |
| 277 | case -ERESTARTNOHAND: |
| 278 | case -ERESTARTSYS: |
| 279 | case -ERESTARTNOINTR: |
| 280 | regs->flags |= PT_FLAGS_CALLER_SAVES; |
| 281 | regs->regs[0] = regs->orig_r0; |
| 282 | regs->pc -= 8; |
| 283 | break; |
| 284 | |
| 285 | case -ERESTART_RESTARTBLOCK: |
| 286 | regs->flags |= PT_FLAGS_CALLER_SAVES; |
| 287 | regs->regs[TREG_SYSCALL_NR] = __NR_restart_syscall; |
| 288 | regs->pc -= 8; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /* If there's no signal to deliver, just put the saved sigmask back. */ |
Al Viro | 51a7b44 | 2012-05-21 23:33:55 -0400 | [diff] [blame] | 294 | restore_saved_sigmask(); |
Chris Metcalf | 34a89d2 | 2010-10-28 15:03:30 -0400 | [diff] [blame] | 295 | |
| 296 | done: |
| 297 | /* Avoid double syscall restart if there are nested signals. */ |
| 298 | regs->faultnum = INT_SWINT_1_SIGRETURN; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 299 | } |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 300 | |
| 301 | int show_unhandled_signals = 1; |
| 302 | |
| 303 | static int __init crashinfo(char *str) |
| 304 | { |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 305 | const char *word; |
| 306 | |
| 307 | if (*str == '\0') |
Daniel Walter | b2dfa04 | 2014-05-26 22:59:32 +0100 | [diff] [blame] | 308 | show_unhandled_signals = 2; |
| 309 | else if (*str != '=' || kstrtoint(++str, 0, &show_unhandled_signals) != 0) |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 310 | return 0; |
Daniel Walter | b2dfa04 | 2014-05-26 22:59:32 +0100 | [diff] [blame] | 311 | |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 312 | switch (show_unhandled_signals) { |
| 313 | case 0: |
| 314 | word = "No"; |
| 315 | break; |
| 316 | case 1: |
| 317 | word = "One-line"; |
| 318 | break; |
| 319 | default: |
| 320 | word = "Detailed"; |
| 321 | break; |
| 322 | } |
| 323 | pr_info("%s crash reports will be generated on the console\n", word); |
| 324 | return 1; |
| 325 | } |
| 326 | __setup("crashinfo", crashinfo); |
| 327 | |
| 328 | static void dump_mem(void __user *address) |
| 329 | { |
| 330 | void __user *addr; |
| 331 | enum { region_size = 256, bytes_per_line = 16 }; |
| 332 | int i, j, k; |
| 333 | int found_readable_mem = 0; |
| 334 | |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 335 | if (!access_ok(VERIFY_READ, address, 1)) { |
| 336 | pr_err("Not dumping at address 0x%lx (kernel address)\n", |
| 337 | (unsigned long)address); |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | addr = (void __user *) |
| 342 | (((unsigned long)address & -bytes_per_line) - region_size/2); |
| 343 | if (addr > address) |
| 344 | addr = NULL; |
| 345 | for (i = 0; i < region_size; |
| 346 | addr += bytes_per_line, i += bytes_per_line) { |
| 347 | unsigned char buf[bytes_per_line]; |
| 348 | char line[100]; |
| 349 | if (copy_from_user(buf, addr, bytes_per_line)) |
| 350 | continue; |
| 351 | if (!found_readable_mem) { |
| 352 | pr_err("Dumping memory around address 0x%lx:\n", |
| 353 | (unsigned long)address); |
| 354 | found_readable_mem = 1; |
| 355 | } |
Joe Perches | f474367 | 2014-10-31 10:50:46 -0700 | [diff] [blame] | 356 | j = sprintf(line, REGFMT ":", (unsigned long)addr); |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 357 | for (k = 0; k < bytes_per_line; ++k) |
| 358 | j += sprintf(&line[j], " %02x", buf[k]); |
| 359 | pr_err("%s\n", line); |
| 360 | } |
| 361 | if (!found_readable_mem) |
| 362 | pr_err("No readable memory around address 0x%lx\n", |
| 363 | (unsigned long)address); |
| 364 | } |
| 365 | |
| 366 | void trace_unhandled_signal(const char *type, struct pt_regs *regs, |
| 367 | unsigned long address, int sig) |
| 368 | { |
| 369 | struct task_struct *tsk = current; |
| 370 | |
| 371 | if (show_unhandled_signals == 0) |
| 372 | return; |
| 373 | |
| 374 | /* If the signal is handled, don't show it here. */ |
| 375 | if (!is_global_init(tsk)) { |
| 376 | void __user *handler = |
| 377 | tsk->sighand->action[sig-1].sa.sa_handler; |
| 378 | if (handler != SIG_IGN && handler != SIG_DFL) |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | /* Rate-limit the one-line output, not the detailed output. */ |
| 383 | if (show_unhandled_signals <= 1 && !printk_ratelimit()) |
| 384 | return; |
| 385 | |
| 386 | printk("%s%s[%d]: %s at %lx pc "REGFMT" signal %d", |
| 387 | task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, |
| 388 | tsk->comm, task_pid_nr(tsk), type, address, regs->pc, sig); |
| 389 | |
| 390 | print_vma_addr(KERN_CONT " in ", regs->pc); |
| 391 | |
| 392 | printk(KERN_CONT "\n"); |
| 393 | |
| 394 | if (show_unhandled_signals > 1) { |
| 395 | switch (sig) { |
| 396 | case SIGILL: |
| 397 | case SIGFPE: |
| 398 | case SIGSEGV: |
| 399 | case SIGBUS: |
Joe Perches | f474367 | 2014-10-31 10:50:46 -0700 | [diff] [blame] | 400 | pr_err("User crash: signal %d, trap %ld, address 0x%lx\n", |
Chris Metcalf | 571d76a | 2011-05-16 14:23:44 -0400 | [diff] [blame] | 401 | sig, regs->faultnum, address); |
| 402 | show_regs(regs); |
| 403 | dump_mem((void __user *)address); |
| 404 | break; |
| 405 | default: |
| 406 | pr_err("User crash: signal %d, trap %ld\n", |
| 407 | sig, regs->faultnum); |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | } |