blob: e204fc49517d56e8b60105955d02a09087bf63bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Kernel support for the ptrace() and syscall tracing interfaces.
3 *
4 * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
5 * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
6 * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
Helge Deller64e2a422016-04-01 22:40:53 +02007 * Copyright (C) 2008-2016 Helge Deller <deller@gmx.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
Helge Deller64e2a422016-04-01 22:40:53 +020014#include <linux/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/errno.h>
16#include <linux/ptrace.h>
Kyle McMartind6b58772009-04-26 23:53:34 -040017#include <linux/tracehook.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/user.h>
19#include <linux/personality.h>
Helge Deller64e2a422016-04-01 22:40:53 +020020#include <linux/regset.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/security.h>
Helge Dellerfe5c8732014-09-21 21:01:15 +020022#include <linux/seccomp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/compat.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070024#include <linux/signal.h>
Helge Deller527973c2013-10-15 19:25:46 +020025#include <linux/audit.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/uaccess.h>
28#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/processor.h>
Sam Ravnborg0013a852005-09-09 20:57:26 +020030#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* PSW bits we allow the debugger to modify */
John David Anglin34360f02012-12-28 23:18:01 +000033#define USER_PSW_BITS (PSW_N | PSW_B | PSW_V | PSW_CB)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Helge Dellerfc791682016-04-13 22:44:54 +020035#define CREATE_TRACE_POINTS
36#include <trace/events/syscalls.h>
37
Helge Deller81e192d2008-10-17 18:48:36 +000038/*
Helge Deller64e2a422016-04-01 22:40:53 +020039 * These are our native regset flavors.
40 */
41enum parisc_regset {
42 REGSET_GENERAL,
43 REGSET_FP
44};
45
46/*
Helge Deller81e192d2008-10-17 18:48:36 +000047 * Called by kernel/ptrace.c when detaching..
48 *
49 * Make sure single step bits etc are not set.
50 */
51void ptrace_disable(struct task_struct *task)
52{
Kyle McMartinecd3d4b2009-09-27 23:03:02 -040053 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
54 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Helge Deller81e192d2008-10-17 18:48:36 +000056 /* make sure the trap bits are not set */
57 pa_psw(task)->r = 0;
58 pa_psw(task)->t = 0;
59 pa_psw(task)->h = 0;
60 pa_psw(task)->l = 0;
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Helge Deller81e192d2008-10-17 18:48:36 +000063/*
64 * The following functions are called by ptrace_resume() when
65 * enabling or disabling single/block tracing.
66 */
67void user_disable_single_step(struct task_struct *task)
68{
69 ptrace_disable(task);
70}
71
72void user_enable_single_step(struct task_struct *task)
73{
Kyle McMartinecd3d4b2009-09-27 23:03:02 -040074 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
75 set_tsk_thread_flag(task, TIF_SINGLESTEP);
Helge Deller81e192d2008-10-17 18:48:36 +000076
77 if (pa_psw(task)->n) {
78 struct siginfo si;
79
80 /* Nullified, just crank over the queue. */
81 task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
82 task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
83 task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
84 pa_psw(task)->n = 0;
85 pa_psw(task)->x = 0;
86 pa_psw(task)->y = 0;
87 pa_psw(task)->z = 0;
88 pa_psw(task)->b = 0;
89 ptrace_disable(task);
90 /* Don't wake up the task, but let the
91 parent know something happened. */
92 si.si_code = TRAP_TRACE;
93 si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
94 si.si_signo = SIGTRAP;
95 si.si_errno = 0;
96 force_sig_info(SIGTRAP, &si, task);
97 /* notify_parent(task, SIGCHLD); */
98 return;
99 }
100
101 /* Enable recovery counter traps. The recovery counter
102 * itself will be set to zero on a task switch. If the
103 * task is suspended on a syscall then the syscall return
104 * path will overwrite the recovery counter with a suitable
105 * value such that it traps once back in user space. We
106 * disable interrupts in the tasks PSW here also, to avoid
107 * interrupts while the recovery counter is decrementing.
108 */
109 pa_psw(task)->r = 1;
110 pa_psw(task)->t = 0;
111 pa_psw(task)->h = 0;
112 pa_psw(task)->l = 0;
113}
114
115void user_enable_block_step(struct task_struct *task)
116{
Kyle McMartinecd3d4b2009-09-27 23:03:02 -0400117 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
118 set_tsk_thread_flag(task, TIF_BLOCKSTEP);
Helge Deller81e192d2008-10-17 18:48:36 +0000119
120 /* Enable taken branch trap. */
121 pa_psw(task)->r = 0;
122 pa_psw(task)->t = 1;
123 pa_psw(task)->h = 0;
124 pa_psw(task)->l = 0;
125}
126
Namhyung Kim9b05a692010-10-27 15:33:47 -0700127long arch_ptrace(struct task_struct *child, long request,
128 unsigned long addr, unsigned long data)
Helge Deller81e192d2008-10-17 18:48:36 +0000129{
Helge Deller64e2a422016-04-01 22:40:53 +0200130 unsigned long __user *datap = (unsigned long __user *)data;
Helge Deller81e192d2008-10-17 18:48:36 +0000131 unsigned long tmp;
132 long ret = -EIO;
133
134 switch (request) {
135
136 /* Read the word at location addr in the USER area. For ptraced
137 processes, the kernel saves all regs on a syscall. */
138 case PTRACE_PEEKUSR:
Namhyung Kim9b05a692010-10-27 15:33:47 -0700139 if ((addr & (sizeof(unsigned long)-1)) ||
140 addr >= sizeof(struct pt_regs))
Helge Deller81e192d2008-10-17 18:48:36 +0000141 break;
142 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
Helge Deller64e2a422016-04-01 22:40:53 +0200143 ret = put_user(tmp, datap);
Helge Deller81e192d2008-10-17 18:48:36 +0000144 break;
145
146 /* Write the word at location addr in the USER area. This will need
147 to change when the kernel no longer saves all regs on a syscall.
148 FIXME. There is a problem at the moment in that r3-r18 are only
149 saved if the process is ptraced on syscall entry, and even then
150 those values are overwritten by actual register values on syscall
151 exit. */
152 case PTRACE_POKEUSR:
153 /* Some register values written here may be ignored in
154 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
155 * r31/r31+4, and not with the values in pt_regs.
156 */
157 if (addr == PT_PSW) {
158 /* Allow writing to Nullify, Divide-step-correction,
159 * and carry/borrow bits.
160 * BEWARE, if you set N, and then single step, it won't
161 * stop on the nullified instruction.
162 */
163 data &= USER_PSW_BITS;
164 task_regs(child)->gr[0] &= ~USER_PSW_BITS;
165 task_regs(child)->gr[0] |= data;
166 ret = 0;
167 break;
168 }
169
Namhyung Kim9b05a692010-10-27 15:33:47 -0700170 if ((addr & (sizeof(unsigned long)-1)) ||
171 addr >= sizeof(struct pt_regs))
Helge Deller81e192d2008-10-17 18:48:36 +0000172 break;
Helge Dellerd0c4b052019-07-16 21:43:11 +0200173 if (addr == PT_IAOQ0 || addr == PT_IAOQ1) {
174 data |= 3; /* ensure userspace privilege */
175 }
Helge Deller81e192d2008-10-17 18:48:36 +0000176 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
177 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
178 (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
179 addr == PT_SAR) {
180 *(unsigned long *) ((char *) task_regs(child) + addr) = data;
181 ret = 0;
182 }
183 break;
184
Helge Deller64e2a422016-04-01 22:40:53 +0200185 case PTRACE_GETREGS: /* Get all gp regs from the child. */
186 return copy_regset_to_user(child,
187 task_user_regset_view(current),
188 REGSET_GENERAL,
189 0, sizeof(struct user_regs_struct),
190 datap);
191
192 case PTRACE_SETREGS: /* Set all gp regs in the child. */
193 return copy_regset_from_user(child,
194 task_user_regset_view(current),
195 REGSET_GENERAL,
196 0, sizeof(struct user_regs_struct),
197 datap);
198
199 case PTRACE_GETFPREGS: /* Get the child FPU state. */
200 return copy_regset_to_user(child,
201 task_user_regset_view(current),
202 REGSET_FP,
203 0, sizeof(struct user_fp_struct),
204 datap);
205
206 case PTRACE_SETFPREGS: /* Set the child FPU state. */
207 return copy_regset_from_user(child,
208 task_user_regset_view(current),
209 REGSET_FP,
210 0, sizeof(struct user_fp_struct),
211 datap);
212
Helge Deller81e192d2008-10-17 18:48:36 +0000213 default:
214 ret = ptrace_request(child, request, addr, data);
215 break;
216 }
217
218 return ret;
219}
220
221
222#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224/* This function is needed to translate 32 bit pt_regs offsets in to
225 * 64 bit pt_regs offsets. For example, a 32 bit gdb under a 64 bit kernel
226 * will request offset 12 if it wants gr3, but the lower 32 bits of
227 * the 64 bit kernels view of gr3 will be at offset 28 (3*8 + 4).
228 * This code relies on a 32 bit pt_regs being comprised of 32 bit values
229 * except for the fp registers which (a) are 64 bits, and (b) follow
230 * the gr registers at the start of pt_regs. The 32 bit pt_regs should
231 * be half the size of the 64 bit pt_regs, plus 32*4 to allow for fr[]
232 * being 64 bit in both cases.
233 */
234
Helge Dellered79b862008-11-20 10:54:09 +0100235static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Helge Dellerd0c4b052019-07-16 21:43:11 +0200237 compat_ulong_t pos;
238
239 if (offset < 32*4) /* gr[0..31] */
240 pos = offset * 2 + 4;
241 else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */
242 pos = (offset - 32*4) + PT_FR0;
243 else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */
244 pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 else
Helge Dellerd0c4b052019-07-16 21:43:11 +0200246 pos = sizeof(struct pt_regs);
247
248 return pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Helge Deller81e192d2008-10-17 18:48:36 +0000251long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
252 compat_ulong_t addr, compat_ulong_t data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Helge Deller81e192d2008-10-17 18:48:36 +0000254 compat_uint_t tmp;
255 long ret = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Helge Deller81e192d2008-10-17 18:48:36 +0000259 case PTRACE_PEEKUSR:
260 if (addr & (sizeof(compat_uint_t)-1))
261 break;
262 addr = translate_usr_offset(addr);
Helge Dellered79b862008-11-20 10:54:09 +0100263 if (addr >= sizeof(struct pt_regs))
Helge Deller81e192d2008-10-17 18:48:36 +0000264 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Helge Deller81e192d2008-10-17 18:48:36 +0000266 tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
267 ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Write the word at location addr in the USER area. This will need
271 to change when the kernel no longer saves all regs on a syscall.
272 FIXME. There is a problem at the moment in that r3-r18 are only
273 saved if the process is ptraced on syscall entry, and even then
274 those values are overwritten by actual register values on syscall
275 exit. */
276 case PTRACE_POKEUSR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Some register values written here may be ignored in
278 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
279 * r31/r31+4, and not with the values in pt_regs.
280 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (addr == PT_PSW) {
Helge Deller81e192d2008-10-17 18:48:36 +0000282 /* Since PT_PSW==0, it is valid for 32 bit processes
283 * under 64 bit kernels as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
Helge Deller81e192d2008-10-17 18:48:36 +0000285 ret = arch_ptrace(child, request, addr, data);
286 } else {
287 if (addr & (sizeof(compat_uint_t)-1))
288 break;
289 addr = translate_usr_offset(addr);
Helge Dellered79b862008-11-20 10:54:09 +0100290 if (addr >= sizeof(struct pt_regs))
Helge Deller81e192d2008-10-17 18:48:36 +0000291 break;
Helge Dellerd0c4b052019-07-16 21:43:11 +0200292 if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) {
293 data |= 3; /* ensure userspace privilege */
294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
296 /* Special case, fp regs are 64 bits anyway */
Helge Dellerd0c4b052019-07-16 21:43:11 +0200297 *(__u32 *) ((char *) task_regs(child) + addr) = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ret = 0;
299 }
300 else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
301 addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
302 addr == PT_SAR+4) {
303 /* Zero the top 32 bits */
Helge Deller81e192d2008-10-17 18:48:36 +0000304 *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
305 *(__u32 *) ((char *) task_regs(child) + addr) = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 ret = 0;
307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
Helge Deller81e192d2008-10-17 18:48:36 +0000309 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 default:
Helge Deller81e192d2008-10-17 18:48:36 +0000312 ret = compat_ptrace_request(child, request, addr, data);
313 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return ret;
317}
Helge Deller81e192d2008-10-17 18:48:36 +0000318#endif
319
Kyle McMartin2798af12009-07-05 14:36:16 -0400320long do_syscall_trace_enter(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Dmitry V. Levine9f06132019-02-16 16:10:39 +0300322 if (test_thread_flag(TIF_SYSCALL_TRACE)) {
323 int rc = tracehook_report_syscall_entry(regs);
324
Helge Deller98e8b6c2016-01-19 16:08:49 +0100325 /*
Dmitry V. Levine9f06132019-02-16 16:10:39 +0300326 * As tracesys_next does not set %r28 to -ENOSYS
327 * when %r20 is set to -1, initialize it here.
Helge Deller98e8b6c2016-01-19 16:08:49 +0100328 */
Dmitry V. Levine9f06132019-02-16 16:10:39 +0300329 regs->gr[28] = -ENOSYS;
330
331 if (rc) {
332 /*
333 * A nonzero return code from
334 * tracehook_report_syscall_entry() tells us
335 * to prevent the syscall execution. Skip
336 * the syscall call and the syscall restart handling.
337 *
338 * Note that the tracer may also just change
339 * regs->gr[20] to an invalid syscall number,
340 * that is handled by tracesys_next.
341 */
342 regs->gr[20] = -1UL;
343 return -1;
344 }
Helge Deller98e8b6c2016-01-19 16:08:49 +0100345 }
Kees Cook375f0182016-06-02 13:15:52 -0700346
347 /* Do the secure computing check after ptrace. */
348 if (secure_computing(NULL) == -1)
349 return -1;
350
Helge Dellerfc791682016-04-13 22:44:54 +0200351#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
352 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
353 trace_sys_enter(regs, regs->gr[20]);
354#endif
Kyle McMartind6b58772009-04-26 23:53:34 -0400355
Helge Deller527973c2013-10-15 19:25:46 +0200356#ifdef CONFIG_64BIT
357 if (!is_compat_task())
Eric Paris91397402014-03-11 13:29:28 -0400358 audit_syscall_entry(regs->gr[20], regs->gr[26], regs->gr[25],
359 regs->gr[24], regs->gr[23]);
Helge Deller527973c2013-10-15 19:25:46 +0200360 else
361#endif
Eric Paris91397402014-03-11 13:29:28 -0400362 audit_syscall_entry(regs->gr[20] & 0xffffffff,
Helge Deller527973c2013-10-15 19:25:46 +0200363 regs->gr[26] & 0xffffffff,
364 regs->gr[25] & 0xffffffff,
365 regs->gr[24] & 0xffffffff,
366 regs->gr[23] & 0xffffffff);
367
Helge Deller910cd322016-03-30 14:14:31 +0200368 /*
369 * Sign extend the syscall number to 64bit since it may have been
370 * modified by a compat ptrace call
371 */
372 return (int) ((u32) regs->gr[20]);
Kyle McMartin2798af12009-07-05 14:36:16 -0400373}
374
375void do_syscall_trace_exit(struct pt_regs *regs)
376{
Kyle McMartinecd3d4b2009-09-27 23:03:02 -0400377 int stepping = test_thread_flag(TIF_SINGLESTEP) ||
378 test_thread_flag(TIF_BLOCKSTEP);
Kyle McMartin2798af12009-07-05 14:36:16 -0400379
Helge Deller527973c2013-10-15 19:25:46 +0200380 audit_syscall_exit(regs);
381
Helge Dellerfc791682016-04-13 22:44:54 +0200382#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
383 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
384 trace_sys_exit(regs, regs->gr[20]);
385#endif
386
Kyle McMartin2798af12009-07-05 14:36:16 -0400387 if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
388 tracehook_report_syscall_exit(regs, stepping);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
Helge Deller64e2a422016-04-01 22:40:53 +0200390
391
392/*
393 * regset functions.
394 */
395
396static int fpr_get(struct task_struct *target,
397 const struct user_regset *regset,
398 unsigned int pos, unsigned int count,
399 void *kbuf, void __user *ubuf)
400{
401 struct pt_regs *regs = task_regs(target);
402 __u64 *k = kbuf;
403 __u64 __user *u = ubuf;
404 __u64 reg;
405
406 pos /= sizeof(reg);
407 count /= sizeof(reg);
408
409 if (kbuf)
410 for (; count > 0 && pos < ELF_NFPREG; --count)
411 *k++ = regs->fr[pos++];
412 else
413 for (; count > 0 && pos < ELF_NFPREG; --count)
414 if (__put_user(regs->fr[pos++], u++))
415 return -EFAULT;
416
417 kbuf = k;
418 ubuf = u;
419 pos *= sizeof(reg);
420 count *= sizeof(reg);
421 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
422 ELF_NFPREG * sizeof(reg), -1);
423}
424
425static int fpr_set(struct task_struct *target,
426 const struct user_regset *regset,
427 unsigned int pos, unsigned int count,
428 const void *kbuf, const void __user *ubuf)
429{
430 struct pt_regs *regs = task_regs(target);
431 const __u64 *k = kbuf;
432 const __u64 __user *u = ubuf;
433 __u64 reg;
434
435 pos /= sizeof(reg);
436 count /= sizeof(reg);
437
438 if (kbuf)
439 for (; count > 0 && pos < ELF_NFPREG; --count)
440 regs->fr[pos++] = *k++;
441 else
442 for (; count > 0 && pos < ELF_NFPREG; --count) {
443 if (__get_user(reg, u++))
444 return -EFAULT;
445 regs->fr[pos++] = reg;
446 }
447
448 kbuf = k;
449 ubuf = u;
450 pos *= sizeof(reg);
451 count *= sizeof(reg);
452 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
453 ELF_NFPREG * sizeof(reg), -1);
454}
455
456#define RI(reg) (offsetof(struct user_regs_struct,reg) / sizeof(long))
457
458static unsigned long get_reg(struct pt_regs *regs, int num)
459{
460 switch (num) {
461 case RI(gr[0]) ... RI(gr[31]): return regs->gr[num - RI(gr[0])];
462 case RI(sr[0]) ... RI(sr[7]): return regs->sr[num - RI(sr[0])];
463 case RI(iasq[0]): return regs->iasq[0];
464 case RI(iasq[1]): return regs->iasq[1];
465 case RI(iaoq[0]): return regs->iaoq[0];
466 case RI(iaoq[1]): return regs->iaoq[1];
467 case RI(sar): return regs->sar;
468 case RI(iir): return regs->iir;
469 case RI(isr): return regs->isr;
470 case RI(ior): return regs->ior;
471 case RI(ipsw): return regs->ipsw;
472 case RI(cr27): return regs->cr27;
473 case RI(cr0): return mfctl(0);
474 case RI(cr24): return mfctl(24);
475 case RI(cr25): return mfctl(25);
476 case RI(cr26): return mfctl(26);
477 case RI(cr28): return mfctl(28);
478 case RI(cr29): return mfctl(29);
479 case RI(cr30): return mfctl(30);
480 case RI(cr31): return mfctl(31);
481 case RI(cr8): return mfctl(8);
482 case RI(cr9): return mfctl(9);
483 case RI(cr12): return mfctl(12);
484 case RI(cr13): return mfctl(13);
485 case RI(cr10): return mfctl(10);
486 case RI(cr15): return mfctl(15);
487 default: return 0;
488 }
489}
490
491static void set_reg(struct pt_regs *regs, int num, unsigned long val)
492{
493 switch (num) {
494 case RI(gr[0]): /*
495 * PSW is in gr[0].
496 * Allow writing to Nullify, Divide-step-correction,
497 * and carry/borrow bits.
498 * BEWARE, if you set N, and then single step, it won't
499 * stop on the nullified instruction.
500 */
501 val &= USER_PSW_BITS;
502 regs->gr[0] &= ~USER_PSW_BITS;
503 regs->gr[0] |= val;
504 return;
505 case RI(gr[1]) ... RI(gr[31]):
506 regs->gr[num - RI(gr[0])] = val;
507 return;
508 case RI(iaoq[0]):
509 case RI(iaoq[1]):
Helge Dellere7193d42019-07-04 03:44:17 +0200510 /* set 2 lowest bits to ensure userspace privilege: */
511 regs->iaoq[num - RI(iaoq[0])] = val | 3;
Helge Deller64e2a422016-04-01 22:40:53 +0200512 return;
513 case RI(sar): regs->sar = val;
514 return;
515 default: return;
516#if 0
517 /* do not allow to change any of the following registers (yet) */
518 case RI(sr[0]) ... RI(sr[7]): return regs->sr[num - RI(sr[0])];
519 case RI(iasq[0]): return regs->iasq[0];
520 case RI(iasq[1]): return regs->iasq[1];
521 case RI(iir): return regs->iir;
522 case RI(isr): return regs->isr;
523 case RI(ior): return regs->ior;
524 case RI(ipsw): return regs->ipsw;
525 case RI(cr27): return regs->cr27;
526 case cr0, cr24, cr25, cr26, cr27, cr28, cr29, cr30, cr31;
527 case cr8, cr9, cr12, cr13, cr10, cr15;
528#endif
529 }
530}
531
532static int gpr_get(struct task_struct *target,
533 const struct user_regset *regset,
534 unsigned int pos, unsigned int count,
535 void *kbuf, void __user *ubuf)
536{
537 struct pt_regs *regs = task_regs(target);
538 unsigned long *k = kbuf;
539 unsigned long __user *u = ubuf;
540 unsigned long reg;
541
542 pos /= sizeof(reg);
543 count /= sizeof(reg);
544
545 if (kbuf)
546 for (; count > 0 && pos < ELF_NGREG; --count)
547 *k++ = get_reg(regs, pos++);
548 else
549 for (; count > 0 && pos < ELF_NGREG; --count)
550 if (__put_user(get_reg(regs, pos++), u++))
551 return -EFAULT;
552 kbuf = k;
553 ubuf = u;
554 pos *= sizeof(reg);
555 count *= sizeof(reg);
556 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
557 ELF_NGREG * sizeof(reg), -1);
558}
559
560static int gpr_set(struct task_struct *target,
561 const struct user_regset *regset,
562 unsigned int pos, unsigned int count,
563 const void *kbuf, const void __user *ubuf)
564{
565 struct pt_regs *regs = task_regs(target);
566 const unsigned long *k = kbuf;
567 const unsigned long __user *u = ubuf;
568 unsigned long reg;
569
570 pos /= sizeof(reg);
571 count /= sizeof(reg);
572
573 if (kbuf)
574 for (; count > 0 && pos < ELF_NGREG; --count)
575 set_reg(regs, pos++, *k++);
576 else
577 for (; count > 0 && pos < ELF_NGREG; --count) {
578 if (__get_user(reg, u++))
579 return -EFAULT;
580 set_reg(regs, pos++, reg);
581 }
582
583 kbuf = k;
584 ubuf = u;
585 pos *= sizeof(reg);
586 count *= sizeof(reg);
587 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
588 ELF_NGREG * sizeof(reg), -1);
589}
590
591static const struct user_regset native_regsets[] = {
592 [REGSET_GENERAL] = {
593 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
594 .size = sizeof(long), .align = sizeof(long),
595 .get = gpr_get, .set = gpr_set
596 },
597 [REGSET_FP] = {
598 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
599 .size = sizeof(__u64), .align = sizeof(__u64),
600 .get = fpr_get, .set = fpr_set
601 }
602};
603
604static const struct user_regset_view user_parisc_native_view = {
605 .name = "parisc", .e_machine = ELF_ARCH, .ei_osabi = ELFOSABI_LINUX,
606 .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
607};
608
609#ifdef CONFIG_64BIT
610#include <linux/compat.h>
611
612static int gpr32_get(struct task_struct *target,
613 const struct user_regset *regset,
614 unsigned int pos, unsigned int count,
615 void *kbuf, void __user *ubuf)
616{
617 struct pt_regs *regs = task_regs(target);
618 compat_ulong_t *k = kbuf;
619 compat_ulong_t __user *u = ubuf;
620 compat_ulong_t reg;
621
622 pos /= sizeof(reg);
623 count /= sizeof(reg);
624
625 if (kbuf)
626 for (; count > 0 && pos < ELF_NGREG; --count)
627 *k++ = get_reg(regs, pos++);
628 else
629 for (; count > 0 && pos < ELF_NGREG; --count)
630 if (__put_user((compat_ulong_t) get_reg(regs, pos++), u++))
631 return -EFAULT;
632
633 kbuf = k;
634 ubuf = u;
635 pos *= sizeof(reg);
636 count *= sizeof(reg);
637 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
638 ELF_NGREG * sizeof(reg), -1);
639}
640
641static int gpr32_set(struct task_struct *target,
642 const struct user_regset *regset,
643 unsigned int pos, unsigned int count,
644 const void *kbuf, const void __user *ubuf)
645{
646 struct pt_regs *regs = task_regs(target);
647 const compat_ulong_t *k = kbuf;
648 const compat_ulong_t __user *u = ubuf;
649 compat_ulong_t reg;
650
651 pos /= sizeof(reg);
652 count /= sizeof(reg);
653
654 if (kbuf)
655 for (; count > 0 && pos < ELF_NGREG; --count)
656 set_reg(regs, pos++, *k++);
657 else
658 for (; count > 0 && pos < ELF_NGREG; --count) {
659 if (__get_user(reg, u++))
660 return -EFAULT;
661 set_reg(regs, pos++, reg);
662 }
663
664 kbuf = k;
665 ubuf = u;
666 pos *= sizeof(reg);
667 count *= sizeof(reg);
668 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
669 ELF_NGREG * sizeof(reg), -1);
670}
671
672/*
673 * These are the regset flavors matching the 32bit native set.
674 */
675static const struct user_regset compat_regsets[] = {
676 [REGSET_GENERAL] = {
677 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
678 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
679 .get = gpr32_get, .set = gpr32_set
680 },
681 [REGSET_FP] = {
682 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
683 .size = sizeof(__u64), .align = sizeof(__u64),
684 .get = fpr_get, .set = fpr_set
685 }
686};
687
688static const struct user_regset_view user_parisc_compat_view = {
689 .name = "parisc", .e_machine = EM_PARISC, .ei_osabi = ELFOSABI_LINUX,
690 .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
691};
692#endif /* CONFIG_64BIT */
693
694const struct user_regset_view *task_user_regset_view(struct task_struct *task)
695{
696 BUILD_BUG_ON(sizeof(struct user_regs_struct)/sizeof(long) != ELF_NGREG);
697 BUILD_BUG_ON(sizeof(struct user_fp_struct)/sizeof(__u64) != ELF_NFPREG);
698#ifdef CONFIG_64BIT
699 if (is_compat_task())
700 return &user_parisc_compat_view;
701#endif
702 return &user_parisc_native_view;
703}