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