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