ptrace.c 25 KB

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