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