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