Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/ptrace.c |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), |
| 7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 8 | * |
| 9 | * Based on PowerPC version |
| 10 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 11 | * |
| 12 | * Derived from "arch/m68k/kernel/ptrace.c" |
| 13 | * Copyright (C) 1994 by Hamish Macdonald |
| 14 | * Taken from linux/kernel/ptrace.c and modified for M680x0. |
| 15 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds |
| 16 | * |
| 17 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 18 | * |
| 19 | * |
| 20 | * This file is subject to the terms and conditions of the GNU General |
| 21 | * Public License. See the file README.legal in the main directory of |
| 22 | * this archive for more details. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/errno.h> |
| 30 | #include <linux/ptrace.h> |
| 31 | #include <linux/user.h> |
| 32 | #include <linux/security.h> |
| 33 | #include <linux/audit.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 34 | #include <linux/signal.h> |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 35 | #include <linux/elf.h> |
| 36 | #include <linux/regset.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 37 | #include <linux/tracehook.h> |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 38 | #include <linux/seccomp.h> |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 39 | #include <trace/syscall.h> |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 40 | #include <asm/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/segment.h> |
| 42 | #include <asm/page.h> |
| 43 | #include <asm/pgtable.h> |
| 44 | #include <asm/pgalloc.h> |
| 45 | #include <asm/system.h> |
| 46 | #include <asm/uaccess.h> |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 47 | #include <asm/unistd.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 48 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 50 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "compat_ptrace.h" |
| 52 | #endif |
| 53 | |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 54 | #define CREATE_TRACE_POINTS |
| 55 | #include <trace/events/syscalls.h> |
Ingo Molnar | 5e9ad7d | 2009-08-18 10:41:57 +0200 | [diff] [blame] | 56 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 57 | enum s390_regset { |
| 58 | REGSET_GENERAL, |
| 59 | REGSET_FP, |
| 60 | }; |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static void |
| 63 | FixPerRegisters(struct task_struct *task) |
| 64 | { |
| 65 | struct pt_regs *regs; |
| 66 | per_struct *per_info; |
| 67 | |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 68 | regs = task_pt_regs(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | per_info = (per_struct *) &task->thread.per_info; |
| 70 | per_info->control_regs.bits.em_instruction_fetch = |
| 71 | per_info->single_step | per_info->instruction_fetch; |
| 72 | |
| 73 | if (per_info->single_step) { |
| 74 | per_info->control_regs.bits.starting_addr = 0; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 75 | #ifdef CONFIG_COMPAT |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 76 | if (is_compat_task()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | per_info->control_regs.bits.ending_addr = 0x7fffffffUL; |
| 78 | else |
| 79 | #endif |
| 80 | per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN; |
| 81 | } else { |
| 82 | per_info->control_regs.bits.starting_addr = |
| 83 | per_info->starting_addr; |
| 84 | per_info->control_regs.bits.ending_addr = |
| 85 | per_info->ending_addr; |
| 86 | } |
| 87 | /* |
| 88 | * if any of the control reg tracing bits are on |
| 89 | * we switch on per in the psw |
| 90 | */ |
| 91 | if (per_info->control_regs.words.cr[0] & PER_EM_MASK) |
| 92 | regs->psw.mask |= PSW_MASK_PER; |
| 93 | else |
| 94 | regs->psw.mask &= ~PSW_MASK_PER; |
| 95 | |
| 96 | if (per_info->control_regs.bits.em_storage_alteration) |
| 97 | per_info->control_regs.bits.storage_alt_space_ctl = 1; |
| 98 | else |
| 99 | per_info->control_regs.bits.storage_alt_space_ctl = 0; |
| 100 | } |
| 101 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 102 | void user_enable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | task->thread.per_info.single_step = 1; |
| 105 | FixPerRegisters(task); |
| 106 | } |
| 107 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 108 | void user_disable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
| 110 | task->thread.per_info.single_step = 0; |
| 111 | FixPerRegisters(task); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Called by kernel/ptrace.c when detaching.. |
| 116 | * |
| 117 | * Make sure single step bits etc are not set. |
| 118 | */ |
| 119 | void |
| 120 | ptrace_disable(struct task_struct *child) |
| 121 | { |
| 122 | /* make sure the single step bit is not set. */ |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 123 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 126 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | # define __ADDR_MASK 3 |
| 128 | #else |
| 129 | # define __ADDR_MASK 7 |
| 130 | #endif |
| 131 | |
| 132 | /* |
| 133 | * Read the word at offset addr from the user area of a process. The |
| 134 | * trouble here is that the information is littered over different |
| 135 | * locations. The process registers are found on the kernel stack, |
| 136 | * the floating point stuff and the trace settings are stored in |
| 137 | * the task structure. In addition the different structures in |
| 138 | * struct user contain pad bytes that should be read as zeroes. |
| 139 | * Lovely... |
| 140 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 141 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct user *dummy = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 144 | addr_t offset, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 147 | /* |
| 148 | * psw and gprs are stored on the stack |
| 149 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 150 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | if (addr == (addr_t) &dummy->regs.psw.mask) |
| 152 | /* Remove per bit from user psw. */ |
| 153 | tmp &= ~PSW_MASK_PER; |
| 154 | |
| 155 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { |
| 156 | /* |
| 157 | * access registers are stored in the thread structure |
| 158 | */ |
| 159 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 160 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 161 | /* |
| 162 | * Very special case: old & broken 64 bit gdb reading |
| 163 | * from acrs[15]. Result is a 64 bit value. Read the |
| 164 | * 32 bit acrs[15] value and shift it by 32. Sick... |
| 165 | */ |
| 166 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 167 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; |
| 168 | else |
| 169 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
| 171 | |
| 172 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 173 | /* |
| 174 | * orig_gpr2 is stored on the kernel stack |
| 175 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 176 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 178 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 179 | /* |
| 180 | * prevent reads of padding hole between |
| 181 | * orig_gpr2 and fp_regs on s390. |
| 182 | */ |
| 183 | tmp = 0; |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 186 | /* |
| 187 | * floating point regs. are stored in the thread structure |
| 188 | */ |
| 189 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 190 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 191 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
| 192 | tmp &= (unsigned long) FPC_VALID_MASK |
| 193 | << (BITS_PER_LONG - 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 196 | /* |
| 197 | * per_info is found in the thread structure |
| 198 | */ |
| 199 | offset = addr - (addr_t) &dummy->regs.per_info; |
| 200 | tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset); |
| 201 | |
| 202 | } else |
| 203 | tmp = 0; |
| 204 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 205 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | static int |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 209 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 211 | addr_t tmp, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 215 | * an alignment of 4. Programmers from hell... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | */ |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 217 | mask = __ADDR_MASK; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 218 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 219 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 220 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 221 | mask = 3; |
| 222 | #endif |
| 223 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return -EIO; |
| 225 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 226 | tmp = __peek_user(child, addr); |
| 227 | return put_user(tmp, (addr_t __user *) data); |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Write a word to the user area of a process at location addr. This |
| 232 | * operation does have an additional problem compared to peek_user. |
| 233 | * Stores to the program status word and on the floating point |
| 234 | * control register needs to get checked for validity. |
| 235 | */ |
| 236 | static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) |
| 237 | { |
| 238 | struct user *dummy = NULL; |
| 239 | addr_t offset; |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 242 | /* |
| 243 | * psw and gprs are stored on the stack |
| 244 | */ |
| 245 | if (addr == (addr_t) &dummy->regs.psw.mask && |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 246 | #ifdef CONFIG_COMPAT |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 247 | data != PSW_MASK_MERGE(psw_user32_bits, data) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #endif |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 249 | data != PSW_MASK_MERGE(psw_user_bits, data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /* Invalid psw mask. */ |
| 251 | return -EINVAL; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 252 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (addr == (addr_t) &dummy->regs.psw.addr) |
| 254 | /* I'd like to reject addresses without the |
| 255 | high order bit but older gdb's rely on it */ |
| 256 | data |= PSW_ADDR_AMODE; |
| 257 | #endif |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 258 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { |
| 261 | /* |
| 262 | * access registers are stored in the thread structure |
| 263 | */ |
| 264 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 265 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 266 | /* |
| 267 | * Very special case: old & broken 64 bit gdb writing |
| 268 | * to acrs[15] with a 64 bit value. Ignore the lower |
| 269 | * half of the value and write the upper 32 bit to |
| 270 | * acrs[15]. Sick... |
| 271 | */ |
| 272 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 273 | child->thread.acrs[15] = (unsigned int) (data >> 32); |
| 274 | else |
| 275 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
| 277 | |
| 278 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 279 | /* |
| 280 | * orig_gpr2 is stored on the kernel stack |
| 281 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 282 | task_pt_regs(child)->orig_gpr2 = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 284 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 285 | /* |
| 286 | * prevent writes of padding hole between |
| 287 | * orig_gpr2 and fp_regs on s390. |
| 288 | */ |
| 289 | return 0; |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 292 | /* |
| 293 | * floating point regs. are stored in the thread structure |
| 294 | */ |
| 295 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 296 | (data & ~((unsigned long) FPC_VALID_MASK |
| 297 | << (BITS_PER_LONG - 32))) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return -EINVAL; |
| 299 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 300 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; |
| 301 | |
| 302 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 303 | /* |
| 304 | * per_info is found in the thread structure |
| 305 | */ |
| 306 | offset = addr - (addr_t) &dummy->regs.per_info; |
| 307 | *(addr_t *)((addr_t) &child->thread.per_info + offset) = data; |
| 308 | |
| 309 | } |
| 310 | |
| 311 | FixPerRegisters(child); |
| 312 | return 0; |
| 313 | } |
| 314 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 315 | static int |
| 316 | poke_user(struct task_struct *child, addr_t addr, addr_t data) |
| 317 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 318 | addr_t mask; |
| 319 | |
| 320 | /* |
| 321 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
| 322 | * an alignment of 4. Programmers from hell indeed... |
| 323 | */ |
| 324 | mask = __ADDR_MASK; |
| 325 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 326 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 327 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 328 | mask = 3; |
| 329 | #endif |
| 330 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
| 331 | return -EIO; |
| 332 | |
| 333 | return __poke_user(child, addr, data); |
| 334 | } |
| 335 | |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 336 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | ptrace_area parea; |
| 339 | int copied, ret; |
| 340 | |
| 341 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | case PTRACE_PEEKUSR: |
| 343 | /* read the word at location addr in the USER area. */ |
| 344 | return peek_user(child, addr, data); |
| 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | case PTRACE_POKEUSR: |
| 347 | /* write the word at location addr in the USER area */ |
| 348 | return poke_user(child, addr, data); |
| 349 | |
| 350 | case PTRACE_PEEKUSR_AREA: |
| 351 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 352 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | sizeof(parea))) |
| 354 | return -EFAULT; |
| 355 | addr = parea.kernel_addr; |
| 356 | data = parea.process_addr; |
| 357 | copied = 0; |
| 358 | while (copied < parea.len) { |
| 359 | if (request == PTRACE_PEEKUSR_AREA) |
| 360 | ret = peek_user(child, addr, data); |
| 361 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 362 | addr_t utmp; |
| 363 | if (get_user(utmp, |
| 364 | (addr_t __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return -EFAULT; |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 366 | ret = poke_user(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | if (ret) |
| 369 | return ret; |
| 370 | addr += sizeof(unsigned long); |
| 371 | data += sizeof(unsigned long); |
| 372 | copied += sizeof(unsigned long); |
| 373 | } |
| 374 | return 0; |
Christian Borntraeger | 07805ac | 2009-09-22 22:58:48 +0200 | [diff] [blame^] | 375 | default: |
| 376 | /* Removing high order bit from addr (only for 31 bit). */ |
| 377 | addr &= PSW_ADDR_INSN; |
| 378 | return ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 382 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* |
| 384 | * Now the fun part starts... a 31 bit program running in the |
| 385 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, |
| 386 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy |
| 387 | * to handle, the difference to the 64 bit versions of the requests |
| 388 | * is that the access is done in multiples of 4 byte instead of |
| 389 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). |
| 390 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, |
| 391 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program |
| 392 | * is a 31 bit program too, the content of struct user can be |
| 393 | * emulated. A 31 bit program peeking into the struct user of |
| 394 | * a 64 bit program is a no-no. |
| 395 | */ |
| 396 | |
| 397 | /* |
| 398 | * Same as peek_user but for a 31 bit program. |
| 399 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 400 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | struct user32 *dummy32 = NULL; |
| 403 | per_struct32 *dummy_per32 = NULL; |
| 404 | addr_t offset; |
| 405 | __u32 tmp; |
| 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | if (addr < (addr_t) &dummy32->regs.acrs) { |
| 408 | /* |
| 409 | * psw and gprs are stored on the stack |
| 410 | */ |
| 411 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
| 412 | /* Fake a 31 bit psw mask. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 413 | tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 414 | tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 416 | /* Fake a 31 bit psw address. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 417 | tmp = (__u32) task_pt_regs(child)->psw.addr | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | PSW32_ADDR_AMODE31; |
| 419 | } else { |
| 420 | /* gpr 0-15 */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 421 | tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | addr*2 + 4); |
| 423 | } |
| 424 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 425 | /* |
| 426 | * access registers are stored in the thread structure |
| 427 | */ |
| 428 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 429 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); |
| 430 | |
| 431 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 432 | /* |
| 433 | * orig_gpr2 is stored on the kernel stack |
| 434 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 435 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 437 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 438 | /* |
| 439 | * prevent reads of padding hole between |
| 440 | * orig_gpr2 and fp_regs on s390. |
| 441 | */ |
| 442 | tmp = 0; |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 445 | /* |
| 446 | * floating point regs. are stored in the thread structure |
| 447 | */ |
| 448 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 449 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); |
| 450 | |
| 451 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 452 | /* |
| 453 | * per_info is found in the thread structure |
| 454 | */ |
| 455 | offset = addr - (addr_t) &dummy32->regs.per_info; |
| 456 | /* This is magic. See per_struct and per_struct32. */ |
| 457 | if ((offset >= (addr_t) &dummy_per32->control_regs && |
| 458 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || |
| 459 | (offset >= (addr_t) &dummy_per32->starting_addr && |
| 460 | offset <= (addr_t) &dummy_per32->ending_addr) || |
| 461 | offset == (addr_t) &dummy_per32->lowcore.words.address) |
| 462 | offset = offset*2 + 4; |
| 463 | else |
| 464 | offset = offset*2; |
| 465 | tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset); |
| 466 | |
| 467 | } else |
| 468 | tmp = 0; |
| 469 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 470 | return tmp; |
| 471 | } |
| 472 | |
| 473 | static int peek_user_compat(struct task_struct *child, |
| 474 | addr_t addr, addr_t data) |
| 475 | { |
| 476 | __u32 tmp; |
| 477 | |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 478 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 479 | return -EIO; |
| 480 | |
| 481 | tmp = __peek_user_compat(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return put_user(tmp, (__u32 __user *) data); |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | * Same as poke_user but for a 31 bit program. |
| 487 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 488 | static int __poke_user_compat(struct task_struct *child, |
| 489 | addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
| 491 | struct user32 *dummy32 = NULL; |
| 492 | per_struct32 *dummy_per32 = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 493 | __u32 tmp = (__u32) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | addr_t offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | if (addr < (addr_t) &dummy32->regs.acrs) { |
| 497 | /* |
| 498 | * psw, gprs, acrs and orig_gpr2 are stored on the stack |
| 499 | */ |
| 500 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
| 501 | /* Build a 64 bit psw mask from 31 bit mask. */ |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 502 | if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* Invalid psw mask. */ |
| 504 | return -EINVAL; |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 505 | task_pt_regs(child)->psw.mask = |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 506 | PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 508 | /* Build a 64 bit psw address from 31 bit address. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 509 | task_pt_regs(child)->psw.addr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | (__u64) tmp & PSW32_ADDR_INSN; |
| 511 | } else { |
| 512 | /* gpr 0-15 */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 513 | *(__u32*)((addr_t) &task_pt_regs(child)->psw |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | + addr*2 + 4) = tmp; |
| 515 | } |
| 516 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 517 | /* |
| 518 | * access registers are stored in the thread structure |
| 519 | */ |
| 520 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 521 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; |
| 522 | |
| 523 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 524 | /* |
| 525 | * orig_gpr2 is stored on the kernel stack |
| 526 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 527 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 529 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 530 | /* |
| 531 | * prevent writess of padding hole between |
| 532 | * orig_gpr2 and fp_regs on s390. |
| 533 | */ |
| 534 | return 0; |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 537 | /* |
| 538 | * floating point regs. are stored in the thread structure |
| 539 | */ |
| 540 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && |
| 541 | (tmp & ~FPC_VALID_MASK) != 0) |
| 542 | /* Invalid floating point control. */ |
| 543 | return -EINVAL; |
| 544 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 545 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; |
| 546 | |
| 547 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 548 | /* |
| 549 | * per_info is found in the thread structure. |
| 550 | */ |
| 551 | offset = addr - (addr_t) &dummy32->regs.per_info; |
| 552 | /* |
| 553 | * This is magic. See per_struct and per_struct32. |
| 554 | * By incident the offsets in per_struct are exactly |
| 555 | * twice the offsets in per_struct32 for all fields. |
| 556 | * The 8 byte fields need special handling though, |
| 557 | * because the second half (bytes 4-7) is needed and |
| 558 | * not the first half. |
| 559 | */ |
| 560 | if ((offset >= (addr_t) &dummy_per32->control_regs && |
| 561 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || |
| 562 | (offset >= (addr_t) &dummy_per32->starting_addr && |
| 563 | offset <= (addr_t) &dummy_per32->ending_addr) || |
| 564 | offset == (addr_t) &dummy_per32->lowcore.words.address) |
| 565 | offset = offset*2 + 4; |
| 566 | else |
| 567 | offset = offset*2; |
| 568 | *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp; |
| 569 | |
| 570 | } |
| 571 | |
| 572 | FixPerRegisters(child); |
| 573 | return 0; |
| 574 | } |
| 575 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 576 | static int poke_user_compat(struct task_struct *child, |
| 577 | addr_t addr, addr_t data) |
| 578 | { |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 579 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user32) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 580 | return -EIO; |
| 581 | |
| 582 | return __poke_user_compat(child, addr, data); |
| 583 | } |
| 584 | |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 585 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
| 586 | compat_ulong_t caddr, compat_ulong_t cdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 588 | unsigned long addr = caddr; |
| 589 | unsigned long data = cdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | ptrace_area_emu31 parea; |
| 591 | int copied, ret; |
| 592 | |
| 593 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | case PTRACE_PEEKUSR: |
| 595 | /* read the word at location addr in the USER area. */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 596 | return peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | case PTRACE_POKEUSR: |
| 599 | /* write the word at location addr in the USER area */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 600 | return poke_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | case PTRACE_PEEKUSR_AREA: |
| 603 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 604 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | sizeof(parea))) |
| 606 | return -EFAULT; |
| 607 | addr = parea.kernel_addr; |
| 608 | data = parea.process_addr; |
| 609 | copied = 0; |
| 610 | while (copied < parea.len) { |
| 611 | if (request == PTRACE_PEEKUSR_AREA) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 612 | ret = peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 614 | __u32 utmp; |
| 615 | if (get_user(utmp, |
| 616 | (__u32 __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | return -EFAULT; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 618 | ret = poke_user_compat(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | if (ret) |
| 621 | return ret; |
| 622 | addr += sizeof(unsigned int); |
| 623 | data += sizeof(unsigned int); |
| 624 | copied += sizeof(unsigned int); |
| 625 | } |
| 626 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 628 | return compat_ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | #endif |
| 631 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 632 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 634 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 636 | /* Do the secure computing check first. */ |
| 637 | secure_computing(regs->gprs[2]); |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 640 | * The sysc_tracesys code in entry.S stored the system |
| 641 | * call number to gprs[2]. |
Bodo Stroesser | c5c3a6d | 2005-06-04 15:43:32 -0700 | [diff] [blame] | 642 | */ |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 643 | ret = regs->gprs[2]; |
| 644 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 645 | (tracehook_report_syscall_entry(regs) || |
| 646 | regs->gprs[2] >= NR_syscalls)) { |
| 647 | /* |
| 648 | * Tracing decided this syscall should not happen or the |
| 649 | * debugger stored an invalid system call number. Skip |
| 650 | * the system call and the system call restart handling. |
| 651 | */ |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 652 | regs->svcnr = 0; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 653 | ret = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 655 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 656 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 657 | trace_sys_enter(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 658 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 659 | if (unlikely(current->audit_context)) |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 660 | audit_syscall_entry(is_compat_task() ? |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 661 | AUDIT_ARCH_S390 : AUDIT_ARCH_S390X, |
| 662 | regs->gprs[2], regs->orig_gpr2, |
| 663 | regs->gprs[3], regs->gprs[4], |
| 664 | regs->gprs[5]); |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) |
| 669 | { |
| 670 | if (unlikely(current->audit_context)) |
| 671 | audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), |
| 672 | regs->gprs[2]); |
| 673 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 674 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 675 | trace_sys_exit(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 676 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 677 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
| 678 | tracehook_report_syscall_exit(regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 680 | |
| 681 | /* |
| 682 | * user_regset definitions. |
| 683 | */ |
| 684 | |
| 685 | static int s390_regs_get(struct task_struct *target, |
| 686 | const struct user_regset *regset, |
| 687 | unsigned int pos, unsigned int count, |
| 688 | void *kbuf, void __user *ubuf) |
| 689 | { |
| 690 | if (target == current) |
| 691 | save_access_regs(target->thread.acrs); |
| 692 | |
| 693 | if (kbuf) { |
| 694 | unsigned long *k = kbuf; |
| 695 | while (count > 0) { |
| 696 | *k++ = __peek_user(target, pos); |
| 697 | count -= sizeof(*k); |
| 698 | pos += sizeof(*k); |
| 699 | } |
| 700 | } else { |
| 701 | unsigned long __user *u = ubuf; |
| 702 | while (count > 0) { |
| 703 | if (__put_user(__peek_user(target, pos), u++)) |
| 704 | return -EFAULT; |
| 705 | count -= sizeof(*u); |
| 706 | pos += sizeof(*u); |
| 707 | } |
| 708 | } |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static int s390_regs_set(struct task_struct *target, |
| 713 | const struct user_regset *regset, |
| 714 | unsigned int pos, unsigned int count, |
| 715 | const void *kbuf, const void __user *ubuf) |
| 716 | { |
| 717 | int rc = 0; |
| 718 | |
| 719 | if (target == current) |
| 720 | save_access_regs(target->thread.acrs); |
| 721 | |
| 722 | if (kbuf) { |
| 723 | const unsigned long *k = kbuf; |
| 724 | while (count > 0 && !rc) { |
| 725 | rc = __poke_user(target, pos, *k++); |
| 726 | count -= sizeof(*k); |
| 727 | pos += sizeof(*k); |
| 728 | } |
| 729 | } else { |
| 730 | const unsigned long __user *u = ubuf; |
| 731 | while (count > 0 && !rc) { |
| 732 | unsigned long word; |
| 733 | rc = __get_user(word, u++); |
| 734 | if (rc) |
| 735 | break; |
| 736 | rc = __poke_user(target, pos, word); |
| 737 | count -= sizeof(*u); |
| 738 | pos += sizeof(*u); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | if (rc == 0 && target == current) |
| 743 | restore_access_regs(target->thread.acrs); |
| 744 | |
| 745 | return rc; |
| 746 | } |
| 747 | |
| 748 | static int s390_fpregs_get(struct task_struct *target, |
| 749 | const struct user_regset *regset, unsigned int pos, |
| 750 | unsigned int count, void *kbuf, void __user *ubuf) |
| 751 | { |
| 752 | if (target == current) |
| 753 | save_fp_regs(&target->thread.fp_regs); |
| 754 | |
| 755 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 756 | &target->thread.fp_regs, 0, -1); |
| 757 | } |
| 758 | |
| 759 | static int s390_fpregs_set(struct task_struct *target, |
| 760 | const struct user_regset *regset, unsigned int pos, |
| 761 | unsigned int count, const void *kbuf, |
| 762 | const void __user *ubuf) |
| 763 | { |
| 764 | int rc = 0; |
| 765 | |
| 766 | if (target == current) |
| 767 | save_fp_regs(&target->thread.fp_regs); |
| 768 | |
| 769 | /* If setting FPC, must validate it first. */ |
| 770 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { |
| 771 | u32 fpc[2] = { target->thread.fp_regs.fpc, 0 }; |
| 772 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc, |
| 773 | 0, offsetof(s390_fp_regs, fprs)); |
| 774 | if (rc) |
| 775 | return rc; |
| 776 | if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0) |
| 777 | return -EINVAL; |
| 778 | target->thread.fp_regs.fpc = fpc[0]; |
| 779 | } |
| 780 | |
| 781 | if (rc == 0 && count > 0) |
| 782 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 783 | target->thread.fp_regs.fprs, |
| 784 | offsetof(s390_fp_regs, fprs), -1); |
| 785 | |
| 786 | if (rc == 0 && target == current) |
| 787 | restore_fp_regs(&target->thread.fp_regs); |
| 788 | |
| 789 | return rc; |
| 790 | } |
| 791 | |
| 792 | static const struct user_regset s390_regsets[] = { |
| 793 | [REGSET_GENERAL] = { |
| 794 | .core_note_type = NT_PRSTATUS, |
| 795 | .n = sizeof(s390_regs) / sizeof(long), |
| 796 | .size = sizeof(long), |
| 797 | .align = sizeof(long), |
| 798 | .get = s390_regs_get, |
| 799 | .set = s390_regs_set, |
| 800 | }, |
| 801 | [REGSET_FP] = { |
| 802 | .core_note_type = NT_PRFPREG, |
| 803 | .n = sizeof(s390_fp_regs) / sizeof(long), |
| 804 | .size = sizeof(long), |
| 805 | .align = sizeof(long), |
| 806 | .get = s390_fpregs_get, |
| 807 | .set = s390_fpregs_set, |
| 808 | }, |
| 809 | }; |
| 810 | |
| 811 | static const struct user_regset_view user_s390_view = { |
| 812 | .name = UTS_MACHINE, |
| 813 | .e_machine = EM_S390, |
| 814 | .regsets = s390_regsets, |
| 815 | .n = ARRAY_SIZE(s390_regsets) |
| 816 | }; |
| 817 | |
| 818 | #ifdef CONFIG_COMPAT |
| 819 | static int s390_compat_regs_get(struct task_struct *target, |
| 820 | const struct user_regset *regset, |
| 821 | unsigned int pos, unsigned int count, |
| 822 | void *kbuf, void __user *ubuf) |
| 823 | { |
| 824 | if (target == current) |
| 825 | save_access_regs(target->thread.acrs); |
| 826 | |
| 827 | if (kbuf) { |
| 828 | compat_ulong_t *k = kbuf; |
| 829 | while (count > 0) { |
| 830 | *k++ = __peek_user_compat(target, pos); |
| 831 | count -= sizeof(*k); |
| 832 | pos += sizeof(*k); |
| 833 | } |
| 834 | } else { |
| 835 | compat_ulong_t __user *u = ubuf; |
| 836 | while (count > 0) { |
| 837 | if (__put_user(__peek_user_compat(target, pos), u++)) |
| 838 | return -EFAULT; |
| 839 | count -= sizeof(*u); |
| 840 | pos += sizeof(*u); |
| 841 | } |
| 842 | } |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | static int s390_compat_regs_set(struct task_struct *target, |
| 847 | const struct user_regset *regset, |
| 848 | unsigned int pos, unsigned int count, |
| 849 | const void *kbuf, const void __user *ubuf) |
| 850 | { |
| 851 | int rc = 0; |
| 852 | |
| 853 | if (target == current) |
| 854 | save_access_regs(target->thread.acrs); |
| 855 | |
| 856 | if (kbuf) { |
| 857 | const compat_ulong_t *k = kbuf; |
| 858 | while (count > 0 && !rc) { |
| 859 | rc = __poke_user_compat(target, pos, *k++); |
| 860 | count -= sizeof(*k); |
| 861 | pos += sizeof(*k); |
| 862 | } |
| 863 | } else { |
| 864 | const compat_ulong_t __user *u = ubuf; |
| 865 | while (count > 0 && !rc) { |
| 866 | compat_ulong_t word; |
| 867 | rc = __get_user(word, u++); |
| 868 | if (rc) |
| 869 | break; |
| 870 | rc = __poke_user_compat(target, pos, word); |
| 871 | count -= sizeof(*u); |
| 872 | pos += sizeof(*u); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | if (rc == 0 && target == current) |
| 877 | restore_access_regs(target->thread.acrs); |
| 878 | |
| 879 | return rc; |
| 880 | } |
| 881 | |
| 882 | static const struct user_regset s390_compat_regsets[] = { |
| 883 | [REGSET_GENERAL] = { |
| 884 | .core_note_type = NT_PRSTATUS, |
| 885 | .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), |
| 886 | .size = sizeof(compat_long_t), |
| 887 | .align = sizeof(compat_long_t), |
| 888 | .get = s390_compat_regs_get, |
| 889 | .set = s390_compat_regs_set, |
| 890 | }, |
| 891 | [REGSET_FP] = { |
| 892 | .core_note_type = NT_PRFPREG, |
| 893 | .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), |
| 894 | .size = sizeof(compat_long_t), |
| 895 | .align = sizeof(compat_long_t), |
| 896 | .get = s390_fpregs_get, |
| 897 | .set = s390_fpregs_set, |
| 898 | }, |
| 899 | }; |
| 900 | |
| 901 | static const struct user_regset_view user_s390_compat_view = { |
| 902 | .name = "s390", |
| 903 | .e_machine = EM_S390, |
| 904 | .regsets = s390_compat_regsets, |
| 905 | .n = ARRAY_SIZE(s390_compat_regsets) |
| 906 | }; |
| 907 | #endif |
| 908 | |
| 909 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 910 | { |
| 911 | #ifdef CONFIG_COMPAT |
| 912 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 913 | return &user_s390_compat_view; |
| 914 | #endif |
| 915 | return &user_s390_view; |
| 916 | } |