ptrace.c 26 KB

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