Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 2 | * arch/s390/kernel/compat_signal.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 4 | * Copyright (C) IBM Corp. 2000,2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 6 | * Gerhard Tonn (ton@de.ibm.com) |
| 7 | * |
| 8 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 9 | * |
| 10 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/compat.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/signal.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/wait.h> |
| 21 | #include <linux/ptrace.h> |
| 22 | #include <linux/unistd.h> |
| 23 | #include <linux/stddef.h> |
| 24 | #include <linux/tty.h> |
| 25 | #include <linux/personality.h> |
| 26 | #include <linux/binfmts.h> |
| 27 | #include <asm/ucontext.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/lowcore.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 30 | #include <asm/switch_to.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "compat_linux.h" |
| 32 | #include "compat_ptrace.h" |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 33 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | typedef struct |
| 36 | { |
| 37 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; |
| 38 | struct sigcontext32 sc; |
| 39 | _sigregs32 sregs; |
| 40 | int signo; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 41 | __u32 gprs_high[NUM_GPRS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 43 | } sigframe32; |
| 44 | |
| 45 | typedef struct |
| 46 | { |
| 47 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; |
| 48 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 49 | compat_siginfo_t info; |
| 50 | struct ucontext32 uc; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 51 | __u32 gprs_high[NUM_GPRS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } rt_sigframe32; |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) |
| 55 | { |
| 56 | int err; |
| 57 | |
| 58 | if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t))) |
| 59 | return -EFAULT; |
| 60 | |
| 61 | /* If you change siginfo_t structure, please be sure |
| 62 | this code is fixed accordingly. |
| 63 | It should never copy any pad contained in the structure |
| 64 | to avoid security leaks, but must copy the generic |
| 65 | 3 ints plus the relevant union member. |
| 66 | This routine must convert siginfo from 64bit to 32bit as well |
| 67 | at the same time. */ |
| 68 | err = __put_user(from->si_signo, &to->si_signo); |
| 69 | err |= __put_user(from->si_errno, &to->si_errno); |
| 70 | err |= __put_user((short)from->si_code, &to->si_code); |
| 71 | if (from->si_code < 0) |
| 72 | err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); |
| 73 | else { |
| 74 | switch (from->si_code >> 16) { |
| 75 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
| 76 | case __SI_MESGQ >> 16: |
| 77 | err |= __put_user(from->si_int, &to->si_int); |
| 78 | /* fallthrough */ |
| 79 | case __SI_KILL >> 16: |
| 80 | err |= __put_user(from->si_pid, &to->si_pid); |
| 81 | err |= __put_user(from->si_uid, &to->si_uid); |
| 82 | break; |
| 83 | case __SI_CHLD >> 16: |
| 84 | err |= __put_user(from->si_pid, &to->si_pid); |
| 85 | err |= __put_user(from->si_uid, &to->si_uid); |
| 86 | err |= __put_user(from->si_utime, &to->si_utime); |
| 87 | err |= __put_user(from->si_stime, &to->si_stime); |
| 88 | err |= __put_user(from->si_status, &to->si_status); |
| 89 | break; |
| 90 | case __SI_FAULT >> 16: |
| 91 | err |= __put_user((unsigned long) from->si_addr, |
| 92 | &to->si_addr); |
| 93 | break; |
| 94 | case __SI_POLL >> 16: |
| 95 | err |= __put_user(from->si_band, &to->si_band); |
| 96 | err |= __put_user(from->si_fd, &to->si_fd); |
| 97 | break; |
| 98 | case __SI_TIMER >> 16: |
| 99 | err |= __put_user(from->si_tid, &to->si_tid); |
| 100 | err |= __put_user(from->si_overrun, &to->si_overrun); |
| 101 | err |= __put_user(from->si_int, &to->si_int); |
| 102 | break; |
| 103 | default: |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | return err; |
| 108 | } |
| 109 | |
| 110 | int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) |
| 111 | { |
| 112 | int err; |
| 113 | u32 tmp; |
| 114 | |
| 115 | if (!access_ok (VERIFY_READ, from, sizeof(compat_siginfo_t))) |
| 116 | return -EFAULT; |
| 117 | |
| 118 | err = __get_user(to->si_signo, &from->si_signo); |
| 119 | err |= __get_user(to->si_errno, &from->si_errno); |
| 120 | err |= __get_user(to->si_code, &from->si_code); |
| 121 | |
| 122 | if (to->si_code < 0) |
| 123 | err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); |
| 124 | else { |
| 125 | switch (to->si_code >> 16) { |
| 126 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
| 127 | case __SI_MESGQ >> 16: |
| 128 | err |= __get_user(to->si_int, &from->si_int); |
| 129 | /* fallthrough */ |
| 130 | case __SI_KILL >> 16: |
| 131 | err |= __get_user(to->si_pid, &from->si_pid); |
| 132 | err |= __get_user(to->si_uid, &from->si_uid); |
| 133 | break; |
| 134 | case __SI_CHLD >> 16: |
| 135 | err |= __get_user(to->si_pid, &from->si_pid); |
| 136 | err |= __get_user(to->si_uid, &from->si_uid); |
| 137 | err |= __get_user(to->si_utime, &from->si_utime); |
| 138 | err |= __get_user(to->si_stime, &from->si_stime); |
| 139 | err |= __get_user(to->si_status, &from->si_status); |
| 140 | break; |
| 141 | case __SI_FAULT >> 16: |
| 142 | err |= __get_user(tmp, &from->si_addr); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 143 | to->si_addr = (void __force __user *) |
| 144 | (u64) (tmp & PSW32_ADDR_INSN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | break; |
| 146 | case __SI_POLL >> 16: |
| 147 | err |= __get_user(to->si_band, &from->si_band); |
| 148 | err |= __get_user(to->si_fd, &from->si_fd); |
| 149 | break; |
| 150 | case __SI_TIMER >> 16: |
| 151 | err |= __get_user(to->si_tid, &from->si_tid); |
| 152 | err |= __get_user(to->si_overrun, &from->si_overrun); |
| 153 | err |= __get_user(to->si_int, &from->si_int); |
| 154 | break; |
| 155 | default: |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | return err; |
| 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | asmlinkage long |
| 163 | sys32_sigaction(int sig, const struct old_sigaction32 __user *act, |
| 164 | struct old_sigaction32 __user *oact) |
| 165 | { |
| 166 | struct k_sigaction new_ka, old_ka; |
| 167 | unsigned long sa_handler, sa_restorer; |
| 168 | int ret; |
| 169 | |
| 170 | if (act) { |
| 171 | compat_old_sigset_t mask; |
| 172 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 173 | __get_user(sa_handler, &act->sa_handler) || |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 174 | __get_user(sa_restorer, &act->sa_restorer) || |
| 175 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
| 176 | __get_user(mask, &act->sa_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return -EFAULT; |
| 178 | new_ka.sa.sa_handler = (__sighandler_t) sa_handler; |
| 179 | new_ka.sa.sa_restorer = (void (*)(void)) sa_restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | siginitset(&new_ka.sa.sa_mask, mask); |
| 181 | } |
| 182 | |
| 183 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 184 | |
| 185 | if (!ret && oact) { |
| 186 | sa_handler = (unsigned long) old_ka.sa.sa_handler; |
| 187 | sa_restorer = (unsigned long) old_ka.sa.sa_restorer; |
| 188 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 189 | __put_user(sa_handler, &oact->sa_handler) || |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 190 | __put_user(sa_restorer, &oact->sa_restorer) || |
| 191 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
| 192 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | asmlinkage long |
| 200 | sys32_rt_sigaction(int sig, const struct sigaction32 __user *act, |
| 201 | struct sigaction32 __user *oact, size_t sigsetsize) |
| 202 | { |
| 203 | struct k_sigaction new_ka, old_ka; |
| 204 | unsigned long sa_handler; |
| 205 | int ret; |
| 206 | compat_sigset_t set32; |
| 207 | |
| 208 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 209 | if (sigsetsize != sizeof(compat_sigset_t)) |
| 210 | return -EINVAL; |
| 211 | |
| 212 | if (act) { |
| 213 | ret = get_user(sa_handler, &act->sa_handler); |
| 214 | ret |= __copy_from_user(&set32, &act->sa_mask, |
| 215 | sizeof(compat_sigset_t)); |
Martin Schwidefsky | 399c1d8 | 2011-10-30 15:17:10 +0100 | [diff] [blame] | 216 | new_ka.sa.sa_mask.sig[0] = |
| 217 | set32.sig[0] | (((long)set32.sig[1]) << 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 219 | |
| 220 | if (ret) |
| 221 | return -EFAULT; |
| 222 | new_ka.sa.sa_handler = (__sighandler_t) sa_handler; |
| 223 | } |
| 224 | |
| 225 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 226 | |
| 227 | if (!ret && oact) { |
Martin Schwidefsky | 399c1d8 | 2011-10-30 15:17:10 +0100 | [diff] [blame] | 228 | set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); |
| 229 | set32.sig[0] = old_ka.sa.sa_mask.sig[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | ret = put_user((unsigned long)old_ka.sa.sa_handler, &oact->sa_handler); |
| 231 | ret |= __copy_to_user(&oact->sa_mask, &set32, |
| 232 | sizeof(compat_sigset_t)); |
| 233 | ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 234 | } |
| 235 | |
| 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | asmlinkage long |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 240 | sys32_sigaltstack(const stack_t32 __user *uss, stack_t32 __user *uoss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 242 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | stack_t kss, koss; |
| 244 | unsigned long ss_sp; |
| 245 | int ret, err = 0; |
| 246 | mm_segment_t old_fs = get_fs(); |
| 247 | |
| 248 | if (uss) { |
| 249 | if (!access_ok(VERIFY_READ, uss, sizeof(*uss))) |
| 250 | return -EFAULT; |
| 251 | err |= __get_user(ss_sp, &uss->ss_sp); |
| 252 | err |= __get_user(kss.ss_size, &uss->ss_size); |
| 253 | err |= __get_user(kss.ss_flags, &uss->ss_flags); |
| 254 | if (err) |
| 255 | return -EFAULT; |
Al Viro | c281447 | 2005-09-29 00:16:02 +0100 | [diff] [blame] | 256 | kss.ss_sp = (void __user *) ss_sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | set_fs (KERNEL_DS); |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 260 | ret = do_sigaltstack((stack_t __force __user *) (uss ? &kss : NULL), |
| 261 | (stack_t __force __user *) (uoss ? &koss : NULL), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | regs->gprs[15]); |
| 263 | set_fs (old_fs); |
| 264 | |
| 265 | if (!ret && uoss) { |
| 266 | if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))) |
| 267 | return -EFAULT; |
| 268 | ss_sp = (unsigned long) koss.ss_sp; |
| 269 | err |= __put_user(ss_sp, &uoss->ss_sp); |
| 270 | err |= __put_user(koss.ss_size, &uoss->ss_size); |
| 271 | err |= __put_user(koss.ss_flags, &uoss->ss_flags); |
| 272 | if (err) |
| 273 | return -EFAULT; |
| 274 | } |
| 275 | return ret; |
| 276 | } |
| 277 | |
| 278 | static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs) |
| 279 | { |
| 280 | _s390_regs_common32 regs32; |
| 281 | int err, i; |
| 282 | |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 283 | regs32.psw.mask = psw32_user_bits | |
| 284 | ((__u32)(regs->psw.mask >> 32) & PSW32_MASK_USER); |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 285 | regs32.psw.addr = (__u32) regs->psw.addr | |
| 286 | (__u32)(regs->psw.mask & PSW_MASK_BA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | for (i = 0; i < NUM_GPRS; i++) |
| 288 | regs32.gprs[i] = (__u32) regs->gprs[i]; |
| 289 | save_access_regs(current->thread.acrs); |
| 290 | memcpy(regs32.acrs, current->thread.acrs, sizeof(regs32.acrs)); |
| 291 | err = __copy_to_user(&sregs->regs, ®s32, sizeof(regs32)); |
| 292 | if (err) |
| 293 | return err; |
| 294 | save_fp_regs(¤t->thread.fp_regs); |
| 295 | /* s390_fp_regs and _s390_fp_regs32 are the same ! */ |
| 296 | return __copy_to_user(&sregs->fpregs, ¤t->thread.fp_regs, |
| 297 | sizeof(_s390_fp_regs32)); |
| 298 | } |
| 299 | |
| 300 | static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs) |
| 301 | { |
| 302 | _s390_regs_common32 regs32; |
| 303 | int err, i; |
| 304 | |
| 305 | /* Alwys make any pending restarted system call return -EINTR */ |
| 306 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 307 | |
| 308 | err = __copy_from_user(®s32, &sregs->regs, sizeof(regs32)); |
| 309 | if (err) |
| 310 | return err; |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 311 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) | |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 312 | (__u64)(regs32.psw.mask & PSW32_MASK_USER) << 32 | |
| 313 | (__u64)(regs32.psw.addr & PSW32_ADDR_AMODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | regs->psw.addr = (__u64)(regs32.psw.addr & PSW32_ADDR_INSN); |
| 315 | for (i = 0; i < NUM_GPRS; i++) |
| 316 | regs->gprs[i] = (__u64) regs32.gprs[i]; |
| 317 | memcpy(current->thread.acrs, regs32.acrs, sizeof(current->thread.acrs)); |
| 318 | restore_access_regs(current->thread.acrs); |
| 319 | |
| 320 | err = __copy_from_user(¤t->thread.fp_regs, &sregs->fpregs, |
| 321 | sizeof(_s390_fp_regs32)); |
| 322 | current->thread.fp_regs.fpc &= FPC_VALID_MASK; |
| 323 | if (err) |
| 324 | return err; |
| 325 | |
| 326 | restore_fp_regs(¤t->thread.fp_regs); |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 327 | clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 331 | static int save_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs) |
| 332 | { |
| 333 | __u32 gprs_high[NUM_GPRS]; |
| 334 | int i; |
| 335 | |
| 336 | for (i = 0; i < NUM_GPRS; i++) |
| 337 | gprs_high[i] = regs->gprs[i] >> 32; |
| 338 | |
| 339 | return __copy_to_user(uregs, &gprs_high, sizeof(gprs_high)); |
| 340 | } |
| 341 | |
| 342 | static int restore_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs) |
| 343 | { |
| 344 | __u32 gprs_high[NUM_GPRS]; |
| 345 | int err, i; |
| 346 | |
| 347 | err = __copy_from_user(&gprs_high, uregs, sizeof(gprs_high)); |
| 348 | if (err) |
| 349 | return err; |
| 350 | for (i = 0; i < NUM_GPRS; i++) |
| 351 | *(__u32 *)®s->gprs[i] = gprs_high[i]; |
| 352 | return 0; |
| 353 | } |
| 354 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 355 | asmlinkage long sys32_sigreturn(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 357 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15]; |
| 359 | sigset_t set; |
| 360 | |
| 361 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 362 | goto badframe; |
| 363 | if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32)) |
| 364 | goto badframe; |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 365 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (restore_sigregs32(regs, &frame->sregs)) |
| 367 | goto badframe; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 368 | if (restore_sigregs_gprs_high(regs, frame->gprs_high)) |
| 369 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | badframe: |
| 372 | force_sig(SIGSEGV, current); |
| 373 | return 0; |
| 374 | } |
| 375 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 376 | asmlinkage long sys32_rt_sigreturn(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 378 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15]; |
| 380 | sigset_t set; |
| 381 | stack_t st; |
| 382 | __u32 ss_sp; |
| 383 | int err; |
| 384 | mm_segment_t old_fs = get_fs(); |
| 385 | |
| 386 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 387 | goto badframe; |
| 388 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 389 | goto badframe; |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 390 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if (restore_sigregs32(regs, &frame->uc.uc_mcontext)) |
| 392 | goto badframe; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 393 | if (restore_sigregs_gprs_high(regs, frame->gprs_high)) |
| 394 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | err = __get_user(ss_sp, &frame->uc.uc_stack.ss_sp); |
Al Viro | c281447 | 2005-09-29 00:16:02 +0100 | [diff] [blame] | 396 | st.ss_sp = compat_ptr(ss_sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | err |= __get_user(st.ss_size, &frame->uc.uc_stack.ss_size); |
| 398 | err |= __get_user(st.ss_flags, &frame->uc.uc_stack.ss_flags); |
| 399 | if (err) |
| 400 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | set_fs (KERNEL_DS); |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 402 | do_sigaltstack((stack_t __force __user *)&st, NULL, regs->gprs[15]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | set_fs (old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | badframe: |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 406 | force_sig(SIGSEGV, current); |
| 407 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* |
| 411 | * Set up a signal frame. |
| 412 | */ |
| 413 | |
| 414 | |
| 415 | /* |
| 416 | * Determine which stack to use.. |
| 417 | */ |
| 418 | static inline void __user * |
| 419 | get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) |
| 420 | { |
| 421 | unsigned long sp; |
| 422 | |
| 423 | /* Default to using normal stack */ |
| 424 | sp = (unsigned long) A(regs->gprs[15]); |
| 425 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 426 | /* Overflow on alternate signal stack gives SIGSEGV. */ |
| 427 | if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL)) |
| 428 | return (void __user *) -1UL; |
| 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* This is the X/Open sanctioned signal stack switching. */ |
| 431 | if (ka->sa.sa_flags & SA_ONSTACK) { |
Laurent Meyer | 28f2237 | 2006-04-27 18:40:07 -0700 | [diff] [blame] | 432 | if (! sas_ss_flags(sp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 434 | } |
| 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return (void __user *)((sp - frame_size) & -8ul); |
| 437 | } |
| 438 | |
| 439 | static inline int map_signal(int sig) |
| 440 | { |
| 441 | if (current_thread_info()->exec_domain |
| 442 | && current_thread_info()->exec_domain->signal_invmap |
| 443 | && sig < 32) |
| 444 | return current_thread_info()->exec_domain->signal_invmap[sig]; |
| 445 | else |
| 446 | return sig; |
| 447 | } |
| 448 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 449 | static int setup_frame32(int sig, struct k_sigaction *ka, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | sigset_t *set, struct pt_regs * regs) |
| 451 | { |
| 452 | sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(sigframe32)); |
| 453 | if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe32))) |
| 454 | goto give_sigsegv; |
| 455 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 456 | if (frame == (void __user *) -1UL) |
| 457 | goto give_sigsegv; |
| 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE32)) |
| 460 | goto give_sigsegv; |
| 461 | |
| 462 | if (save_sigregs32(regs, &frame->sregs)) |
| 463 | goto give_sigsegv; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 464 | if (save_sigregs_gprs_high(regs, frame->gprs_high)) |
| 465 | goto give_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (__put_user((unsigned long) &frame->sregs, &frame->sc.sregs)) |
| 467 | goto give_sigsegv; |
| 468 | |
| 469 | /* Set up to return from userspace. If provided, use a stub |
| 470 | already in userspace. */ |
| 471 | if (ka->sa.sa_flags & SA_RESTORER) { |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 472 | regs->gprs[14] = (__u64) ka->sa.sa_restorer | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } else { |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 474 | regs->gprs[14] = (__u64) frame->retcode | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn, |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 476 | (u16 __force __user *)(frame->retcode))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | goto give_sigsegv; |
| 478 | } |
| 479 | |
| 480 | /* Set up backchain. */ |
| 481 | if (__put_user(regs->gprs[15], (unsigned int __user *) frame)) |
| 482 | goto give_sigsegv; |
| 483 | |
| 484 | /* Set up registers for signal handler */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 485 | regs->gprs[15] = (__force __u64) frame; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 486 | regs->psw.mask |= PSW_MASK_BA; /* force amode 31 */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 487 | regs->psw.addr = (__force __u64) ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | regs->gprs[2] = map_signal(sig); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 490 | regs->gprs[3] = (__force __u64) &frame->sc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | /* We forgot to include these in the sigcontext. |
| 493 | To avoid breaking binary compatibility, they are passed as args. */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 494 | if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
| 495 | sig == SIGTRAP || sig == SIGFPE) { |
| 496 | /* set extra registers only for synchronous signals */ |
| 497 | regs->gprs[4] = regs->int_code & 127; |
| 498 | regs->gprs[5] = regs->int_parm_long; |
| 499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
| 501 | /* Place signal number on stack to allow backtrace from handler. */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 502 | if (__put_user(regs->gprs[2], (int __force __user *) &frame->signo)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | goto give_sigsegv; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 504 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | give_sigsegv: |
| 507 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 508 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 511 | static int setup_rt_frame32(int sig, struct k_sigaction *ka, siginfo_t *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | sigset_t *set, struct pt_regs * regs) |
| 513 | { |
| 514 | int err = 0; |
| 515 | rt_sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(rt_sigframe32)); |
| 516 | if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe32))) |
| 517 | goto give_sigsegv; |
| 518 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 519 | if (frame == (void __user *) -1UL) |
| 520 | goto give_sigsegv; |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (copy_siginfo_to_user32(&frame->info, info)) |
| 523 | goto give_sigsegv; |
| 524 | |
| 525 | /* Create the ucontext. */ |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 526 | err |= __put_user(UC_EXTENDED, &frame->uc.uc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | err |= __put_user(0, &frame->uc.uc_link); |
| 528 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
| 529 | err |= __put_user(sas_ss_flags(regs->gprs[15]), |
| 530 | &frame->uc.uc_stack.ss_flags); |
| 531 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 532 | err |= save_sigregs32(regs, &frame->uc.uc_mcontext); |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 533 | err |= save_sigregs_gprs_high(regs, frame->gprs_high); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 535 | if (err) |
| 536 | goto give_sigsegv; |
| 537 | |
| 538 | /* Set up to return from userspace. If provided, use a stub |
| 539 | already in userspace. */ |
| 540 | if (ka->sa.sa_flags & SA_RESTORER) { |
Martin Schwidefsky | 207a054 | 2011-12-27 11:27:30 +0100 | [diff] [blame] | 541 | regs->gprs[14] = (__u64) ka->sa.sa_restorer | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } else { |
Martin Schwidefsky | 207a054 | 2011-12-27 11:27:30 +0100 | [diff] [blame] | 543 | regs->gprs[14] = (__u64) frame->retcode | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | err |= __put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn, |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 545 | (u16 __force __user *)(frame->retcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /* Set up backchain. */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 549 | if (__put_user(regs->gprs[15], (unsigned int __force __user *) frame)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | goto give_sigsegv; |
| 551 | |
| 552 | /* Set up registers for signal handler */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 553 | regs->gprs[15] = (__force __u64) frame; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 554 | regs->psw.mask |= PSW_MASK_BA; /* force amode 31 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | regs->psw.addr = (__u64) ka->sa.sa_handler; |
| 556 | |
| 557 | regs->gprs[2] = map_signal(sig); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 558 | regs->gprs[3] = (__force __u64) &frame->info; |
| 559 | regs->gprs[4] = (__force __u64) &frame->uc; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 560 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | give_sigsegv: |
| 563 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 564 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* |
| 568 | * OK, we're invoking a handler |
| 569 | */ |
| 570 | |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 571 | void handle_signal32(unsigned long sig, struct k_sigaction *ka, |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 572 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 574 | int ret; |
| 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* Set up the stack frame */ |
| 577 | if (ka->sa.sa_flags & SA_SIGINFO) |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 578 | ret = setup_rt_frame32(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | else |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 580 | ret = setup_frame32(sig, ka, oldset, regs); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 581 | if (ret) |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 582 | return; |
Al Viro | efee984 | 2012-04-28 02:04:15 -0400 | [diff] [blame^] | 583 | signal_delivered(sig, info, ka, regs, |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 584 | test_thread_flag(TIF_SINGLE_STEP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |