Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2000, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 4 | * Gerhard Tonn (ton@de.ibm.com) |
| 5 | * |
| 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 7 | * |
| 8 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/compat.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/signal.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/unistd.h> |
| 21 | #include <linux/stddef.h> |
| 22 | #include <linux/tty.h> |
| 23 | #include <linux/personality.h> |
| 24 | #include <linux/binfmts.h> |
| 25 | #include <asm/ucontext.h> |
| 26 | #include <asm/uaccess.h> |
| 27 | #include <asm/lowcore.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 28 | #include <asm/switch_to.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "compat_linux.h" |
| 30 | #include "compat_ptrace.h" |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 31 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | typedef struct |
| 34 | { |
| 35 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; |
| 36 | struct sigcontext32 sc; |
| 37 | _sigregs32 sregs; |
| 38 | int signo; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 39 | __u32 gprs_high[NUM_GPRS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 41 | } sigframe32; |
| 42 | |
| 43 | typedef struct |
| 44 | { |
| 45 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; |
| 46 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 47 | compat_siginfo_t info; |
| 48 | struct ucontext32 uc; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 49 | __u32 gprs_high[NUM_GPRS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } rt_sigframe32; |
| 51 | |
Al Viro | ce39596 | 2013-10-13 17:23:53 -0400 | [diff] [blame] | 52 | int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | int err; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* If you change siginfo_t structure, please be sure |
| 57 | this code is fixed accordingly. |
| 58 | It should never copy any pad contained in the structure |
| 59 | to avoid security leaks, but must copy the generic |
| 60 | 3 ints plus the relevant union member. |
| 61 | This routine must convert siginfo from 64bit to 32bit as well |
| 62 | at the same time. */ |
| 63 | err = __put_user(from->si_signo, &to->si_signo); |
| 64 | err |= __put_user(from->si_errno, &to->si_errno); |
| 65 | err |= __put_user((short)from->si_code, &to->si_code); |
| 66 | if (from->si_code < 0) |
| 67 | err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); |
| 68 | else { |
| 69 | switch (from->si_code >> 16) { |
| 70 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
| 71 | case __SI_MESGQ >> 16: |
| 72 | err |= __put_user(from->si_int, &to->si_int); |
| 73 | /* fallthrough */ |
| 74 | case __SI_KILL >> 16: |
| 75 | err |= __put_user(from->si_pid, &to->si_pid); |
| 76 | err |= __put_user(from->si_uid, &to->si_uid); |
| 77 | break; |
| 78 | case __SI_CHLD >> 16: |
| 79 | err |= __put_user(from->si_pid, &to->si_pid); |
| 80 | err |= __put_user(from->si_uid, &to->si_uid); |
| 81 | err |= __put_user(from->si_utime, &to->si_utime); |
| 82 | err |= __put_user(from->si_stime, &to->si_stime); |
| 83 | err |= __put_user(from->si_status, &to->si_status); |
| 84 | break; |
| 85 | case __SI_FAULT >> 16: |
| 86 | err |= __put_user((unsigned long) from->si_addr, |
| 87 | &to->si_addr); |
| 88 | break; |
| 89 | case __SI_POLL >> 16: |
| 90 | err |= __put_user(from->si_band, &to->si_band); |
| 91 | err |= __put_user(from->si_fd, &to->si_fd); |
| 92 | break; |
| 93 | case __SI_TIMER >> 16: |
| 94 | err |= __put_user(from->si_tid, &to->si_tid); |
| 95 | err |= __put_user(from->si_overrun, &to->si_overrun); |
| 96 | err |= __put_user(from->si_int, &to->si_int); |
| 97 | break; |
| 98 | default: |
| 99 | break; |
| 100 | } |
| 101 | } |
Heiko Carstens | 0ebfd31 | 2013-10-14 12:09:37 +0200 | [diff] [blame] | 102 | return err ? -EFAULT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) |
| 106 | { |
| 107 | int err; |
| 108 | u32 tmp; |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | err = __get_user(to->si_signo, &from->si_signo); |
| 111 | err |= __get_user(to->si_errno, &from->si_errno); |
| 112 | err |= __get_user(to->si_code, &from->si_code); |
| 113 | |
| 114 | if (to->si_code < 0) |
| 115 | err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); |
| 116 | else { |
| 117 | switch (to->si_code >> 16) { |
| 118 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
| 119 | case __SI_MESGQ >> 16: |
| 120 | err |= __get_user(to->si_int, &from->si_int); |
| 121 | /* fallthrough */ |
| 122 | case __SI_KILL >> 16: |
| 123 | err |= __get_user(to->si_pid, &from->si_pid); |
| 124 | err |= __get_user(to->si_uid, &from->si_uid); |
| 125 | break; |
| 126 | case __SI_CHLD >> 16: |
| 127 | err |= __get_user(to->si_pid, &from->si_pid); |
| 128 | err |= __get_user(to->si_uid, &from->si_uid); |
| 129 | err |= __get_user(to->si_utime, &from->si_utime); |
| 130 | err |= __get_user(to->si_stime, &from->si_stime); |
| 131 | err |= __get_user(to->si_status, &from->si_status); |
| 132 | break; |
| 133 | case __SI_FAULT >> 16: |
| 134 | err |= __get_user(tmp, &from->si_addr); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 135 | to->si_addr = (void __force __user *) |
| 136 | (u64) (tmp & PSW32_ADDR_INSN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | break; |
| 138 | case __SI_POLL >> 16: |
| 139 | err |= __get_user(to->si_band, &from->si_band); |
| 140 | err |= __get_user(to->si_fd, &from->si_fd); |
| 141 | break; |
| 142 | case __SI_TIMER >> 16: |
| 143 | err |= __get_user(to->si_tid, &from->si_tid); |
| 144 | err |= __get_user(to->si_overrun, &from->si_overrun); |
| 145 | err |= __get_user(to->si_int, &from->si_int); |
| 146 | break; |
| 147 | default: |
| 148 | break; |
| 149 | } |
| 150 | } |
Heiko Carstens | 0ebfd31 | 2013-10-14 12:09:37 +0200 | [diff] [blame] | 151 | return err ? -EFAULT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs) |
| 155 | { |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 156 | _sigregs32 user_sregs; |
| 157 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 159 | user_sregs.regs.psw.mask = (__u32)(regs->psw.mask >> 32); |
| 160 | user_sregs.regs.psw.mask &= PSW32_MASK_USER | PSW32_MASK_RI; |
Heiko Carstens | f26946d | 2013-10-16 14:17:29 +0200 | [diff] [blame] | 161 | user_sregs.regs.psw.mask |= PSW32_USER_BITS; |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 162 | user_sregs.regs.psw.addr = (__u32) regs->psw.addr | |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 163 | (__u32)(regs->psw.mask & PSW_MASK_BA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | for (i = 0; i < NUM_GPRS; i++) |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 165 | user_sregs.regs.gprs[i] = (__u32) regs->gprs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | save_access_regs(current->thread.acrs); |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 167 | memcpy(&user_sregs.regs.acrs, current->thread.acrs, |
| 168 | sizeof(user_sregs.regs.acrs)); |
| 169 | save_fp_ctl(¤t->thread.fp_regs.fpc); |
| 170 | save_fp_regs(current->thread.fp_regs.fprs); |
| 171 | memcpy(&user_sregs.fpregs, ¤t->thread.fp_regs, |
| 172 | sizeof(user_sregs.fpregs)); |
| 173 | if (__copy_to_user(sregs, &user_sregs, sizeof(_sigregs32))) |
Heiko Carstens | f8544ec | 2013-10-14 13:34:28 +0200 | [diff] [blame] | 174 | return -EFAULT; |
| 175 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs) |
| 179 | { |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 180 | _sigregs32 user_sregs; |
| 181 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | /* Alwys make any pending restarted system call return -EINTR */ |
| 184 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 185 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 186 | if (__copy_from_user(&user_sregs, &sregs->regs, sizeof(user_sregs))) |
Heiko Carstens | f8544ec | 2013-10-14 13:34:28 +0200 | [diff] [blame] | 187 | return -EFAULT; |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 188 | |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 189 | if (!is_ri_task(current) && (user_sregs.regs.psw.mask & PSW32_MASK_RI)) |
| 190 | return -EINVAL; |
| 191 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 192 | /* Loading the floating-point-control word can fail. Do that first. */ |
| 193 | if (restore_fp_ctl(&user_sregs.fpregs.fpc)) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | /* Use regs->psw.mask instead of PSW_USER_BITS to preserve PER bit. */ |
Hendrik Brueckner | aa7e04b | 2013-11-19 12:26:09 +0100 | [diff] [blame] | 197 | regs->psw.mask = (regs->psw.mask & ~(PSW_MASK_USER | PSW_MASK_RI)) | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 198 | (__u64)(user_sregs.regs.psw.mask & PSW32_MASK_USER) << 32 | |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 199 | (__u64)(user_sregs.regs.psw.mask & PSW32_MASK_RI) << 32 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 200 | (__u64)(user_sregs.regs.psw.addr & PSW32_ADDR_AMODE); |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 201 | /* Check for invalid user address space control. */ |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 202 | if ((regs->psw.mask & PSW_MASK_ASC) == PSW_ASC_HOME) |
| 203 | regs->psw.mask = PSW_ASC_PRIMARY | |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 204 | (regs->psw.mask & ~PSW_MASK_ASC); |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 205 | regs->psw.addr = (__u64)(user_sregs.regs.psw.addr & PSW32_ADDR_INSN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | for (i = 0; i < NUM_GPRS; i++) |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 207 | regs->gprs[i] = (__u64) user_sregs.regs.gprs[i]; |
| 208 | memcpy(¤t->thread.acrs, &user_sregs.regs.acrs, |
| 209 | sizeof(current->thread.acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | restore_access_regs(current->thread.acrs); |
| 211 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 212 | memcpy(¤t->thread.fp_regs, &user_sregs.fpregs, |
| 213 | sizeof(current->thread.fp_regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 215 | restore_fp_regs(current->thread.fp_regs.fprs); |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 216 | clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 220 | static int save_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs) |
| 221 | { |
| 222 | __u32 gprs_high[NUM_GPRS]; |
| 223 | int i; |
| 224 | |
| 225 | for (i = 0; i < NUM_GPRS; i++) |
| 226 | gprs_high[i] = regs->gprs[i] >> 32; |
Heiko Carstens | f8544ec | 2013-10-14 13:34:28 +0200 | [diff] [blame] | 227 | if (__copy_to_user(uregs, &gprs_high, sizeof(gprs_high))) |
| 228 | return -EFAULT; |
| 229 | return 0; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static int restore_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs) |
| 233 | { |
| 234 | __u32 gprs_high[NUM_GPRS]; |
Heiko Carstens | f8544ec | 2013-10-14 13:34:28 +0200 | [diff] [blame] | 235 | int i; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 236 | |
Heiko Carstens | f8544ec | 2013-10-14 13:34:28 +0200 | [diff] [blame] | 237 | if (__copy_from_user(&gprs_high, uregs, sizeof(gprs_high))) |
| 238 | return -EFAULT; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 239 | for (i = 0; i < NUM_GPRS; i++) |
| 240 | *(__u32 *)®s->gprs[i] = gprs_high[i]; |
| 241 | return 0; |
| 242 | } |
| 243 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 244 | asmlinkage long sys32_sigreturn(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 246 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15]; |
| 248 | sigset_t set; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32)) |
| 251 | goto badframe; |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 252 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (restore_sigregs32(regs, &frame->sregs)) |
| 254 | goto badframe; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 255 | if (restore_sigregs_gprs_high(regs, frame->gprs_high)) |
| 256 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | badframe: |
| 259 | force_sig(SIGSEGV, current); |
| 260 | return 0; |
| 261 | } |
| 262 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 263 | asmlinkage long sys32_rt_sigreturn(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 265 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15]; |
| 267 | sigset_t set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 270 | goto badframe; |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 271 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (restore_sigregs32(regs, &frame->uc.uc_mcontext)) |
| 273 | goto badframe; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 274 | if (restore_sigregs_gprs_high(regs, frame->gprs_high)) |
| 275 | goto badframe; |
Al Viro | e214125 | 2012-12-23 03:36:41 -0500 | [diff] [blame] | 276 | if (compat_restore_altstack(&frame->uc.uc_stack)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | badframe: |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 280 | force_sig(SIGSEGV, current); |
| 281 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Set up a signal frame. |
| 286 | */ |
| 287 | |
| 288 | |
| 289 | /* |
| 290 | * Determine which stack to use.. |
| 291 | */ |
| 292 | static inline void __user * |
| 293 | get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) |
| 294 | { |
| 295 | unsigned long sp; |
| 296 | |
| 297 | /* Default to using normal stack */ |
| 298 | sp = (unsigned long) A(regs->gprs[15]); |
| 299 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 300 | /* Overflow on alternate signal stack gives SIGSEGV. */ |
| 301 | if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL)) |
| 302 | return (void __user *) -1UL; |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* This is the X/Open sanctioned signal stack switching. */ |
| 305 | if (ka->sa.sa_flags & SA_ONSTACK) { |
Laurent Meyer | 28f2237 | 2006-04-27 18:40:07 -0700 | [diff] [blame] | 306 | if (! sas_ss_flags(sp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 308 | } |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return (void __user *)((sp - frame_size) & -8ul); |
| 311 | } |
| 312 | |
| 313 | static inline int map_signal(int sig) |
| 314 | { |
| 315 | if (current_thread_info()->exec_domain |
| 316 | && current_thread_info()->exec_domain->signal_invmap |
| 317 | && sig < 32) |
| 318 | return current_thread_info()->exec_domain->signal_invmap[sig]; |
| 319 | else |
| 320 | return sig; |
| 321 | } |
| 322 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 323 | static int setup_frame32(int sig, struct k_sigaction *ka, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | sigset_t *set, struct pt_regs * regs) |
| 325 | { |
| 326 | sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(sigframe32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 328 | if (frame == (void __user *) -1UL) |
| 329 | goto give_sigsegv; |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE32)) |
| 332 | goto give_sigsegv; |
| 333 | |
| 334 | if (save_sigregs32(regs, &frame->sregs)) |
| 335 | goto give_sigsegv; |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 336 | if (save_sigregs_gprs_high(regs, frame->gprs_high)) |
| 337 | goto give_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (__put_user((unsigned long) &frame->sregs, &frame->sc.sregs)) |
| 339 | goto give_sigsegv; |
| 340 | |
| 341 | /* Set up to return from userspace. If provided, use a stub |
| 342 | already in userspace. */ |
| 343 | if (ka->sa.sa_flags & SA_RESTORER) { |
Heiko Carstens | 5b512be | 2013-09-06 18:52:31 +0200 | [diff] [blame] | 344 | regs->gprs[14] = (__u64 __force) ka->sa.sa_restorer | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } else { |
Heiko Carstens | 5b512be | 2013-09-06 18:52:31 +0200 | [diff] [blame] | 346 | regs->gprs[14] = (__u64 __force) frame->retcode | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn, |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 348 | (u16 __force __user *)(frame->retcode))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | goto give_sigsegv; |
| 350 | } |
| 351 | |
| 352 | /* Set up backchain. */ |
| 353 | if (__put_user(regs->gprs[15], (unsigned int __user *) frame)) |
| 354 | goto give_sigsegv; |
| 355 | |
| 356 | /* Set up registers for signal handler */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 357 | regs->gprs[15] = (__force __u64) frame; |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 358 | /* Force 31 bit amode and default user address space control. */ |
| 359 | regs->psw.mask = PSW_MASK_BA | |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 360 | (PSW_USER_BITS & PSW_MASK_ASC) | |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 361 | (regs->psw.mask & ~PSW_MASK_ASC); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 362 | regs->psw.addr = (__force __u64) ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | regs->gprs[2] = map_signal(sig); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 365 | regs->gprs[3] = (__force __u64) &frame->sc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | /* We forgot to include these in the sigcontext. |
| 368 | To avoid breaking binary compatibility, they are passed as args. */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 369 | if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
| 370 | sig == SIGTRAP || sig == SIGFPE) { |
| 371 | /* set extra registers only for synchronous signals */ |
| 372 | regs->gprs[4] = regs->int_code & 127; |
| 373 | regs->gprs[5] = regs->int_parm_long; |
Michael Holzheu | bd9e034 | 2013-04-15 17:50:03 +0200 | [diff] [blame] | 374 | regs->gprs[6] = task_thread_info(current)->last_break; |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | /* Place signal number on stack to allow backtrace from handler. */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 378 | if (__put_user(regs->gprs[2], (int __force __user *) &frame->signo)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | goto give_sigsegv; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 380 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | give_sigsegv: |
| 383 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 384 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 387 | 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] | 388 | sigset_t *set, struct pt_regs * regs) |
| 389 | { |
| 390 | int err = 0; |
| 391 | rt_sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(rt_sigframe32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 393 | if (frame == (void __user *) -1UL) |
| 394 | goto give_sigsegv; |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (copy_siginfo_to_user32(&frame->info, info)) |
| 397 | goto give_sigsegv; |
| 398 | |
| 399 | /* Create the ucontext. */ |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 400 | err |= __put_user(UC_EXTENDED, &frame->uc.uc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | err |= __put_user(0, &frame->uc.uc_link); |
Al Viro | e214125 | 2012-12-23 03:36:41 -0500 | [diff] [blame] | 402 | err |= __compat_save_altstack(&frame->uc.uc_stack, regs->gprs[15]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | err |= save_sigregs32(regs, &frame->uc.uc_mcontext); |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 404 | err |= save_sigregs_gprs_high(regs, frame->gprs_high); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 406 | if (err) |
| 407 | goto give_sigsegv; |
| 408 | |
| 409 | /* Set up to return from userspace. If provided, use a stub |
| 410 | already in userspace. */ |
| 411 | if (ka->sa.sa_flags & SA_RESTORER) { |
Heiko Carstens | 5b512be | 2013-09-06 18:52:31 +0200 | [diff] [blame] | 412 | regs->gprs[14] = (__u64 __force) ka->sa.sa_restorer | PSW32_ADDR_AMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } else { |
Heiko Carstens | 5b512be | 2013-09-06 18:52:31 +0200 | [diff] [blame] | 414 | regs->gprs[14] = (__u64 __force) frame->retcode | PSW32_ADDR_AMODE; |
Martin Schwidefsky | 41932bc | 2013-12-10 16:18:07 +0100 | [diff] [blame] | 415 | if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn, |
| 416 | (u16 __force __user *)(frame->retcode))) |
| 417 | goto give_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* Set up backchain. */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 421 | if (__put_user(regs->gprs[15], (unsigned int __force __user *) frame)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | goto give_sigsegv; |
| 423 | |
| 424 | /* Set up registers for signal handler */ |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 425 | regs->gprs[15] = (__force __u64) frame; |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 426 | /* Force 31 bit amode and default user address space control. */ |
| 427 | regs->psw.mask = PSW_MASK_BA | |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 428 | (PSW_USER_BITS & PSW_MASK_ASC) | |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 429 | (regs->psw.mask & ~PSW_MASK_ASC); |
Heiko Carstens | 5b512be | 2013-09-06 18:52:31 +0200 | [diff] [blame] | 430 | regs->psw.addr = (__u64 __force) ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | regs->gprs[2] = map_signal(sig); |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 433 | regs->gprs[3] = (__force __u64) &frame->info; |
| 434 | regs->gprs[4] = (__force __u64) &frame->uc; |
Michael Holzheu | bd9e034 | 2013-04-15 17:50:03 +0200 | [diff] [blame] | 435 | regs->gprs[5] = task_thread_info(current)->last_break; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 436 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | give_sigsegv: |
| 439 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 440 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* |
| 444 | * OK, we're invoking a handler |
| 445 | */ |
| 446 | |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 447 | void handle_signal32(unsigned long sig, struct k_sigaction *ka, |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 448 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 450 | int ret; |
| 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* Set up the stack frame */ |
| 453 | if (ka->sa.sa_flags & SA_SIGINFO) |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 454 | ret = setup_rt_frame32(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | else |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 456 | ret = setup_frame32(sig, ka, oldset, regs); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 457 | if (ret) |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 458 | return; |
Al Viro | efee984 | 2012-04-28 02:04:15 -0400 | [diff] [blame] | 459 | signal_delivered(sig, info, ka, regs, |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 460 | test_thread_flag(TIF_SINGLE_STEP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |