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