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