Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 6 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 7 | * 2000-2002 x86-64 support by Andi Kleen |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 9 | |
| 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 12 | #include <linux/sched.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 13 | #include <linux/mm.h> |
Hiroshi Shimamoto | 5c9b3a0 | 2008-11-21 17:36:41 -0800 | [diff] [blame] | 14 | #include <linux/smp.h> |
| 15 | #include <linux/kernel.h> |
Hiroshi Shimamoto | 5c9b3a0 | 2008-11-21 17:36:41 -0800 | [diff] [blame] | 16 | #include <linux/errno.h> |
| 17 | #include <linux/wait.h> |
Hiroshi Shimamoto | 5c9b3a0 | 2008-11-21 17:36:41 -0800 | [diff] [blame] | 18 | #include <linux/tracehook.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/stddef.h> |
| 21 | #include <linux/personality.h> |
| 22 | #include <linux/uaccess.h> |
Avi Kivity | 7c68af6 | 2009-09-19 09:40:22 +0300 | [diff] [blame] | 23 | #include <linux/user-return-notifier.h> |
Srikar Dronamraju | 0326f5a | 2012-03-13 23:30:11 +0530 | [diff] [blame] | 24 | #include <linux/uprobes.h> |
Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame^] | 25 | #include <linux/context_tracking.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/processor.h> |
| 28 | #include <asm/ucontext.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/i387.h> |
Linus Torvalds | 1361b83 | 2012-02-21 13:19:22 -0800 | [diff] [blame] | 30 | #include <asm/fpu-internal.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 31 | #include <asm/vdso.h> |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 32 | #include <asm/mce.h> |
H. Peter Anvin | f28f0c2 | 2012-02-19 07:38:43 -0800 | [diff] [blame] | 33 | #include <asm/sighandling.h> |
Hiroshi Shimamoto | 5c9b3a0 | 2008-11-21 17:36:41 -0800 | [diff] [blame] | 34 | |
| 35 | #ifdef CONFIG_X86_64 |
| 36 | #include <asm/proto.h> |
| 37 | #include <asm/ia32_unistd.h> |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 38 | #include <asm/sys_ia32.h> |
Hiroshi Shimamoto | 5c9b3a0 | 2008-11-21 17:36:41 -0800 | [diff] [blame] | 39 | #endif /* CONFIG_X86_64 */ |
| 40 | |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 41 | #include <asm/syscall.h> |
Jaswinder Singh | bbc1f69 | 2008-07-21 21:34:13 +0530 | [diff] [blame] | 42 | #include <asm/syscalls.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 43 | |
Hiroshi Shimamoto | 41af86f | 2008-12-17 18:50:32 -0800 | [diff] [blame] | 44 | #include <asm/sigframe.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Harvey Harrison | 1a17680 | 2008-02-08 12:09:59 -0800 | [diff] [blame] | 46 | #ifdef CONFIG_X86_32 |
| 47 | # define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF) |
| 48 | #else |
| 49 | # define FIX_EFLAGS __FIX_EFLAGS |
| 50 | #endif |
| 51 | |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 52 | #define COPY(x) do { \ |
| 53 | get_user_ex(regs->x, &sc->x); \ |
| 54 | } while (0) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 55 | |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 56 | #define GET_SEG(seg) ({ \ |
| 57 | unsigned short tmp; \ |
| 58 | get_user_ex(tmp, &sc->seg); \ |
| 59 | tmp; \ |
| 60 | }) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 61 | |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 62 | #define COPY_SEG(seg) do { \ |
| 63 | regs->seg = GET_SEG(seg); \ |
| 64 | } while (0) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 65 | |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 66 | #define COPY_SEG_CPL3(seg) do { \ |
| 67 | regs->seg = GET_SEG(seg) | 3; \ |
| 68 | } while (0) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 69 | |
H. Peter Anvin | 8513942 | 2012-02-19 07:43:09 -0800 | [diff] [blame] | 70 | int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, |
| 71 | unsigned long *pax) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 72 | { |
| 73 | void __user *buf; |
| 74 | unsigned int tmpflags; |
| 75 | unsigned int err = 0; |
| 76 | |
| 77 | /* Always make any pending restarted system calls return -EINTR */ |
| 78 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 79 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 80 | get_user_try { |
| 81 | |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 82 | #ifdef CONFIG_X86_32 |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 83 | set_user_gs(regs, GET_SEG(gs)); |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 84 | COPY_SEG(fs); |
| 85 | COPY_SEG(es); |
| 86 | COPY_SEG(ds); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 87 | #endif /* CONFIG_X86_32 */ |
| 88 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 89 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); |
| 90 | COPY(dx); COPY(cx); COPY(ip); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 91 | |
| 92 | #ifdef CONFIG_X86_64 |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 93 | COPY(r8); |
| 94 | COPY(r9); |
| 95 | COPY(r10); |
| 96 | COPY(r11); |
| 97 | COPY(r12); |
| 98 | COPY(r13); |
| 99 | COPY(r14); |
| 100 | COPY(r15); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 101 | #endif /* CONFIG_X86_64 */ |
| 102 | |
| 103 | #ifdef CONFIG_X86_32 |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 104 | COPY_SEG_CPL3(cs); |
| 105 | COPY_SEG_CPL3(ss); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 106 | #else /* !CONFIG_X86_32 */ |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 107 | /* Kernel saves and restores only the CS segment register on signals, |
| 108 | * which is the bare minimum needed to allow mixed 32/64-bit code. |
| 109 | * App's signal handler can save/restore other segments if needed. */ |
| 110 | COPY_SEG_CPL3(cs); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 111 | #endif /* CONFIG_X86_32 */ |
| 112 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 113 | get_user_ex(tmpflags, &sc->flags); |
| 114 | regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); |
| 115 | regs->orig_ax = -1; /* disable syscall checks */ |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 116 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 117 | get_user_ex(buf, &sc->fpstate); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 118 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 119 | get_user_ex(*pax, &sc->ax); |
| 120 | } get_user_catch(err); |
| 121 | |
H. Peter Anvin | 49b8c695 | 2012-09-21 17:18:44 -0700 | [diff] [blame] | 122 | err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32)); |
H. Peter Anvin | 5e88353 | 2012-09-21 12:43:15 -0700 | [diff] [blame] | 123 | |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 124 | return err; |
| 125 | } |
| 126 | |
H. Peter Anvin | 8513942 | 2012-02-19 07:43:09 -0800 | [diff] [blame] | 127 | int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, |
| 128 | struct pt_regs *regs, unsigned long mask) |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 129 | { |
| 130 | int err = 0; |
| 131 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 132 | put_user_try { |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 133 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 134 | #ifdef CONFIG_X86_32 |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 135 | put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs); |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 136 | put_user_ex(regs->fs, (unsigned int __user *)&sc->fs); |
| 137 | put_user_ex(regs->es, (unsigned int __user *)&sc->es); |
| 138 | put_user_ex(regs->ds, (unsigned int __user *)&sc->ds); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 139 | #endif /* CONFIG_X86_32 */ |
| 140 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 141 | put_user_ex(regs->di, &sc->di); |
| 142 | put_user_ex(regs->si, &sc->si); |
| 143 | put_user_ex(regs->bp, &sc->bp); |
| 144 | put_user_ex(regs->sp, &sc->sp); |
| 145 | put_user_ex(regs->bx, &sc->bx); |
| 146 | put_user_ex(regs->dx, &sc->dx); |
| 147 | put_user_ex(regs->cx, &sc->cx); |
| 148 | put_user_ex(regs->ax, &sc->ax); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 149 | #ifdef CONFIG_X86_64 |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 150 | put_user_ex(regs->r8, &sc->r8); |
| 151 | put_user_ex(regs->r9, &sc->r9); |
| 152 | put_user_ex(regs->r10, &sc->r10); |
| 153 | put_user_ex(regs->r11, &sc->r11); |
| 154 | put_user_ex(regs->r12, &sc->r12); |
| 155 | put_user_ex(regs->r13, &sc->r13); |
| 156 | put_user_ex(regs->r14, &sc->r14); |
| 157 | put_user_ex(regs->r15, &sc->r15); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 158 | #endif /* CONFIG_X86_64 */ |
| 159 | |
Srikar Dronamraju | 51e7dc7 | 2012-03-12 14:55:55 +0530 | [diff] [blame] | 160 | put_user_ex(current->thread.trap_nr, &sc->trapno); |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 161 | put_user_ex(current->thread.error_code, &sc->err); |
| 162 | put_user_ex(regs->ip, &sc->ip); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 163 | #ifdef CONFIG_X86_32 |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 164 | put_user_ex(regs->cs, (unsigned int __user *)&sc->cs); |
| 165 | put_user_ex(regs->flags, &sc->flags); |
| 166 | put_user_ex(regs->sp, &sc->sp_at_signal); |
| 167 | put_user_ex(regs->ss, (unsigned int __user *)&sc->ss); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 168 | #else /* !CONFIG_X86_32 */ |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 169 | put_user_ex(regs->flags, &sc->flags); |
| 170 | put_user_ex(regs->cs, &sc->cs); |
| 171 | put_user_ex(0, &sc->gs); |
| 172 | put_user_ex(0, &sc->fs); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 173 | #endif /* CONFIG_X86_32 */ |
| 174 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 175 | put_user_ex(fpstate, &sc->fpstate); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 176 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 177 | /* non-iBCS2 extensions.. */ |
| 178 | put_user_ex(mask, &sc->oldmask); |
| 179 | put_user_ex(current->thread.cr2, &sc->cr2); |
| 180 | } put_user_catch(err); |
Hiroshi Shimamoto | 2601657 | 2008-11-24 18:21:37 -0800 | [diff] [blame] | 181 | |
| 182 | return err; |
| 183 | } |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | * Set up a signal frame. |
| 187 | */ |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Determine which stack to use.. |
| 191 | */ |
Hiroshi Shimamoto | 1fae027 | 2009-02-27 10:30:32 -0800 | [diff] [blame] | 192 | static unsigned long align_sigframe(unsigned long sp) |
| 193 | { |
| 194 | #ifdef CONFIG_X86_32 |
| 195 | /* |
| 196 | * Align the stack pointer according to the i386 ABI, |
| 197 | * i.e. so that on function entry ((sp + 4) & 15) == 0. |
| 198 | */ |
| 199 | sp = ((sp + 4) & -16ul) - 4; |
| 200 | #else /* !CONFIG_X86_32 */ |
| 201 | sp = round_down(sp, 16) - 8; |
| 202 | #endif |
| 203 | return sp; |
| 204 | } |
| 205 | |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 206 | static inline void __user * |
| 207 | get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size, |
| 208 | void __user **fpstate) |
| 209 | { |
| 210 | /* Default to using normal stack */ |
Suresh Siddha | 72a671c | 2012-07-24 16:05:29 -0700 | [diff] [blame] | 211 | unsigned long math_size = 0; |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 212 | unsigned long sp = regs->sp; |
Suresh Siddha | 72a671c | 2012-07-24 16:05:29 -0700 | [diff] [blame] | 213 | unsigned long buf_fx = 0; |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 214 | int onsigstack = on_sig_stack(sp); |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 215 | |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 216 | /* redzone */ |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 217 | if (config_enabled(CONFIG_X86_64)) |
| 218 | sp -= 128; |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 219 | |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 220 | if (!onsigstack) { |
| 221 | /* This is the X/Open sanctioned signal stack switching. */ |
| 222 | if (ka->sa.sa_flags & SA_ONSTACK) { |
Hiroshi Shimamoto | 0f8f308 | 2009-03-26 10:03:08 -0700 | [diff] [blame] | 223 | if (current->sas_ss_size) |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 224 | sp = current->sas_ss_sp + current->sas_ss_size; |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 225 | } else if (config_enabled(CONFIG_X86_32) && |
| 226 | (regs->ss & 0xffff) != __USER_DS && |
| 227 | !(ka->sa.sa_flags & SA_RESTORER) && |
| 228 | ka->sa.sa_restorer) { |
| 229 | /* This is the legacy signal stack switching. */ |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 230 | sp = (unsigned long) ka->sa.sa_restorer; |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 231 | } |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (used_math()) { |
Suresh Siddha | 72a671c | 2012-07-24 16:05:29 -0700 | [diff] [blame] | 235 | sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32), |
| 236 | &buf_fx, &math_size); |
Hiroshi Shimamoto | 2505170 | 2009-03-02 17:20:01 -0800 | [diff] [blame] | 237 | *fpstate = (void __user *)sp; |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 240 | sp = align_sigframe(sp - frame_size); |
| 241 | |
| 242 | /* |
| 243 | * If we are on the alternate signal stack and would overflow it, don't. |
| 244 | * Return an always-bogus address instead so we will die with SIGSEGV. |
| 245 | */ |
| 246 | if (onsigstack && !likely(on_sig_stack(sp))) |
| 247 | return (void __user *)-1L; |
| 248 | |
Suresh Siddha | 72a671c | 2012-07-24 16:05:29 -0700 | [diff] [blame] | 249 | /* save i387 and extended state */ |
| 250 | if (used_math() && |
| 251 | save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0) |
Hiroshi Shimamoto | 14fc9fb | 2009-03-19 10:56:29 -0700 | [diff] [blame] | 252 | return (void __user *)-1L; |
| 253 | |
| 254 | return (void __user *)sp; |
Hiroshi Shimamoto | 75779f0 | 2009-02-27 10:29:57 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 257 | #ifdef CONFIG_X86_32 |
| 258 | static const struct { |
| 259 | u16 poplmovl; |
| 260 | u32 val; |
| 261 | u16 int80; |
| 262 | } __attribute__((packed)) retcode = { |
| 263 | 0xb858, /* popl %eax; movl $..., %eax */ |
| 264 | __NR_sigreturn, |
| 265 | 0x80cd, /* int $0x80 */ |
| 266 | }; |
| 267 | |
| 268 | static const struct { |
| 269 | u8 movl; |
| 270 | u32 val; |
| 271 | u16 int80; |
| 272 | u8 pad; |
| 273 | } __attribute__((packed)) rt_retcode = { |
| 274 | 0xb8, /* movl $..., %eax */ |
| 275 | __NR_rt_sigreturn, |
| 276 | 0x80cd, /* int $0x80 */ |
| 277 | 0 |
| 278 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 280 | static int |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 281 | __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, |
| 282 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | struct sigframe __user *frame; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 285 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 287 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 289 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 292 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 294 | if (__put_user(sig, &frame->sig)) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 295 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 297 | if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 298 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | if (_NSIG_WORDS > 1) { |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 301 | if (__copy_to_user(&frame->extramask, &set->sig[1], |
| 302 | sizeof(frame->extramask))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 303 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Roland McGrath | 1a3e4ca | 2008-04-09 01:29:27 -0700 | [diff] [blame] | 306 | if (current->mm->context.vdso) |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 307 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn); |
Andi Kleen | 9fbbd4d | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 308 | else |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 309 | restorer = &frame->retcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (ka->sa.sa_flags & SA_RESTORER) |
| 311 | restorer = ka->sa.sa_restorer; |
| 312 | |
| 313 | /* Set up to return from userspace. */ |
| 314 | err |= __put_user(restorer, &frame->pretcode); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 317 | * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | * |
| 319 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 320 | * reasons and because gdb uses it as a signature to notice |
| 321 | * signal handler stack frames. |
| 322 | */ |
Hiroshi Shimamoto | 4a61204 | 2008-11-11 19:09:29 -0800 | [diff] [blame] | 323 | err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 326 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | /* Set up registers for signal handler */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 329 | regs->sp = (unsigned long)frame; |
| 330 | regs->ip = (unsigned long)ka->sa.sa_handler; |
| 331 | regs->ax = (unsigned long)sig; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 332 | regs->dx = 0; |
| 333 | regs->cx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 335 | regs->ds = __USER_DS; |
| 336 | regs->es = __USER_DS; |
| 337 | regs->ss = __USER_DS; |
| 338 | regs->cs = __USER_CS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 340 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 343 | static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
| 344 | sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | struct rt_sigframe __user *frame; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 347 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 349 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 351 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 354 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 356 | put_user_try { |
| 357 | put_user_ex(sig, &frame->sig); |
| 358 | put_user_ex(&frame->info, &frame->pinfo); |
| 359 | put_user_ex(&frame->uc, &frame->puc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 361 | /* Create the ucontext. */ |
| 362 | if (cpu_has_xsave) |
| 363 | put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags); |
| 364 | else |
| 365 | put_user_ex(0, &frame->uc.uc_flags); |
| 366 | put_user_ex(0, &frame->uc.uc_link); |
| 367 | put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
| 368 | put_user_ex(sas_ss_flags(regs->sp), |
| 369 | &frame->uc.uc_stack.ss_flags); |
| 370 | put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 372 | /* Set up to return from userspace. */ |
| 373 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); |
| 374 | if (ka->sa.sa_flags & SA_RESTORER) |
| 375 | restorer = ka->sa.sa_restorer; |
| 376 | put_user_ex(restorer, &frame->pretcode); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 377 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 378 | /* |
| 379 | * This is movl $__NR_rt_sigreturn, %ax ; int $0x80 |
| 380 | * |
| 381 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 382 | * reasons and because gdb uses it as a signature to notice |
| 383 | * signal handler stack frames. |
| 384 | */ |
| 385 | put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode); |
| 386 | } put_user_catch(err); |
H. Peter Anvin | 49b8c695 | 2012-09-21 17:18:44 -0700 | [diff] [blame] | 387 | |
H. Peter Anvin | 5e88353 | 2012-09-21 12:43:15 -0700 | [diff] [blame] | 388 | err |= copy_siginfo_to_user(&frame->info, info); |
| 389 | err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate, |
| 390 | regs, set->sig[0]); |
| 391 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 394 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /* Set up registers for signal handler */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 397 | regs->sp = (unsigned long)frame; |
| 398 | regs->ip = (unsigned long)ka->sa.sa_handler; |
Hiroshi Shimamoto | 13ad772 | 2008-09-05 16:28:38 -0700 | [diff] [blame] | 399 | regs->ax = (unsigned long)sig; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 400 | regs->dx = (unsigned long)&frame->info; |
| 401 | regs->cx = (unsigned long)&frame->uc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 403 | regs->ds = __USER_DS; |
| 404 | regs->es = __USER_DS; |
| 405 | regs->ss = __USER_DS; |
| 406 | regs->cs = __USER_CS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 408 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 410 | #else /* !CONFIG_X86_32 */ |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 411 | static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
| 412 | sigset_t *set, struct pt_regs *regs) |
| 413 | { |
| 414 | struct rt_sigframe __user *frame; |
| 415 | void __user *fp = NULL; |
| 416 | int err = 0; |
| 417 | struct task_struct *me = current; |
| 418 | |
Hiroshi Shimamoto | 97286a2 | 2009-02-27 10:28:48 -0800 | [diff] [blame] | 419 | frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 420 | |
| 421 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 422 | return -EFAULT; |
| 423 | |
| 424 | if (ka->sa.sa_flags & SA_SIGINFO) { |
| 425 | if (copy_siginfo_to_user(&frame->info, info)) |
| 426 | return -EFAULT; |
| 427 | } |
| 428 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 429 | put_user_try { |
| 430 | /* Create the ucontext. */ |
| 431 | if (cpu_has_xsave) |
| 432 | put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags); |
| 433 | else |
| 434 | put_user_ex(0, &frame->uc.uc_flags); |
| 435 | put_user_ex(0, &frame->uc.uc_link); |
| 436 | put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
| 437 | put_user_ex(sas_ss_flags(regs->sp), |
| 438 | &frame->uc.uc_stack.ss_flags); |
| 439 | put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 440 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 441 | /* Set up to return from userspace. If provided, use a stub |
| 442 | already in userspace. */ |
| 443 | /* x86-64 should always use SA_RESTORER. */ |
| 444 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 445 | put_user_ex(ka->sa.sa_restorer, &frame->pretcode); |
| 446 | } else { |
| 447 | /* could use a vstub here */ |
| 448 | err |= -EFAULT; |
| 449 | } |
| 450 | } put_user_catch(err); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 451 | |
H. Peter Anvin | 5e88353 | 2012-09-21 12:43:15 -0700 | [diff] [blame] | 452 | err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]); |
| 453 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 454 | |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 455 | if (err) |
| 456 | return -EFAULT; |
| 457 | |
| 458 | /* Set up registers for signal handler */ |
| 459 | regs->di = sig; |
| 460 | /* In case the signal handler was declared without prototypes */ |
| 461 | regs->ax = 0; |
| 462 | |
| 463 | /* This also works for non SA_SIGINFO handlers because they expect the |
| 464 | next argument after the signal number on the stack. */ |
| 465 | regs->si = (unsigned long)&frame->info; |
| 466 | regs->dx = (unsigned long)&frame->uc; |
| 467 | regs->ip = (unsigned long) ka->sa.sa_handler; |
| 468 | |
| 469 | regs->sp = (unsigned long)frame; |
| 470 | |
| 471 | /* Set up the CS register to run signal handlers in 64-bit mode, |
| 472 | even if the handler happens to be interrupting 32-bit code. */ |
| 473 | regs->cs = __USER_CS; |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | #endif /* CONFIG_X86_32 */ |
| 478 | |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 479 | static int x32_setup_rt_frame(int sig, struct k_sigaction *ka, |
| 480 | siginfo_t *info, compat_sigset_t *set, |
| 481 | struct pt_regs *regs) |
| 482 | { |
| 483 | #ifdef CONFIG_X86_X32_ABI |
| 484 | struct rt_sigframe_x32 __user *frame; |
| 485 | void __user *restorer; |
| 486 | int err = 0; |
| 487 | void __user *fpstate = NULL; |
| 488 | |
| 489 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
| 490 | |
| 491 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 492 | return -EFAULT; |
| 493 | |
| 494 | if (ka->sa.sa_flags & SA_SIGINFO) { |
| 495 | if (copy_siginfo_to_user32(&frame->info, info)) |
| 496 | return -EFAULT; |
| 497 | } |
| 498 | |
| 499 | put_user_try { |
| 500 | /* Create the ucontext. */ |
| 501 | if (cpu_has_xsave) |
| 502 | put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags); |
| 503 | else |
| 504 | put_user_ex(0, &frame->uc.uc_flags); |
| 505 | put_user_ex(0, &frame->uc.uc_link); |
| 506 | put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
| 507 | put_user_ex(sas_ss_flags(regs->sp), |
| 508 | &frame->uc.uc_stack.ss_flags); |
| 509 | put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 510 | put_user_ex(0, &frame->uc.uc__pad0); |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 511 | |
| 512 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 513 | restorer = ka->sa.sa_restorer; |
| 514 | } else { |
| 515 | /* could use a vstub here */ |
| 516 | restorer = NULL; |
| 517 | err |= -EFAULT; |
| 518 | } |
| 519 | put_user_ex(restorer, &frame->pretcode); |
| 520 | } put_user_catch(err); |
| 521 | |
H. Peter Anvin | 49b8c695 | 2012-09-21 17:18:44 -0700 | [diff] [blame] | 522 | err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate, |
| 523 | regs, set->sig[0]); |
| 524 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 525 | |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 526 | if (err) |
| 527 | return -EFAULT; |
| 528 | |
| 529 | /* Set up registers for signal handler */ |
| 530 | regs->sp = (unsigned long) frame; |
| 531 | regs->ip = (unsigned long) ka->sa.sa_handler; |
| 532 | |
| 533 | /* We use the x32 calling convention here... */ |
| 534 | regs->di = sig; |
| 535 | regs->si = (unsigned long) &frame->info; |
| 536 | regs->dx = (unsigned long) &frame->uc; |
| 537 | |
| 538 | loadsegment(ds, __USER_DS); |
| 539 | loadsegment(es, __USER_DS); |
| 540 | |
| 541 | regs->cs = __USER_CS; |
| 542 | regs->ss = __USER_DS; |
| 543 | #endif /* CONFIG_X86_X32_ABI */ |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 548 | #ifdef CONFIG_X86_32 |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 549 | /* |
| 550 | * Atomically swap in the new signal mask, and wait for a signal. |
| 551 | */ |
| 552 | asmlinkage int |
| 553 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) |
| 554 | { |
Oleg Nesterov | 3982294 | 2011-07-10 21:27:27 +0200 | [diff] [blame] | 555 | sigset_t blocked; |
Oleg Nesterov | 3982294 | 2011-07-10 21:27:27 +0200 | [diff] [blame] | 556 | siginitset(&blocked, mask); |
Al Viro | 68f3f16 | 2012-05-21 21:42:32 -0400 | [diff] [blame] | 557 | return sigsuspend(&blocked); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | asmlinkage int |
| 561 | sys_sigaction(int sig, const struct old_sigaction __user *act, |
| 562 | struct old_sigaction __user *oact) |
| 563 | { |
| 564 | struct k_sigaction new_ka, old_ka; |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 565 | int ret = 0; |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 566 | |
| 567 | if (act) { |
| 568 | old_sigset_t mask; |
| 569 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 570 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 571 | return -EFAULT; |
| 572 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 573 | get_user_try { |
| 574 | get_user_ex(new_ka.sa.sa_handler, &act->sa_handler); |
| 575 | get_user_ex(new_ka.sa.sa_flags, &act->sa_flags); |
| 576 | get_user_ex(mask, &act->sa_mask); |
| 577 | get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer); |
| 578 | } get_user_catch(ret); |
| 579 | |
| 580 | if (ret) |
| 581 | return -EFAULT; |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 582 | siginitset(&new_ka.sa.sa_mask, mask); |
| 583 | } |
| 584 | |
| 585 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 586 | |
| 587 | if (!ret && oact) { |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 588 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 589 | return -EFAULT; |
| 590 | |
Hiroshi Shimamoto | 98e3d45 | 2009-01-23 15:50:10 -0800 | [diff] [blame] | 591 | put_user_try { |
| 592 | put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler); |
| 593 | put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags); |
| 594 | put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); |
| 595 | put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer); |
| 596 | } put_user_catch(ret); |
| 597 | |
| 598 | if (ret) |
| 599 | return -EFAULT; |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | return ret; |
| 603 | } |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 604 | #endif /* CONFIG_X86_32 */ |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 605 | |
Brian Gerst | 052acad | 2009-12-09 19:01:54 -0500 | [diff] [blame] | 606 | long |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 607 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
| 608 | struct pt_regs *regs) |
| 609 | { |
| 610 | return do_sigaltstack(uss, uoss, regs->sp); |
| 611 | } |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 612 | |
| 613 | /* |
| 614 | * Do a signal return; undo the signal stack. |
| 615 | */ |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 616 | #ifdef CONFIG_X86_32 |
Brian Gerst | b12bdaf | 2009-02-11 16:43:58 -0500 | [diff] [blame] | 617 | unsigned long sys_sigreturn(struct pt_regs *regs) |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 618 | { |
| 619 | struct sigframe __user *frame; |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 620 | unsigned long ax; |
| 621 | sigset_t set; |
| 622 | |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 623 | frame = (struct sigframe __user *)(regs->sp - 8); |
| 624 | |
| 625 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 626 | goto badframe; |
| 627 | if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 |
| 628 | && __copy_from_user(&set.sig[1], &frame->extramask, |
| 629 | sizeof(frame->extramask)))) |
| 630 | goto badframe; |
| 631 | |
Oleg Nesterov | 3982294 | 2011-07-10 21:27:27 +0200 | [diff] [blame] | 632 | set_current_blocked(&set); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 633 | |
| 634 | if (restore_sigcontext(regs, &frame->sc, &ax)) |
| 635 | goto badframe; |
| 636 | return ax; |
| 637 | |
| 638 | badframe: |
Hiroshi Shimamoto | ae417bb | 2008-12-16 14:02:16 -0800 | [diff] [blame] | 639 | signal_fault(regs, frame, "sigreturn"); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 640 | |
| 641 | return 0; |
| 642 | } |
Hiroshi Shimamoto | e5fa2d0 | 2008-11-24 18:24:11 -0800 | [diff] [blame] | 643 | #endif /* CONFIG_X86_32 */ |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 644 | |
H. Peter Anvin | 7445250 | 2009-02-11 16:31:40 -0800 | [diff] [blame] | 645 | long sys_rt_sigreturn(struct pt_regs *regs) |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 646 | { |
| 647 | struct rt_sigframe __user *frame; |
| 648 | unsigned long ax; |
| 649 | sigset_t set; |
| 650 | |
| 651 | frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); |
| 652 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 653 | goto badframe; |
| 654 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 655 | goto badframe; |
| 656 | |
Oleg Nesterov | e9bd3f0 | 2011-04-27 21:09:39 +0200 | [diff] [blame] | 657 | set_current_blocked(&set); |
Hiroshi Shimamoto | bfeb91a | 2008-11-24 18:23:12 -0800 | [diff] [blame] | 658 | |
| 659 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) |
| 660 | goto badframe; |
| 661 | |
| 662 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) |
| 663 | goto badframe; |
| 664 | |
| 665 | return ax; |
| 666 | |
| 667 | badframe: |
| 668 | signal_fault(regs, frame, "rt_sigreturn"); |
| 669 | return 0; |
| 670 | } |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | /* |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 673 | * OK, we're invoking a handler: |
| 674 | */ |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 675 | static int signr_convert(int sig) |
| 676 | { |
Hiroshi Shimamoto | 96bf84b | 2008-10-29 18:44:08 -0700 | [diff] [blame] | 677 | #ifdef CONFIG_X86_32 |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 678 | struct thread_info *info = current_thread_info(); |
| 679 | |
| 680 | if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32) |
| 681 | return info->exec_domain->signal_invmap[sig]; |
Hiroshi Shimamoto | 96bf84b | 2008-10-29 18:44:08 -0700 | [diff] [blame] | 682 | #endif /* CONFIG_X86_32 */ |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 683 | return sig; |
| 684 | } |
| 685 | |
Roland McGrath | 7c1def1 | 2005-06-23 00:08:21 -0700 | [diff] [blame] | 686 | static int |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 687 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Oleg Nesterov | 9b42962 | 2011-07-10 20:22:03 +0200 | [diff] [blame] | 688 | struct pt_regs *regs) |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 689 | { |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 690 | int usig = signr_convert(sig); |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 691 | sigset_t *set = sigmask_to_save(); |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 692 | compat_sigset_t *cset = (compat_sigset_t *) set; |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 693 | |
| 694 | /* Set up the stack frame */ |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 695 | if (is_ia32_frame()) { |
Hiroshi Shimamoto | 455edbc | 2008-09-24 19:13:11 -0700 | [diff] [blame] | 696 | if (ka->sa.sa_flags & SA_SIGINFO) |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 697 | return ia32_setup_rt_frame(usig, ka, info, cset, regs); |
Hiroshi Shimamoto | 455edbc | 2008-09-24 19:13:11 -0700 | [diff] [blame] | 698 | else |
Suresh Siddha | 050902c | 2012-07-24 16:05:27 -0700 | [diff] [blame] | 699 | return ia32_setup_frame(usig, ka, cset, regs); |
| 700 | } else if (is_x32_frame()) { |
| 701 | return x32_setup_rt_frame(usig, ka, info, cset, regs); |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 702 | } else { |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 703 | return __setup_rt_frame(sig, ka, info, set, regs); |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 704 | } |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 707 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, |
Oleg Nesterov | 9b42962 | 2011-07-10 20:22:03 +0200 | [diff] [blame] | 709 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | /* Are we from a system call? */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 712 | if (syscall_get_nr(current, regs) >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | /* If so, check system call restarting.. */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 714 | switch (syscall_get_error(current, regs)) { |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 715 | case -ERESTART_RESTARTBLOCK: |
| 716 | case -ERESTARTNOHAND: |
| 717 | regs->ax = -EINTR; |
| 718 | break; |
| 719 | |
| 720 | case -ERESTARTSYS: |
| 721 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 722 | regs->ax = -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | break; |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 724 | } |
| 725 | /* fallthrough */ |
| 726 | case -ERESTARTNOINTR: |
| 727 | regs->ax = regs->orig_ax; |
| 728 | regs->ip -= 2; |
| 729 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | /* |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 734 | * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF |
| 735 | * flag so that register information in the sigcontext is correct. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 737 | if (unlikely(regs->flags & X86_EFLAGS_TF) && |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 738 | likely(test_and_clear_thread_flag(TIF_FORCED_TF))) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 739 | regs->flags &= ~X86_EFLAGS_TF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 741 | if (setup_rt_frame(sig, ka, info, regs) < 0) { |
| 742 | force_sigsegv(sig, current); |
| 743 | return; |
| 744 | } |
Roland McGrath | 7c1def1 | 2005-06-23 00:08:21 -0700 | [diff] [blame] | 745 | |
Roland McGrath | 8b9c5ff | 2008-04-19 14:26:54 -0700 | [diff] [blame] | 746 | /* |
| 747 | * Clear the direction flag as per the ABI for function entry. |
| 748 | */ |
| 749 | regs->flags &= ~X86_EFLAGS_DF; |
| 750 | |
| 751 | /* |
| 752 | * Clear TF when entering the signal handler, but |
| 753 | * notify any tracer that was single-stepping it. |
| 754 | * The tracer may want to single-step inside the |
| 755 | * handler too. |
| 756 | */ |
| 757 | regs->flags &= ~X86_EFLAGS_TF; |
Roland McGrath | 8b9c5ff | 2008-04-19 14:26:54 -0700 | [diff] [blame] | 758 | |
Al Viro | efee984 | 2012-04-28 02:04:15 -0400 | [diff] [blame] | 759 | signal_delivered(sig, info, ka, regs, |
| 760 | test_thread_flag(TIF_SINGLESTEP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Hiroshi Shimamoto | 5791775 | 2008-10-29 18:46:40 -0700 | [diff] [blame] | 763 | #ifdef CONFIG_X86_32 |
Hiroshi Shimamoto | 8fcd8e2 | 2008-09-05 16:27:39 -0700 | [diff] [blame] | 764 | #define NR_restart_syscall __NR_restart_syscall |
Hiroshi Shimamoto | 5791775 | 2008-10-29 18:46:40 -0700 | [diff] [blame] | 765 | #else /* !CONFIG_X86_32 */ |
| 766 | #define NR_restart_syscall \ |
| 767 | test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall |
| 768 | #endif /* CONFIG_X86_32 */ |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* |
| 771 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 772 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 773 | * mistake. |
| 774 | */ |
Harvey Harrison | 75604d7 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 775 | static void do_signal(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 777 | struct k_sigaction ka; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | siginfo_t info; |
| 779 | int signr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 782 | if (signr > 0) { |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 783 | /* Whee! Actually deliver the signal. */ |
Oleg Nesterov | 9b42962 | 2011-07-10 20:22:03 +0200 | [diff] [blame] | 784 | handle_signal(signr, &info, &ka, regs); |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 785 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* Did we come from a system call? */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 789 | if (syscall_get_nr(current, regs) >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | /* Restart the system call - no handlers present */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 791 | switch (syscall_get_error(current, regs)) { |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 792 | case -ERESTARTNOHAND: |
| 793 | case -ERESTARTSYS: |
| 794 | case -ERESTARTNOINTR: |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 795 | regs->ax = regs->orig_ax; |
| 796 | regs->ip -= 2; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 797 | break; |
| 798 | |
| 799 | case -ERESTART_RESTARTBLOCK: |
Hiroshi Shimamoto | 8fcd8e2 | 2008-09-05 16:27:39 -0700 | [diff] [blame] | 800 | regs->ax = NR_restart_syscall; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 801 | regs->ip -= 2; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 802 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | } |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 805 | |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 806 | /* |
| 807 | * If there's no signal to deliver, we just put the saved sigmask |
| 808 | * back. |
| 809 | */ |
Al Viro | 51a7b44 | 2012-05-21 23:33:55 -0400 | [diff] [blame] | 810 | restore_saved_sigmask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* |
| 814 | * notification of userspace execution resumption |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 815 | * - triggered by the TIF_WORK_MASK flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 817 | void |
| 818 | do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | { |
Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame^] | 820 | user_exit(); |
Frederic Weisbecker | edf55fd | 2012-07-11 20:26:39 +0200 | [diff] [blame] | 821 | |
Andi Kleen | c1ebf83 | 2009-07-09 00:31:41 +0200 | [diff] [blame] | 822 | #ifdef CONFIG_X86_MCE |
Hiroshi Shimamoto | ee847c5 | 2008-09-23 17:21:45 -0700 | [diff] [blame] | 823 | /* notify userspace of pending MCEs */ |
| 824 | if (thread_info_flags & _TIF_MCE_NOTIFY) |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 825 | mce_notify_process(); |
Hiroshi Shimamoto | ee847c5 | 2008-09-23 17:21:45 -0700 | [diff] [blame] | 826 | #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ |
| 827 | |
Srikar Dronamraju | 0326f5a | 2012-03-13 23:30:11 +0530 | [diff] [blame] | 828 | if (thread_info_flags & _TIF_UPROBE) { |
| 829 | clear_thread_flag(TIF_UPROBE); |
| 830 | uprobe_notify_resume(regs); |
| 831 | } |
| 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | /* deal with pending signal delivery */ |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 834 | if (thread_info_flags & _TIF_SIGPENDING) |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 835 | do_signal(regs); |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 836 | |
Roland McGrath | 59e5213 | 2008-04-19 19:10:57 -0700 | [diff] [blame] | 837 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
| 838 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 839 | tracehook_notify_resume(regs); |
| 840 | } |
Avi Kivity | 7c68af6 | 2009-09-19 09:40:22 +0300 | [diff] [blame] | 841 | if (thread_info_flags & _TIF_USER_RETURN_NOTIFY) |
| 842 | fire_user_return_notifiers(); |
Roland McGrath | 59e5213 | 2008-04-19 19:10:57 -0700 | [diff] [blame] | 843 | |
Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame^] | 844 | user_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 846 | |
| 847 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) |
| 848 | { |
| 849 | struct task_struct *me = current; |
| 850 | |
| 851 | if (show_unhandled_signals && printk_ratelimit()) { |
Hiroshi Shimamoto | ae417bb | 2008-12-16 14:02:16 -0800 | [diff] [blame] | 852 | printk("%s" |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 853 | "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", |
Hiroshi Shimamoto | ae417bb | 2008-12-16 14:02:16 -0800 | [diff] [blame] | 854 | task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG, |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 855 | me->comm, me->pid, where, frame, |
| 856 | regs->ip, regs->sp, regs->orig_ax); |
| 857 | print_vma_addr(" in ", regs->ip); |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 858 | pr_cont("\n"); |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | force_sig(SIGSEGV, me); |
| 862 | } |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 863 | |
| 864 | #ifdef CONFIG_X86_X32_ABI |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 865 | asmlinkage long sys32_x32_rt_sigreturn(struct pt_regs *regs) |
| 866 | { |
| 867 | struct rt_sigframe_x32 __user *frame; |
| 868 | sigset_t set; |
| 869 | unsigned long ax; |
| 870 | struct pt_regs tregs; |
| 871 | |
| 872 | frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8); |
| 873 | |
| 874 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 875 | goto badframe; |
| 876 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 877 | goto badframe; |
| 878 | |
H. Peter Anvin | c5a3739 | 2012-02-19 09:41:09 -0800 | [diff] [blame] | 879 | set_current_blocked(&set); |
| 880 | |
| 881 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) |
| 882 | goto badframe; |
| 883 | |
| 884 | tregs = *regs; |
| 885 | if (sys32_sigaltstack(&frame->uc.uc_stack, NULL, &tregs) == -EFAULT) |
| 886 | goto badframe; |
| 887 | |
| 888 | return ax; |
| 889 | |
| 890 | badframe: |
| 891 | signal_fault(regs, frame, "x32 rt_sigreturn"); |
| 892 | return 0; |
| 893 | } |
| 894 | #endif |