Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/signal.c |
| 3 | * |
Russell King | ab72b00 | 2009-10-25 15:39:37 +0000 | [diff] [blame] | 4 | * Copyright (C) 1995-2009 Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/errno.h> |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 11 | #include <linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/personality.h> |
Russell King | 33fa9b1 | 2008-09-06 11:35:55 +0100 | [diff] [blame] | 14 | #include <linux/uaccess.h> |
David Howells | 733e5e4 | 2009-09-09 08:30:21 +0100 | [diff] [blame] | 15 | #include <linux/tracehook.h> |
David A. Long | c7edc9e | 2014-03-07 11:23:04 -0500 | [diff] [blame] | 16 | #include <linux/uprobes.h> |
Thomas Garnier | ffecead | 2017-09-07 08:30:46 -0700 | [diff] [blame] | 17 | #include <linux/syscalls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Russell King | ee90dab | 2006-11-09 14:20:47 +0000 | [diff] [blame] | 19 | #include <asm/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/cacheflush.h> |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 21 | #include <asm/traps.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/ucontext.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/unistd.h> |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 24 | #include <asm/vfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Victor Kamensky | 574e2b5 | 2013-08-27 22:41:57 -0700 | [diff] [blame] | 26 | extern const unsigned long sigreturn_codes[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 28 | static unsigned long signal_return_offset; |
| 29 | |
Lennert Buytenhek | 3bec6ded | 2006-06-27 22:56:18 +0100 | [diff] [blame] | 30 | #ifdef CONFIG_CRUNCH |
Hartley Sweeten | 65a5053 | 2009-08-04 23:20:45 +0100 | [diff] [blame] | 31 | static int preserve_crunch_context(struct crunch_sigframe __user *frame) |
Lennert Buytenhek | 3bec6ded | 2006-06-27 22:56:18 +0100 | [diff] [blame] | 32 | { |
| 33 | char kbuf[sizeof(*frame) + 8]; |
| 34 | struct crunch_sigframe *kframe; |
| 35 | |
| 36 | /* the crunch context must be 64 bit aligned */ |
| 37 | kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7); |
| 38 | kframe->magic = CRUNCH_MAGIC; |
| 39 | kframe->size = CRUNCH_STORAGE_SIZE; |
| 40 | crunch_task_copy(current_thread_info(), &kframe->storage); |
| 41 | return __copy_to_user(frame, kframe, sizeof(*frame)); |
| 42 | } |
| 43 | |
Hartley Sweeten | 65a5053 | 2009-08-04 23:20:45 +0100 | [diff] [blame] | 44 | static int restore_crunch_context(struct crunch_sigframe __user *frame) |
Lennert Buytenhek | 3bec6ded | 2006-06-27 22:56:18 +0100 | [diff] [blame] | 45 | { |
| 46 | char kbuf[sizeof(*frame) + 8]; |
| 47 | struct crunch_sigframe *kframe; |
| 48 | |
| 49 | /* the crunch context must be 64 bit aligned */ |
| 50 | kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7); |
| 51 | if (__copy_from_user(kframe, frame, sizeof(*frame))) |
| 52 | return -1; |
| 53 | if (kframe->magic != CRUNCH_MAGIC || |
| 54 | kframe->size != CRUNCH_STORAGE_SIZE) |
| 55 | return -1; |
| 56 | crunch_task_restore(current_thread_info(), &kframe->storage); |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_IWMMXT |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame) |
| 64 | { |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 65 | char kbuf[sizeof(*frame) + 8]; |
| 66 | struct iwmmxt_sigframe *kframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* the iWMMXt context must be 64 bit aligned */ |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 69 | kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7); |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 70 | kframe->magic = IWMMXT_MAGIC; |
| 71 | kframe->size = IWMMXT_STORAGE_SIZE; |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 72 | iwmmxt_task_copy(current_thread_info(), &kframe->storage); |
| 73 | return __copy_to_user(frame, kframe, sizeof(*frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame) |
| 77 | { |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 78 | char kbuf[sizeof(*frame) + 8]; |
| 79 | struct iwmmxt_sigframe *kframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 81 | /* the iWMMXt context must be 64 bit aligned */ |
| 82 | kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7); |
| 83 | if (__copy_from_user(kframe, frame, sizeof(*frame))) |
| 84 | return -1; |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 85 | if (kframe->magic != IWMMXT_MAGIC || |
| 86 | kframe->size != IWMMXT_STORAGE_SIZE) |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 87 | return -1; |
| 88 | iwmmxt_task_restore(current_thread_info(), &kframe->storage); |
| 89 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | #endif |
| 93 | |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 94 | #ifdef CONFIG_VFP |
| 95 | |
| 96 | static int preserve_vfp_context(struct vfp_sigframe __user *frame) |
| 97 | { |
Julien Thierry | 6f86d53 | 2019-02-14 09:49:16 -0500 | [diff] [blame] | 98 | struct vfp_sigframe kframe; |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 99 | int err = 0; |
| 100 | |
Julien Thierry | 6f86d53 | 2019-02-14 09:49:16 -0500 | [diff] [blame] | 101 | memset(&kframe, 0, sizeof(kframe)); |
| 102 | kframe.magic = VFP_MAGIC; |
| 103 | kframe.size = VFP_STORAGE_SIZE; |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 104 | |
Julien Thierry | 6f86d53 | 2019-02-14 09:49:16 -0500 | [diff] [blame] | 105 | err = vfp_preserve_user_clear_hwstate(&kframe.ufp, &kframe.ufp_exc); |
Will Deacon | 2498814 | 2012-04-23 15:38:28 +0100 | [diff] [blame] | 106 | if (err) |
Julien Thierry | 6f86d53 | 2019-02-14 09:49:16 -0500 | [diff] [blame] | 107 | return err; |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 108 | |
Julien Thierry | 6f86d53 | 2019-02-14 09:49:16 -0500 | [diff] [blame] | 109 | return __copy_to_user(frame, &kframe, sizeof(kframe)); |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Russell King | 9c91b96 | 2018-11-07 11:43:58 -0500 | [diff] [blame] | 112 | static int restore_vfp_context(struct vfp_sigframe __user *auxp) |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 113 | { |
Russell King | 9c91b96 | 2018-11-07 11:43:58 -0500 | [diff] [blame] | 114 | struct vfp_sigframe frame; |
| 115 | int err; |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 116 | |
Russell King | 9c91b96 | 2018-11-07 11:43:58 -0500 | [diff] [blame] | 117 | err = __copy_from_user(&frame, (char __user *) auxp, sizeof(frame)); |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 118 | |
| 119 | if (err) |
Russell King | 9c91b96 | 2018-11-07 11:43:58 -0500 | [diff] [blame] | 120 | return err; |
| 121 | |
| 122 | if (frame.magic != VFP_MAGIC || frame.size != VFP_STORAGE_SIZE) |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | |
Russell King | 9c91b96 | 2018-11-07 11:43:58 -0500 | [diff] [blame] | 125 | return vfp_restore_user_hwstate(&frame.ufp, &frame.ufp_exc); |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | #endif |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | * Do a signal return; undo the signal stack. These are aligned to 64-bit. |
| 132 | */ |
| 133 | struct sigframe { |
Russell King | 7d4fdc1 | 2006-06-15 20:13:25 +0100 | [diff] [blame] | 134 | struct ucontext uc; |
Nicolas Pitre | fcca538 | 2006-01-18 22:38:47 +0000 | [diff] [blame] | 135 | unsigned long retcode[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct rt_sigframe { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | struct siginfo info; |
Russell King | cb3504e | 2006-06-15 20:18:25 +0100 | [diff] [blame] | 140 | struct sigframe sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 143 | static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Russell King | 50f032c | 2018-11-07 11:43:57 -0500 | [diff] [blame] | 145 | struct sigcontext context; |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 146 | struct aux_sigframe __user *aux; |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 147 | sigset_t set; |
| 148 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 150 | err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); |
Al Viro | 77097ae | 2012-04-27 13:58:59 -0400 | [diff] [blame] | 151 | if (err == 0) |
Matt Fleming | 101d9b0 | 2012-03-05 15:05:34 -0800 | [diff] [blame] | 152 | set_current_blocked(&set); |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 153 | |
Russell King | 50f032c | 2018-11-07 11:43:57 -0500 | [diff] [blame] | 154 | err |= __copy_from_user(&context, &sf->uc.uc_mcontext, sizeof(context)); |
| 155 | if (err == 0) { |
| 156 | regs->ARM_r0 = context.arm_r0; |
| 157 | regs->ARM_r1 = context.arm_r1; |
| 158 | regs->ARM_r2 = context.arm_r2; |
| 159 | regs->ARM_r3 = context.arm_r3; |
| 160 | regs->ARM_r4 = context.arm_r4; |
| 161 | regs->ARM_r5 = context.arm_r5; |
| 162 | regs->ARM_r6 = context.arm_r6; |
| 163 | regs->ARM_r7 = context.arm_r7; |
| 164 | regs->ARM_r8 = context.arm_r8; |
| 165 | regs->ARM_r9 = context.arm_r9; |
| 166 | regs->ARM_r10 = context.arm_r10; |
| 167 | regs->ARM_fp = context.arm_fp; |
| 168 | regs->ARM_ip = context.arm_ip; |
| 169 | regs->ARM_sp = context.arm_sp; |
| 170 | regs->ARM_lr = context.arm_lr; |
| 171 | regs->ARM_pc = context.arm_pc; |
| 172 | regs->ARM_cpsr = context.arm_cpsr; |
| 173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | err |= !valid_user_regs(regs); |
| 176 | |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 177 | aux = (struct aux_sigframe __user *) sf->uc.uc_regspace; |
Lennert Buytenhek | 3bec6ded | 2006-06-27 22:56:18 +0100 | [diff] [blame] | 178 | #ifdef CONFIG_CRUNCH |
| 179 | if (err == 0) |
| 180 | err |= restore_crunch_context(&aux->crunch); |
| 181 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | #ifdef CONFIG_IWMMXT |
| 183 | if (err == 0 && test_thread_flag(TIF_USING_IWMMXT)) |
| 184 | err |= restore_iwmmxt_context(&aux->iwmmxt); |
| 185 | #endif |
| 186 | #ifdef CONFIG_VFP |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 187 | if (err == 0) |
| 188 | err |= restore_vfp_context(&aux->vfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #endif |
| 190 | |
| 191 | return err; |
| 192 | } |
| 193 | |
| 194 | asmlinkage int sys_sigreturn(struct pt_regs *regs) |
| 195 | { |
| 196 | struct sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /* Always make any pending restarted system calls return -EINTR */ |
Andy Lutomirski | f56141e | 2015-02-12 15:01:14 -0800 | [diff] [blame] | 199 | current->restart_block.fn = do_no_restart_syscall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * Since we stacked the signal on a 64-bit boundary, |
| 203 | * then 'sp' should be word aligned here. If it's |
| 204 | * not, then the user is trying to mess with us. |
| 205 | */ |
| 206 | if (regs->ARM_sp & 7) |
| 207 | goto badframe; |
| 208 | |
| 209 | frame = (struct sigframe __user *)regs->ARM_sp; |
| 210 | |
| 211 | if (!access_ok(VERIFY_READ, frame, sizeof (*frame))) |
| 212 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 214 | if (restore_sigframe(regs, frame)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | goto badframe; |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return regs->ARM_r0; |
| 218 | |
| 219 | badframe: |
| 220 | force_sig(SIGSEGV, current); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | asmlinkage int sys_rt_sigreturn(struct pt_regs *regs) |
| 225 | { |
| 226 | struct rt_sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /* Always make any pending restarted system calls return -EINTR */ |
Andy Lutomirski | f56141e | 2015-02-12 15:01:14 -0800 | [diff] [blame] | 229 | current->restart_block.fn = do_no_restart_syscall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * Since we stacked the signal on a 64-bit boundary, |
| 233 | * then 'sp' should be word aligned here. If it's |
| 234 | * not, then the user is trying to mess with us. |
| 235 | */ |
| 236 | if (regs->ARM_sp & 7) |
| 237 | goto badframe; |
| 238 | |
| 239 | frame = (struct rt_sigframe __user *)regs->ARM_sp; |
| 240 | |
| 241 | if (!access_ok(VERIFY_READ, frame, sizeof (*frame))) |
| 242 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Russell King | 6807148 | 2006-06-15 20:23:02 +0100 | [diff] [blame] | 244 | if (restore_sigframe(regs, &frame->sig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | goto badframe; |
| 246 | |
Al Viro | ec93ac8 | 2012-12-23 01:52:54 -0500 | [diff] [blame] | 247 | if (restore_altstack(&frame->sig.uc.uc_stack)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | goto badframe; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return regs->ARM_r0; |
| 251 | |
| 252 | badframe: |
| 253 | force_sig(SIGSEGV, current); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int |
Russell King | aca6ca1 | 2006-06-15 20:28:03 +0100 | [diff] [blame] | 258 | setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 260 | struct aux_sigframe __user *aux; |
Julien Thierry | 31ac781 | 2019-02-14 09:49:15 -0500 | [diff] [blame] | 261 | struct sigcontext context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | int err = 0; |
| 263 | |
Julien Thierry | 31ac781 | 2019-02-14 09:49:15 -0500 | [diff] [blame] | 264 | context = (struct sigcontext) { |
| 265 | .arm_r0 = regs->ARM_r0, |
| 266 | .arm_r1 = regs->ARM_r1, |
| 267 | .arm_r2 = regs->ARM_r2, |
| 268 | .arm_r3 = regs->ARM_r3, |
| 269 | .arm_r4 = regs->ARM_r4, |
| 270 | .arm_r5 = regs->ARM_r5, |
| 271 | .arm_r6 = regs->ARM_r6, |
| 272 | .arm_r7 = regs->ARM_r7, |
| 273 | .arm_r8 = regs->ARM_r8, |
| 274 | .arm_r9 = regs->ARM_r9, |
| 275 | .arm_r10 = regs->ARM_r10, |
| 276 | .arm_fp = regs->ARM_fp, |
| 277 | .arm_ip = regs->ARM_ip, |
| 278 | .arm_sp = regs->ARM_sp, |
| 279 | .arm_lr = regs->ARM_lr, |
| 280 | .arm_pc = regs->ARM_pc, |
| 281 | .arm_cpsr = regs->ARM_cpsr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Julien Thierry | 31ac781 | 2019-02-14 09:49:15 -0500 | [diff] [blame] | 283 | .trap_no = current->thread.trap_no, |
| 284 | .error_code = current->thread.error_code, |
| 285 | .fault_address = current->thread.address, |
| 286 | .oldmask = set->sig[0], |
| 287 | }; |
| 288 | |
| 289 | err |= __copy_to_user(&sf->uc.uc_mcontext, &context, sizeof(context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Russell King | aca6ca1 | 2006-06-15 20:28:03 +0100 | [diff] [blame] | 291 | err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Daniel Jacobowitz | 85fe068 | 2006-06-24 23:46:21 +0100 | [diff] [blame] | 293 | aux = (struct aux_sigframe __user *) sf->uc.uc_regspace; |
Lennert Buytenhek | 3bec6ded | 2006-06-27 22:56:18 +0100 | [diff] [blame] | 294 | #ifdef CONFIG_CRUNCH |
| 295 | if (err == 0) |
| 296 | err |= preserve_crunch_context(&aux->crunch); |
| 297 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | #ifdef CONFIG_IWMMXT |
| 299 | if (err == 0 && test_thread_flag(TIF_USING_IWMMXT)) |
| 300 | err |= preserve_iwmmxt_context(&aux->iwmmxt); |
| 301 | #endif |
| 302 | #ifdef CONFIG_VFP |
Imre Deak | 82c6f5a | 2010-04-11 15:58:27 +0100 | [diff] [blame] | 303 | if (err == 0) |
| 304 | err |= preserve_vfp_context(&aux->vfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | #endif |
Julien Thierry | c4fa56d | 2019-02-14 09:49:18 -0500 | [diff] [blame] | 306 | err |= __put_user(0, &aux->end_magic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | return err; |
| 309 | } |
| 310 | |
| 311 | static inline void __user * |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 312 | get_sigframe(struct ksignal *ksig, struct pt_regs *regs, int framesize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 314 | unsigned long sp = sigsp(regs->ARM_sp, ksig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | void __user *frame; |
| 316 | |
| 317 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | * ATPCS B01 mandates 8-byte alignment |
| 319 | */ |
| 320 | frame = (void __user *)((sp - framesize) & ~7); |
| 321 | |
| 322 | /* |
| 323 | * Check that we can actually write to the signal frame. |
| 324 | */ |
| 325 | if (!access_ok(VERIFY_WRITE, frame, framesize)) |
| 326 | frame = NULL; |
| 327 | |
| 328 | return frame; |
| 329 | } |
| 330 | |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 331 | static int |
| 332 | setup_return(struct pt_regs *regs, struct ksignal *ksig, |
| 333 | unsigned long __user *rc, void __user *frame) |
| 334 | { |
| 335 | unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | unsigned long retcode; |
| 337 | int thumb = 0; |
Russell King | 5339905 | 2011-02-20 12:22:52 +0000 | [diff] [blame] | 338 | unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT); |
| 339 | |
| 340 | cpsr |= PSR_ENDSTATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* |
| 343 | * Maybe we need to deliver a 32-bit signal to a 26-bit task. |
| 344 | */ |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 345 | if (ksig->ka.sa.sa_flags & SA_THIRTYTWO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | cpsr = (cpsr & ~MODE_MASK) | USR_MODE; |
| 347 | |
| 348 | #ifdef CONFIG_ARM_THUMB |
| 349 | if (elf_hwcap & HWCAP_THUMB) { |
| 350 | /* |
| 351 | * The LSB of the handler determines if we're going to |
| 352 | * be using THUMB or ARM mode for this signal handler. |
| 353 | */ |
| 354 | thumb = handler & 1; |
| 355 | |
T.J. Purtell | 6ecf830 | 2013-11-06 18:38:05 +0100 | [diff] [blame] | 356 | /* |
Russell King | 9b55613 | 2015-09-11 16:44:02 +0100 | [diff] [blame] | 357 | * Clear the If-Then Thumb-2 execution state. ARM spec |
| 358 | * requires this to be all 000s in ARM mode. Snapdragon |
| 359 | * S4/Krait misbehaves on a Thumb=>ARM signal transition |
| 360 | * without this. |
| 361 | * |
| 362 | * We must do this whenever we are running on a Thumb-2 |
| 363 | * capable CPU, which includes ARMv6T2. However, we elect |
Russell King | 12fc730 | 2015-09-16 11:08:49 +0100 | [diff] [blame] | 364 | * to always do this to simplify the code; this field is |
| 365 | * marked UNK/SBZP for older architectures. |
T.J. Purtell | 6ecf830 | 2013-11-06 18:38:05 +0100 | [diff] [blame] | 366 | */ |
| 367 | cpsr &= ~PSR_IT_MASK; |
T.J. Purtell | 6ecf830 | 2013-11-06 18:38:05 +0100 | [diff] [blame] | 368 | |
Catalin Marinas | d71e135 | 2009-05-30 14:00:15 +0100 | [diff] [blame] | 369 | if (thumb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | cpsr |= PSR_T_BIT; |
Catalin Marinas | d71e135 | 2009-05-30 14:00:15 +0100 | [diff] [blame] | 371 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | cpsr &= ~PSR_T_BIT; |
| 373 | } |
| 374 | #endif |
| 375 | |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 376 | if (ksig->ka.sa.sa_flags & SA_RESTORER) { |
| 377 | retcode = (unsigned long)ksig->ka.sa.sa_restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } else { |
Nicolas Pitre | fcca538 | 2006-01-18 22:38:47 +0000 | [diff] [blame] | 379 | unsigned int idx = thumb << 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 381 | if (ksig->ka.sa.sa_flags & SA_SIGINFO) |
Nicolas Pitre | fcca538 | 2006-01-18 22:38:47 +0000 | [diff] [blame] | 382 | idx += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Jonathan Austin | 9dfc28b | 2013-04-18 18:37:24 +0100 | [diff] [blame] | 384 | /* |
| 385 | * Put the sigreturn code on the stack no matter which return |
| 386 | * mechanism we use in order to remain ABI compliant |
| 387 | */ |
Nicolas Pitre | fcca538 | 2006-01-18 22:38:47 +0000 | [diff] [blame] | 388 | if (__put_user(sigreturn_codes[idx], rc) || |
| 389 | __put_user(sigreturn_codes[idx+1], rc+1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return 1; |
| 391 | |
Russell King | 8c0cc8a | 2013-08-03 10:39:51 +0100 | [diff] [blame] | 392 | #ifdef CONFIG_MMU |
| 393 | if (cpsr & MODE32_BIT) { |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 394 | struct mm_struct *mm = current->mm; |
| 395 | |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 396 | /* |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 397 | * 32-bit code can use the signal return page |
| 398 | * except when the MPU has protected the vectors |
| 399 | * page from PL0 |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 400 | */ |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 401 | retcode = mm->context.sigpage + signal_return_offset + |
| 402 | (idx << 2) + thumb; |
Russell King | 8c0cc8a | 2013-08-03 10:39:51 +0100 | [diff] [blame] | 403 | } else |
| 404 | #endif |
| 405 | { |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 406 | /* |
| 407 | * Ensure that the instruction cache sees |
| 408 | * the return code written onto the stack. |
| 409 | */ |
| 410 | flush_icache_range((unsigned long)rc, |
Nicolas Pitre | fcca538 | 2006-01-18 22:38:47 +0000 | [diff] [blame] | 411 | (unsigned long)(rc + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 413 | retcode = ((unsigned long)rc) + thumb; |
| 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Richard Weinberger | a498044 | 2014-07-13 15:24:03 +0200 | [diff] [blame] | 417 | regs->ARM_r0 = ksig->sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | regs->ARM_sp = (unsigned long)frame; |
| 419 | regs->ARM_lr = retcode; |
| 420 | regs->ARM_pc = handler; |
| 421 | regs->ARM_cpsr = cpsr; |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 427 | setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 429 | struct sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int err = 0; |
| 431 | |
| 432 | if (!frame) |
| 433 | return 1; |
| 434 | |
Russell King | ca195cf | 2006-06-24 22:41:09 +0100 | [diff] [blame] | 435 | /* |
| 436 | * Set uc.uc_flags to a value which sc.trap_no would never have. |
| 437 | */ |
Julien Thierry | c4fa56d | 2019-02-14 09:49:18 -0500 | [diff] [blame] | 438 | err = __put_user(0x5ac3c35a, &frame->uc.uc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Russell King | aca6ca1 | 2006-06-15 20:28:03 +0100 | [diff] [blame] | 440 | err |= setup_sigframe(frame, regs, set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (err == 0) |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 442 | err = setup_return(regs, ksig, frame->retcode, frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | return err; |
| 445 | } |
| 446 | |
| 447 | static int |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 448 | setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 450 | struct rt_sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | int err = 0; |
| 452 | |
| 453 | if (!frame) |
| 454 | return 1; |
| 455 | |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 456 | err |= copy_siginfo_to_user(&frame->info, &ksig->info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Julien Thierry | c4fa56d | 2019-02-14 09:49:18 -0500 | [diff] [blame] | 458 | err |= __put_user(0, &frame->sig.uc.uc_flags); |
| 459 | err |= __put_user(NULL, &frame->sig.uc.uc_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Al Viro | ec93ac8 | 2012-12-23 01:52:54 -0500 | [diff] [blame] | 461 | err |= __save_altstack(&frame->sig.uc.uc_stack, regs->ARM_sp); |
Russell King | aca6ca1 | 2006-06-15 20:28:03 +0100 | [diff] [blame] | 462 | err |= setup_sigframe(&frame->sig, regs, set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | if (err == 0) |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 464 | err = setup_return(regs, ksig, frame->sig.retcode, frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | if (err == 0) { |
| 467 | /* |
| 468 | * For realtime signals we must also set the second and third |
| 469 | * arguments for the signal handler. |
| 470 | * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06 |
| 471 | */ |
| 472 | regs->ARM_r1 = (unsigned long)&frame->info; |
Russell King | cb3504e | 2006-06-15 20:18:25 +0100 | [diff] [blame] | 473 | regs->ARM_r2 = (unsigned long)&frame->sig.uc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | return err; |
| 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* |
| 480 | * OK, we're invoking a handler |
| 481 | */ |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 482 | static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 484 | sigset_t *oldset = sigmask_to_save(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | int ret; |
| 486 | |
| 487 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | * Set up the stack frame |
| 489 | */ |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 490 | if (ksig->ka.sa.sa_flags & SA_SIGINFO) |
| 491 | ret = setup_rt_frame(ksig, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | else |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 493 | ret = setup_frame(ksig, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | /* |
| 496 | * Check that the resulting registers are actually sane. |
| 497 | */ |
| 498 | ret |= !valid_user_regs(regs); |
| 499 | |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 500 | signal_setup_done(ret, ksig, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* |
| 504 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 505 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 506 | * mistake. |
| 507 | * |
| 508 | * Note that we go through the signals twice: once to check the signals that |
| 509 | * the kernel can handle, and then we build all the user-level signal handling |
| 510 | * stack-frames in one go after that. |
| 511 | */ |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 512 | static int do_signal(struct pt_regs *regs, int syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 514 | unsigned int retval = 0, continue_addr = 0, restart_addr = 0; |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 515 | struct ksignal ksig; |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 516 | int restart = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /* |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 519 | * If we were from a system call, check for system call restarting... |
| 520 | */ |
| 521 | if (syscall) { |
| 522 | continue_addr = regs->ARM_pc; |
| 523 | restart_addr = continue_addr - (thumb_mode(regs) ? 2 : 4); |
| 524 | retval = regs->ARM_r0; |
| 525 | |
| 526 | /* |
| 527 | * Prepare for system call restart. We do this here so that a |
| 528 | * debugger will see the already changed PSW. |
| 529 | */ |
| 530 | switch (retval) { |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 531 | case -ERESTART_RESTARTBLOCK: |
Al Viro | 6628521 | 2012-07-19 17:48:50 +0100 | [diff] [blame] | 532 | restart -= 2; |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 533 | case -ERESTARTNOHAND: |
| 534 | case -ERESTARTSYS: |
| 535 | case -ERESTARTNOINTR: |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 536 | restart++; |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 537 | regs->ARM_r0 = regs->ARM_ORIG_r0; |
| 538 | regs->ARM_pc = restart_addr; |
| 539 | break; |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 543 | /* |
| 544 | * Get the signal to deliver. When running under ptrace, at this |
| 545 | * point the debugger may change all our registers ... |
| 546 | */ |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 547 | /* |
| 548 | * Depending on the signal settings we may need to revert the |
| 549 | * decision to restart the system call. But skip this if a |
| 550 | * debugger has chosen to restart at a different PC. |
| 551 | */ |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 552 | if (get_signal(&ksig)) { |
| 553 | /* handler */ |
| 554 | if (unlikely(restart) && regs->ARM_pc == restart_addr) { |
Will Deacon | ad82cc0 | 2012-07-19 17:46:44 +0100 | [diff] [blame] | 555 | if (retval == -ERESTARTNOHAND || |
| 556 | retval == -ERESTART_RESTARTBLOCK |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 557 | || (retval == -ERESTARTSYS |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 558 | && !(ksig.ka.sa.sa_flags & SA_RESTART))) { |
Arnd Bergmann | 2af68df | 2011-05-03 18:32:55 +0100 | [diff] [blame] | 559 | regs->ARM_r0 = -EINTR; |
| 560 | regs->ARM_pc = continue_addr; |
| 561 | } |
| 562 | } |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 563 | handle_signal(&ksig, regs); |
| 564 | } else { |
| 565 | /* no handler */ |
| 566 | restore_saved_sigmask(); |
| 567 | if (unlikely(restart) && regs->ARM_pc == restart_addr) { |
| 568 | regs->ARM_pc = continue_addr; |
| 569 | return restart; |
| 570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
Al Viro | 7e24364 | 2012-11-07 17:53:13 -0500 | [diff] [blame] | 572 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 575 | asmlinkage int |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 576 | do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 578 | /* |
| 579 | * The assembly code enters us with IRQs off, but it hasn't |
| 580 | * informed the tracing code of that for efficiency reasons. |
| 581 | * Update the trace code with the current status. |
| 582 | */ |
| 583 | trace_hardirqs_off(); |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 584 | do { |
| 585 | if (likely(thread_flags & _TIF_NEED_RESCHED)) { |
| 586 | schedule(); |
| 587 | } else { |
| 588 | if (unlikely(!user_mode(regs))) |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 589 | return 0; |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 590 | local_irq_enable(); |
| 591 | if (thread_flags & _TIF_SIGPENDING) { |
Al Viro | 6628521 | 2012-07-19 17:48:50 +0100 | [diff] [blame] | 592 | int restart = do_signal(regs, syscall); |
| 593 | if (unlikely(restart)) { |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 594 | /* |
| 595 | * Restart without handlers. |
| 596 | * Deal with it without leaving |
| 597 | * the kernel space. |
| 598 | */ |
Al Viro | 6628521 | 2012-07-19 17:48:50 +0100 | [diff] [blame] | 599 | return restart; |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 600 | } |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 601 | syscall = 0; |
David A. Long | c7edc9e | 2014-03-07 11:23:04 -0500 | [diff] [blame] | 602 | } else if (thread_flags & _TIF_UPROBE) { |
David A. Long | c7edc9e | 2014-03-07 11:23:04 -0500 | [diff] [blame] | 603 | uprobe_notify_resume(regs); |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 604 | } else { |
| 605 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 606 | tracehook_notify_resume(regs); |
| 607 | } |
| 608 | } |
| 609 | local_irq_disable(); |
| 610 | thread_flags = current_thread_info()->flags; |
| 611 | } while (thread_flags & _TIF_WORK_MASK); |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 612 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 614 | |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 615 | struct page *get_signal_page(void) |
| 616 | { |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 617 | unsigned long ptr; |
| 618 | unsigned offset; |
| 619 | struct page *page; |
| 620 | void *addr; |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 621 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 622 | page = alloc_pages(GFP_KERNEL, 0); |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 623 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 624 | if (!page) |
| 625 | return NULL; |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 626 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 627 | addr = page_address(page); |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 628 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 629 | /* Give the signal return code some randomness */ |
| 630 | offset = 0x200 + (get_random_int() & 0x7fc); |
| 631 | signal_return_offset = offset; |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 632 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 633 | /* |
| 634 | * Copy signal return handlers into the vector page, and |
| 635 | * set sigreturn to be a pointer to these. |
| 636 | */ |
| 637 | memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes)); |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 638 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 639 | ptr = (unsigned long)addr + offset; |
| 640 | flush_icache_range(ptr, ptr + sizeof(sigreturn_codes)); |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 641 | |
Russell King | e0d4075 | 2013-08-03 10:30:05 +0100 | [diff] [blame] | 642 | return page; |
Russell King | 48be69a | 2013-07-24 00:29:18 +0100 | [diff] [blame] | 643 | } |
Thomas Garnier | ffecead | 2017-09-07 08:30:46 -0700 | [diff] [blame] | 644 | |
| 645 | /* Defer to generic check */ |
| 646 | asmlinkage void addr_limit_check_failed(void) |
| 647 | { |
| 648 | addr_limit_user_check(); |
| 649 | } |