ptrace.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /*
  2. * linux/kernel/ptrace.c
  3. *
  4. * (C) Copyright 1999 Linus Torvalds
  5. *
  6. * Common interfaces for "ptrace()" which we do not want
  7. * to continually duplicate across every architecture.
  8. */
  9. #include <linux/capability.h>
  10. #include <linux/module.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/mm.h>
  14. #include <linux/highmem.h>
  15. #include <linux/pagemap.h>
  16. #include <linux/smp_lock.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/security.h>
  19. #include <linux/signal.h>
  20. #include <linux/audit.h>
  21. #include <linux/pid_namespace.h>
  22. #include <linux/syscalls.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/uaccess.h>
  25. /*
  26. * ptrace a task: make the debugger its new parent and
  27. * move it to the ptrace list.
  28. *
  29. * Must be called with the tasklist lock write-held.
  30. */
  31. void __ptrace_link(struct task_struct *child, struct task_struct *new_parent)
  32. {
  33. BUG_ON(!list_empty(&child->ptrace_entry));
  34. list_add(&child->ptrace_entry, &new_parent->ptraced);
  35. child->parent = new_parent;
  36. }
  37. /*
  38. * Turn a tracing stop into a normal stop now, since with no tracer there
  39. * would be no way to wake it up with SIGCONT or SIGKILL. If there was a
  40. * signal sent that would resume the child, but didn't because it was in
  41. * TASK_TRACED, resume it now.
  42. * Requires that irqs be disabled.
  43. */
  44. static void ptrace_untrace(struct task_struct *child)
  45. {
  46. spin_lock(&child->sighand->siglock);
  47. if (task_is_traced(child)) {
  48. if (child->signal->flags & SIGNAL_STOP_STOPPED) {
  49. __set_task_state(child, TASK_STOPPED);
  50. } else {
  51. signal_wake_up(child, 1);
  52. }
  53. }
  54. spin_unlock(&child->sighand->siglock);
  55. }
  56. /*
  57. * unptrace a task: move it back to its original parent and
  58. * remove it from the ptrace list.
  59. *
  60. * Must be called with the tasklist lock write-held.
  61. */
  62. void __ptrace_unlink(struct task_struct *child)
  63. {
  64. BUG_ON(!child->ptrace);
  65. child->ptrace = 0;
  66. child->parent = child->real_parent;
  67. list_del_init(&child->ptrace_entry);
  68. if (task_is_traced(child))
  69. ptrace_untrace(child);
  70. }
  71. /*
  72. * Check that we have indeed attached to the thing..
  73. */
  74. int ptrace_check_attach(struct task_struct *child, int kill)
  75. {
  76. int ret = -ESRCH;
  77. /*
  78. * We take the read lock around doing both checks to close a
  79. * possible race where someone else was tracing our child and
  80. * detached between these two checks. After this locked check,
  81. * we are sure that this is our traced child and that can only
  82. * be changed by us so it's not changing right after this.
  83. */
  84. read_lock(&tasklist_lock);
  85. if ((child->ptrace & PT_PTRACED) && child->parent == current) {
  86. ret = 0;
  87. /*
  88. * child->sighand can't be NULL, release_task()
  89. * does ptrace_unlink() before __exit_signal().
  90. */
  91. spin_lock_irq(&child->sighand->siglock);
  92. if (task_is_stopped(child))
  93. child->state = TASK_TRACED;
  94. else if (!task_is_traced(child) && !kill)
  95. ret = -ESRCH;
  96. spin_unlock_irq(&child->sighand->siglock);
  97. }
  98. read_unlock(&tasklist_lock);
  99. if (!ret && !kill)
  100. ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH;
  101. /* All systems go.. */
  102. return ret;
  103. }
  104. int __ptrace_may_access(struct task_struct *task, unsigned int mode)
  105. {
  106. const struct cred *cred = current_cred(), *tcred;
  107. /* May we inspect the given task?
  108. * This check is used both for attaching with ptrace
  109. * and for allowing access to sensitive information in /proc.
  110. *
  111. * ptrace_attach denies several cases that /proc allows
  112. * because setting up the necessary parent/child relationship
  113. * or halting the specified task is impossible.
  114. */
  115. int dumpable = 0;
  116. /* Don't let security modules deny introspection */
  117. if (task == current)
  118. return 0;
  119. rcu_read_lock();
  120. tcred = __task_cred(task);
  121. if ((cred->uid != tcred->euid ||
  122. cred->uid != tcred->suid ||
  123. cred->uid != tcred->uid ||
  124. cred->gid != tcred->egid ||
  125. cred->gid != tcred->sgid ||
  126. cred->gid != tcred->gid) &&
  127. !capable(CAP_SYS_PTRACE)) {
  128. rcu_read_unlock();
  129. return -EPERM;
  130. }
  131. rcu_read_unlock();
  132. smp_rmb();
  133. if (task->mm)
  134. dumpable = get_dumpable(task->mm);
  135. if (!dumpable && !capable(CAP_SYS_PTRACE))
  136. return -EPERM;
  137. return security_ptrace_may_access(task, mode);
  138. }
  139. bool ptrace_may_access(struct task_struct *task, unsigned int mode)
  140. {
  141. int err;
  142. task_lock(task);
  143. err = __ptrace_may_access(task, mode);
  144. task_unlock(task);
  145. return (!err ? true : false);
  146. }
  147. int ptrace_attach(struct task_struct *task)
  148. {
  149. int retval;
  150. unsigned long flags;
  151. audit_ptrace(task);
  152. retval = -EPERM;
  153. if (same_thread_group(task, current))
  154. goto out;
  155. /* Protect exec's credential calculations against our interference;
  156. * SUID, SGID and LSM creds get determined differently under ptrace.
  157. */
  158. retval = mutex_lock_interruptible(&current->cred_exec_mutex);
  159. if (retval < 0)
  160. goto out;
  161. retval = -EPERM;
  162. repeat:
  163. /*
  164. * Nasty, nasty.
  165. *
  166. * We want to hold both the task-lock and the
  167. * tasklist_lock for writing at the same time.
  168. * But that's against the rules (tasklist_lock
  169. * is taken for reading by interrupts on other
  170. * cpu's that may have task_lock).
  171. */
  172. task_lock(task);
  173. if (!write_trylock_irqsave(&tasklist_lock, flags)) {
  174. task_unlock(task);
  175. do {
  176. cpu_relax();
  177. } while (!write_can_lock(&tasklist_lock));
  178. goto repeat;
  179. }
  180. if (!task->mm)
  181. goto bad;
  182. /* the same process cannot be attached many times */
  183. if (task->ptrace & PT_PTRACED)
  184. goto bad;
  185. retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
  186. if (retval)
  187. goto bad;
  188. /* Go */
  189. task->ptrace |= PT_PTRACED;
  190. if (capable(CAP_SYS_PTRACE))
  191. task->ptrace |= PT_PTRACE_CAP;
  192. __ptrace_link(task, current);
  193. send_sig_info(SIGSTOP, SEND_SIG_FORCED, task);
  194. bad:
  195. write_unlock_irqrestore(&tasklist_lock, flags);
  196. task_unlock(task);
  197. mutex_unlock(&current->cred_exec_mutex);
  198. out:
  199. return retval;
  200. }
  201. static inline void __ptrace_detach(struct task_struct *child, unsigned int data)
  202. {
  203. child->exit_code = data;
  204. /* .. re-parent .. */
  205. __ptrace_unlink(child);
  206. /* .. and wake it up. */
  207. if (child->exit_state != EXIT_ZOMBIE)
  208. wake_up_process(child);
  209. }
  210. int ptrace_detach(struct task_struct *child, unsigned int data)
  211. {
  212. if (!valid_signal(data))
  213. return -EIO;
  214. /* Architecture-specific hardware disable .. */
  215. ptrace_disable(child);
  216. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  217. write_lock_irq(&tasklist_lock);
  218. /* protect against de_thread()->release_task() */
  219. if (child->ptrace)
  220. __ptrace_detach(child, data);
  221. write_unlock_irq(&tasklist_lock);
  222. return 0;
  223. }
  224. int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
  225. {
  226. int copied = 0;
  227. while (len > 0) {
  228. char buf[128];
  229. int this_len, retval;
  230. this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
  231. retval = access_process_vm(tsk, src, buf, this_len, 0);
  232. if (!retval) {
  233. if (copied)
  234. break;
  235. return -EIO;
  236. }
  237. if (copy_to_user(dst, buf, retval))
  238. return -EFAULT;
  239. copied += retval;
  240. src += retval;
  241. dst += retval;
  242. len -= retval;
  243. }
  244. return copied;
  245. }
  246. int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
  247. {
  248. int copied = 0;
  249. while (len > 0) {
  250. char buf[128];
  251. int this_len, retval;
  252. this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
  253. if (copy_from_user(buf, src, this_len))
  254. return -EFAULT;
  255. retval = access_process_vm(tsk, dst, buf, this_len, 1);
  256. if (!retval) {
  257. if (copied)
  258. break;
  259. return -EIO;
  260. }
  261. copied += retval;
  262. src += retval;
  263. dst += retval;
  264. len -= retval;
  265. }
  266. return copied;
  267. }
  268. static int ptrace_setoptions(struct task_struct *child, long data)
  269. {
  270. child->ptrace &= ~PT_TRACE_MASK;
  271. if (data & PTRACE_O_TRACESYSGOOD)
  272. child->ptrace |= PT_TRACESYSGOOD;
  273. if (data & PTRACE_O_TRACEFORK)
  274. child->ptrace |= PT_TRACE_FORK;
  275. if (data & PTRACE_O_TRACEVFORK)
  276. child->ptrace |= PT_TRACE_VFORK;
  277. if (data & PTRACE_O_TRACECLONE)
  278. child->ptrace |= PT_TRACE_CLONE;
  279. if (data & PTRACE_O_TRACEEXEC)
  280. child->ptrace |= PT_TRACE_EXEC;
  281. if (data & PTRACE_O_TRACEVFORKDONE)
  282. child->ptrace |= PT_TRACE_VFORK_DONE;
  283. if (data & PTRACE_O_TRACEEXIT)
  284. child->ptrace |= PT_TRACE_EXIT;
  285. return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
  286. }
  287. static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)
  288. {
  289. int error = -ESRCH;
  290. read_lock(&tasklist_lock);
  291. if (likely(child->sighand != NULL)) {
  292. error = -EINVAL;
  293. spin_lock_irq(&child->sighand->siglock);
  294. if (likely(child->last_siginfo != NULL)) {
  295. *info = *child->last_siginfo;
  296. error = 0;
  297. }
  298. spin_unlock_irq(&child->sighand->siglock);
  299. }
  300. read_unlock(&tasklist_lock);
  301. return error;
  302. }
  303. static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
  304. {
  305. int error = -ESRCH;
  306. read_lock(&tasklist_lock);
  307. if (likely(child->sighand != NULL)) {
  308. error = -EINVAL;
  309. spin_lock_irq(&child->sighand->siglock);
  310. if (likely(child->last_siginfo != NULL)) {
  311. *child->last_siginfo = *info;
  312. error = 0;
  313. }
  314. spin_unlock_irq(&child->sighand->siglock);
  315. }
  316. read_unlock(&tasklist_lock);
  317. return error;
  318. }
  319. #ifdef PTRACE_SINGLESTEP
  320. #define is_singlestep(request) ((request) == PTRACE_SINGLESTEP)
  321. #else
  322. #define is_singlestep(request) 0
  323. #endif
  324. #ifdef PTRACE_SINGLEBLOCK
  325. #define is_singleblock(request) ((request) == PTRACE_SINGLEBLOCK)
  326. #else
  327. #define is_singleblock(request) 0
  328. #endif
  329. #ifdef PTRACE_SYSEMU
  330. #define is_sysemu_singlestep(request) ((request) == PTRACE_SYSEMU_SINGLESTEP)
  331. #else
  332. #define is_sysemu_singlestep(request) 0
  333. #endif
  334. static int ptrace_resume(struct task_struct *child, long request, long data)
  335. {
  336. if (!valid_signal(data))
  337. return -EIO;
  338. if (request == PTRACE_SYSCALL)
  339. set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  340. else
  341. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  342. #ifdef TIF_SYSCALL_EMU
  343. if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP)
  344. set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  345. else
  346. clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  347. #endif
  348. if (is_singleblock(request)) {
  349. if (unlikely(!arch_has_block_step()))
  350. return -EIO;
  351. user_enable_block_step(child);
  352. } else if (is_singlestep(request) || is_sysemu_singlestep(request)) {
  353. if (unlikely(!arch_has_single_step()))
  354. return -EIO;
  355. user_enable_single_step(child);
  356. }
  357. else
  358. user_disable_single_step(child);
  359. child->exit_code = data;
  360. wake_up_process(child);
  361. return 0;
  362. }
  363. int ptrace_request(struct task_struct *child, long request,
  364. long addr, long data)
  365. {
  366. int ret = -EIO;
  367. siginfo_t siginfo;
  368. switch (request) {
  369. case PTRACE_PEEKTEXT:
  370. case PTRACE_PEEKDATA:
  371. return generic_ptrace_peekdata(child, addr, data);
  372. case PTRACE_POKETEXT:
  373. case PTRACE_POKEDATA:
  374. return generic_ptrace_pokedata(child, addr, data);
  375. #ifdef PTRACE_OLDSETOPTIONS
  376. case PTRACE_OLDSETOPTIONS:
  377. #endif
  378. case PTRACE_SETOPTIONS:
  379. ret = ptrace_setoptions(child, data);
  380. break;
  381. case PTRACE_GETEVENTMSG:
  382. ret = put_user(child->ptrace_message, (unsigned long __user *) data);
  383. break;
  384. case PTRACE_GETSIGINFO:
  385. ret = ptrace_getsiginfo(child, &siginfo);
  386. if (!ret)
  387. ret = copy_siginfo_to_user((siginfo_t __user *) data,
  388. &siginfo);
  389. break;
  390. case PTRACE_SETSIGINFO:
  391. if (copy_from_user(&siginfo, (siginfo_t __user *) data,
  392. sizeof siginfo))
  393. ret = -EFAULT;
  394. else
  395. ret = ptrace_setsiginfo(child, &siginfo);
  396. break;
  397. case PTRACE_DETACH: /* detach a process that was attached. */
  398. ret = ptrace_detach(child, data);
  399. break;
  400. #ifdef PTRACE_SINGLESTEP
  401. case PTRACE_SINGLESTEP:
  402. #endif
  403. #ifdef PTRACE_SINGLEBLOCK
  404. case PTRACE_SINGLEBLOCK:
  405. #endif
  406. #ifdef PTRACE_SYSEMU
  407. case PTRACE_SYSEMU:
  408. case PTRACE_SYSEMU_SINGLESTEP:
  409. #endif
  410. case PTRACE_SYSCALL:
  411. case PTRACE_CONT:
  412. return ptrace_resume(child, request, data);
  413. case PTRACE_KILL:
  414. if (child->exit_state) /* already dead */
  415. return 0;
  416. return ptrace_resume(child, request, SIGKILL);
  417. default:
  418. break;
  419. }
  420. return ret;
  421. }
  422. /**
  423. * ptrace_traceme -- helper for PTRACE_TRACEME
  424. *
  425. * Performs checks and sets PT_PTRACED.
  426. * Should be used by all ptrace implementations for PTRACE_TRACEME.
  427. */
  428. int ptrace_traceme(void)
  429. {
  430. int ret = -EPERM;
  431. /*
  432. * Are we already being traced?
  433. */
  434. repeat:
  435. task_lock(current);
  436. if (!(current->ptrace & PT_PTRACED)) {
  437. /*
  438. * See ptrace_attach() comments about the locking here.
  439. */
  440. unsigned long flags;
  441. if (!write_trylock_irqsave(&tasklist_lock, flags)) {
  442. task_unlock(current);
  443. do {
  444. cpu_relax();
  445. } while (!write_can_lock(&tasklist_lock));
  446. goto repeat;
  447. }
  448. ret = security_ptrace_traceme(current->parent);
  449. /*
  450. * Set the ptrace bit in the process ptrace flags.
  451. * Then link us on our parent's ptraced list.
  452. */
  453. if (!ret) {
  454. current->ptrace |= PT_PTRACED;
  455. __ptrace_link(current, current->real_parent);
  456. }
  457. write_unlock_irqrestore(&tasklist_lock, flags);
  458. }
  459. task_unlock(current);
  460. return ret;
  461. }
  462. /**
  463. * ptrace_get_task_struct -- grab a task struct reference for ptrace
  464. * @pid: process id to grab a task_struct reference of
  465. *
  466. * This function is a helper for ptrace implementations. It checks
  467. * permissions and then grabs a task struct for use of the actual
  468. * ptrace implementation.
  469. *
  470. * Returns the task_struct for @pid or an ERR_PTR() on failure.
  471. */
  472. struct task_struct *ptrace_get_task_struct(pid_t pid)
  473. {
  474. struct task_struct *child;
  475. read_lock(&tasklist_lock);
  476. child = find_task_by_vpid(pid);
  477. if (child)
  478. get_task_struct(child);
  479. read_unlock(&tasklist_lock);
  480. if (!child)
  481. return ERR_PTR(-ESRCH);
  482. return child;
  483. }
  484. #ifndef arch_ptrace_attach
  485. #define arch_ptrace_attach(child) do { } while (0)
  486. #endif
  487. asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
  488. {
  489. struct task_struct *child;
  490. long ret;
  491. /*
  492. * This lock_kernel fixes a subtle race with suid exec
  493. */
  494. lock_kernel();
  495. if (request == PTRACE_TRACEME) {
  496. ret = ptrace_traceme();
  497. if (!ret)
  498. arch_ptrace_attach(current);
  499. goto out;
  500. }
  501. child = ptrace_get_task_struct(pid);
  502. if (IS_ERR(child)) {
  503. ret = PTR_ERR(child);
  504. goto out;
  505. }
  506. if (request == PTRACE_ATTACH) {
  507. ret = ptrace_attach(child);
  508. /*
  509. * Some architectures need to do book-keeping after
  510. * a ptrace attach.
  511. */
  512. if (!ret)
  513. arch_ptrace_attach(child);
  514. goto out_put_task_struct;
  515. }
  516. ret = ptrace_check_attach(child, request == PTRACE_KILL);
  517. if (ret < 0)
  518. goto out_put_task_struct;
  519. ret = arch_ptrace(child, request, addr, data);
  520. if (ret < 0)
  521. goto out_put_task_struct;
  522. out_put_task_struct:
  523. put_task_struct(child);
  524. out:
  525. unlock_kernel();
  526. return ret;
  527. }
  528. int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
  529. {
  530. unsigned long tmp;
  531. int copied;
  532. copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
  533. if (copied != sizeof(tmp))
  534. return -EIO;
  535. return put_user(tmp, (unsigned long __user *)data);
  536. }
  537. int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
  538. {
  539. int copied;
  540. copied = access_process_vm(tsk, addr, &data, sizeof(data), 1);
  541. return (copied == sizeof(data)) ? 0 : -EIO;
  542. }
  543. #if defined CONFIG_COMPAT && defined __ARCH_WANT_COMPAT_SYS_PTRACE
  544. #include <linux/compat.h>
  545. int compat_ptrace_request(struct task_struct *child, compat_long_t request,
  546. compat_ulong_t addr, compat_ulong_t data)
  547. {
  548. compat_ulong_t __user *datap = compat_ptr(data);
  549. compat_ulong_t word;
  550. siginfo_t siginfo;
  551. int ret;
  552. switch (request) {
  553. case PTRACE_PEEKTEXT:
  554. case PTRACE_PEEKDATA:
  555. ret = access_process_vm(child, addr, &word, sizeof(word), 0);
  556. if (ret != sizeof(word))
  557. ret = -EIO;
  558. else
  559. ret = put_user(word, datap);
  560. break;
  561. case PTRACE_POKETEXT:
  562. case PTRACE_POKEDATA:
  563. ret = access_process_vm(child, addr, &data, sizeof(data), 1);
  564. ret = (ret != sizeof(data) ? -EIO : 0);
  565. break;
  566. case PTRACE_GETEVENTMSG:
  567. ret = put_user((compat_ulong_t) child->ptrace_message, datap);
  568. break;
  569. case PTRACE_GETSIGINFO:
  570. ret = ptrace_getsiginfo(child, &siginfo);
  571. if (!ret)
  572. ret = copy_siginfo_to_user32(
  573. (struct compat_siginfo __user *) datap,
  574. &siginfo);
  575. break;
  576. case PTRACE_SETSIGINFO:
  577. memset(&siginfo, 0, sizeof siginfo);
  578. if (copy_siginfo_from_user32(
  579. &siginfo, (struct compat_siginfo __user *) datap))
  580. ret = -EFAULT;
  581. else
  582. ret = ptrace_setsiginfo(child, &siginfo);
  583. break;
  584. default:
  585. ret = ptrace_request(child, request, addr, data);
  586. }
  587. return ret;
  588. }
  589. asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  590. compat_long_t addr, compat_long_t data)
  591. {
  592. struct task_struct *child;
  593. long ret;
  594. /*
  595. * This lock_kernel fixes a subtle race with suid exec
  596. */
  597. lock_kernel();
  598. if (request == PTRACE_TRACEME) {
  599. ret = ptrace_traceme();
  600. goto out;
  601. }
  602. child = ptrace_get_task_struct(pid);
  603. if (IS_ERR(child)) {
  604. ret = PTR_ERR(child);
  605. goto out;
  606. }
  607. if (request == PTRACE_ATTACH) {
  608. ret = ptrace_attach(child);
  609. /*
  610. * Some architectures need to do book-keeping after
  611. * a ptrace attach.
  612. */
  613. if (!ret)
  614. arch_ptrace_attach(child);
  615. goto out_put_task_struct;
  616. }
  617. ret = ptrace_check_attach(child, request == PTRACE_KILL);
  618. if (!ret)
  619. ret = compat_arch_ptrace(child, request, addr, data);
  620. out_put_task_struct:
  621. put_task_struct(child);
  622. out:
  623. unlock_kernel();
  624. return ret;
  625. }
  626. #endif /* CONFIG_COMPAT && __ARCH_WANT_COMPAT_SYS_PTRACE */