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