ptrace.c 25 KB

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