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