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