]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - kernel/ptrace.c
ptrace_detach: the wrong wakeup breaks the ERESTARTxxx logic
[linux-2.6-omap-h63xx.git] / kernel / ptrace.c
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
10 #include <linux/capability.h>
11 #include <linux/module.h>
12 #include <linux/sched.h>
13 #include <linux/errno.h>
14 #include <linux/mm.h>
15 #include <linux/highmem.h>
16 #include <linux/pagemap.h>
17 #include <linux/smp_lock.h>
18 #include <linux/ptrace.h>
19 #include <linux/security.h>
20 #include <linux/signal.h>
21 #include <linux/audit.h>
22 #include <linux/pid_namespace.h>
23 #include <linux/syscalls.h>
24
25 #include <asm/pgtable.h>
26 #include <asm/uaccess.h>
27
28
29 /*
30  * Initialize a new task whose father had been ptraced.
31  *
32  * Called from copy_process().
33  */
34 void ptrace_fork(struct task_struct *child, unsigned long clone_flags)
35 {
36         arch_ptrace_fork(child, clone_flags);
37 }
38
39 /*
40  * ptrace a task: make the debugger its new parent and
41  * move it to the ptrace list.
42  *
43  * Must be called with the tasklist lock write-held.
44  */
45 void __ptrace_link(struct task_struct *child, struct task_struct *new_parent)
46 {
47         BUG_ON(!list_empty(&child->ptrace_entry));
48         list_add(&child->ptrace_entry, &new_parent->ptraced);
49         child->parent = new_parent;
50 }
51  
52 /*
53  * Turn a tracing stop into a normal stop now, since with no tracer there
54  * would be no way to wake it up with SIGCONT or SIGKILL.  If there was a
55  * signal sent that would resume the child, but didn't because it was in
56  * TASK_TRACED, resume it now.
57  * Requires that irqs be disabled.
58  */
59 static void ptrace_untrace(struct task_struct *child)
60 {
61         spin_lock(&child->sighand->siglock);
62         if (task_is_traced(child)) {
63                 if (child->signal->flags & SIGNAL_STOP_STOPPED) {
64                         __set_task_state(child, TASK_STOPPED);
65                 } else {
66                         signal_wake_up(child, 1);
67                 }
68         }
69         spin_unlock(&child->sighand->siglock);
70 }
71
72 /*
73  * unptrace a task: move it back to its original parent and
74  * remove it from the ptrace list.
75  *
76  * Must be called with the tasklist lock write-held.
77  */
78 void __ptrace_unlink(struct task_struct *child)
79 {
80         BUG_ON(!child->ptrace);
81
82         child->ptrace = 0;
83         child->parent = child->real_parent;
84         list_del_init(&child->ptrace_entry);
85
86         arch_ptrace_untrace(child);
87         if (task_is_traced(child))
88                 ptrace_untrace(child);
89 }
90
91 /*
92  * Check that we have indeed attached to the thing..
93  */
94 int ptrace_check_attach(struct task_struct *child, int kill)
95 {
96         int ret = -ESRCH;
97
98         /*
99          * We take the read lock around doing both checks to close a
100          * possible race where someone else was tracing our child and
101          * detached between these two checks.  After this locked check,
102          * we are sure that this is our traced child and that can only
103          * be changed by us so it's not changing right after this.
104          */
105         read_lock(&tasklist_lock);
106         if ((child->ptrace & PT_PTRACED) && child->parent == current) {
107                 ret = 0;
108                 /*
109                  * child->sighand can't be NULL, release_task()
110                  * does ptrace_unlink() before __exit_signal().
111                  */
112                 spin_lock_irq(&child->sighand->siglock);
113                 if (task_is_stopped(child))
114                         child->state = TASK_TRACED;
115                 else if (!task_is_traced(child) && !kill)
116                         ret = -ESRCH;
117                 spin_unlock_irq(&child->sighand->siglock);
118         }
119         read_unlock(&tasklist_lock);
120
121         if (!ret && !kill)
122                 ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH;
123
124         /* All systems go.. */
125         return ret;
126 }
127
128 int __ptrace_may_access(struct task_struct *task, unsigned int mode)
129 {
130         const struct cred *cred = current_cred(), *tcred;
131
132         /* May we inspect the given task?
133          * This check is used both for attaching with ptrace
134          * and for allowing access to sensitive information in /proc.
135          *
136          * ptrace_attach denies several cases that /proc allows
137          * because setting up the necessary parent/child relationship
138          * or halting the specified task is impossible.
139          */
140         int dumpable = 0;
141         /* Don't let security modules deny introspection */
142         if (task == current)
143                 return 0;
144         rcu_read_lock();
145         tcred = __task_cred(task);
146         if ((cred->uid != tcred->euid ||
147              cred->uid != tcred->suid ||
148              cred->uid != tcred->uid  ||
149              cred->gid != tcred->egid ||
150              cred->gid != tcred->sgid ||
151              cred->gid != tcred->gid) &&
152             !capable(CAP_SYS_PTRACE)) {
153                 rcu_read_unlock();
154                 return -EPERM;
155         }
156         rcu_read_unlock();
157         smp_rmb();
158         if (task->mm)
159                 dumpable = get_dumpable(task->mm);
160         if (!dumpable && !capable(CAP_SYS_PTRACE))
161                 return -EPERM;
162
163         return security_ptrace_may_access(task, mode);
164 }
165
166 bool ptrace_may_access(struct task_struct *task, unsigned int mode)
167 {
168         int err;
169         task_lock(task);
170         err = __ptrace_may_access(task, mode);
171         task_unlock(task);
172         return (!err ? true : false);
173 }
174
175 int ptrace_attach(struct task_struct *task)
176 {
177         int retval;
178         unsigned long flags;
179
180         audit_ptrace(task);
181
182         retval = -EPERM;
183         if (same_thread_group(task, current))
184                 goto out;
185
186         /* Protect exec's credential calculations against our interference;
187          * SUID, SGID and LSM creds get determined differently under ptrace.
188          */
189         retval = mutex_lock_interruptible(&current->cred_exec_mutex);
190         if (retval  < 0)
191                 goto out;
192
193         retval = -EPERM;
194 repeat:
195         /*
196          * Nasty, nasty.
197          *
198          * We want to hold both the task-lock and the
199          * tasklist_lock for writing at the same time.
200          * But that's against the rules (tasklist_lock
201          * is taken for reading by interrupts on other
202          * cpu's that may have task_lock).
203          */
204         task_lock(task);
205         if (!write_trylock_irqsave(&tasklist_lock, flags)) {
206                 task_unlock(task);
207                 do {
208                         cpu_relax();
209                 } while (!write_can_lock(&tasklist_lock));
210                 goto repeat;
211         }
212
213         if (!task->mm)
214                 goto bad;
215         /* the same process cannot be attached many times */
216         if (task->ptrace & PT_PTRACED)
217                 goto bad;
218         retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
219         if (retval)
220                 goto bad;
221
222         /* Go */
223         task->ptrace |= PT_PTRACED;
224         if (capable(CAP_SYS_PTRACE))
225                 task->ptrace |= PT_PTRACE_CAP;
226
227         __ptrace_link(task, current);
228
229         send_sig_info(SIGSTOP, SEND_SIG_FORCED, task);
230 bad:
231         write_unlock_irqrestore(&tasklist_lock, flags);
232         task_unlock(task);
233         mutex_unlock(&current->cred_exec_mutex);
234 out:
235         return retval;
236 }
237
238 /*
239  * Called with irqs disabled, returns true if childs should reap themselves.
240  */
241 static int ignoring_children(struct sighand_struct *sigh)
242 {
243         int ret;
244         spin_lock(&sigh->siglock);
245         ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) ||
246               (sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT);
247         spin_unlock(&sigh->siglock);
248         return ret;
249 }
250
251 /*
252  * Called with tasklist_lock held for writing.
253  * Unlink a traced task, and clean it up if it was a traced zombie.
254  * Return true if it needs to be reaped with release_task().
255  * (We can't call release_task() here because we already hold tasklist_lock.)
256  *
257  * If it's a zombie, our attachedness prevented normal parent notification
258  * or self-reaping.  Do notification now if it would have happened earlier.
259  * If it should reap itself, return true.
260  *
261  * If it's our own child, there is no notification to do.
262  * But if our normal children self-reap, then this child
263  * was prevented by ptrace and we must reap it now.
264  */
265 static bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
266 {
267         __ptrace_unlink(p);
268
269         if (p->exit_state == EXIT_ZOMBIE) {
270                 if (!task_detached(p) && thread_group_empty(p)) {
271                         if (!same_thread_group(p->real_parent, tracer))
272                                 do_notify_parent(p, p->exit_signal);
273                         else if (ignoring_children(tracer->sighand))
274                                 p->exit_signal = -1;
275                 }
276                 if (task_detached(p)) {
277                         /* Mark it as in the process of being reaped. */
278                         p->exit_state = EXIT_DEAD;
279                         return true;
280                 }
281         }
282
283         return false;
284 }
285
286 int ptrace_detach(struct task_struct *child, unsigned int data)
287 {
288         bool dead = false;
289
290         if (!valid_signal(data))
291                 return -EIO;
292
293         /* Architecture-specific hardware disable .. */
294         ptrace_disable(child);
295         clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
296
297         write_lock_irq(&tasklist_lock);
298         /*
299          * This child can be already killed. Make sure de_thread() or
300          * our sub-thread doing do_wait() didn't do release_task() yet.
301          */
302         if (child->ptrace) {
303                 child->exit_code = data;
304                 dead = __ptrace_detach(current, child);
305         }
306         write_unlock_irq(&tasklist_lock);
307
308         if (unlikely(dead))
309                 release_task(child);
310
311         return 0;
312 }
313
314 /*
315  * Detach all tasks we were using ptrace on.
316  */
317 void exit_ptrace(struct task_struct *tracer)
318 {
319         struct task_struct *p, *n;
320         LIST_HEAD(ptrace_dead);
321
322         write_lock_irq(&tasklist_lock);
323         list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) {
324                 if (__ptrace_detach(tracer, p))
325                         list_add(&p->ptrace_entry, &ptrace_dead);
326         }
327         write_unlock_irq(&tasklist_lock);
328
329         BUG_ON(!list_empty(&tracer->ptraced));
330
331         list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) {
332                 list_del_init(&p->ptrace_entry);
333                 release_task(p);
334         }
335 }
336
337 int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
338 {
339         int copied = 0;
340
341         while (len > 0) {
342                 char buf[128];
343                 int this_len, retval;
344
345                 this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
346                 retval = access_process_vm(tsk, src, buf, this_len, 0);
347                 if (!retval) {
348                         if (copied)
349                                 break;
350                         return -EIO;
351                 }
352                 if (copy_to_user(dst, buf, retval))
353                         return -EFAULT;
354                 copied += retval;
355                 src += retval;
356                 dst += retval;
357                 len -= retval;                  
358         }
359         return copied;
360 }
361
362 int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
363 {
364         int copied = 0;
365
366         while (len > 0) {
367                 char buf[128];
368                 int this_len, retval;
369
370                 this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
371                 if (copy_from_user(buf, src, this_len))
372                         return -EFAULT;
373                 retval = access_process_vm(tsk, dst, buf, this_len, 1);
374                 if (!retval) {
375                         if (copied)
376                                 break;
377                         return -EIO;
378                 }
379                 copied += retval;
380                 src += retval;
381                 dst += retval;
382                 len -= retval;                  
383         }
384         return copied;
385 }
386
387 static int ptrace_setoptions(struct task_struct *child, long data)
388 {
389         child->ptrace &= ~PT_TRACE_MASK;
390
391         if (data & PTRACE_O_TRACESYSGOOD)
392                 child->ptrace |= PT_TRACESYSGOOD;
393
394         if (data & PTRACE_O_TRACEFORK)
395                 child->ptrace |= PT_TRACE_FORK;
396
397         if (data & PTRACE_O_TRACEVFORK)
398                 child->ptrace |= PT_TRACE_VFORK;
399
400         if (data & PTRACE_O_TRACECLONE)
401                 child->ptrace |= PT_TRACE_CLONE;
402
403         if (data & PTRACE_O_TRACEEXEC)
404                 child->ptrace |= PT_TRACE_EXEC;
405
406         if (data & PTRACE_O_TRACEVFORKDONE)
407                 child->ptrace |= PT_TRACE_VFORK_DONE;
408
409         if (data & PTRACE_O_TRACEEXIT)
410                 child->ptrace |= PT_TRACE_EXIT;
411
412         return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
413 }
414
415 static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)
416 {
417         int error = -ESRCH;
418
419         read_lock(&tasklist_lock);
420         if (likely(child->sighand != NULL)) {
421                 error = -EINVAL;
422                 spin_lock_irq(&child->sighand->siglock);
423                 if (likely(child->last_siginfo != NULL)) {
424                         *info = *child->last_siginfo;
425                         error = 0;
426                 }
427                 spin_unlock_irq(&child->sighand->siglock);
428         }
429         read_unlock(&tasklist_lock);
430         return error;
431 }
432
433 static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
434 {
435         int error = -ESRCH;
436
437         read_lock(&tasklist_lock);
438         if (likely(child->sighand != NULL)) {
439                 error = -EINVAL;
440                 spin_lock_irq(&child->sighand->siglock);
441                 if (likely(child->last_siginfo != NULL)) {
442                         *child->last_siginfo = *info;
443                         error = 0;
444                 }
445                 spin_unlock_irq(&child->sighand->siglock);
446         }
447         read_unlock(&tasklist_lock);
448         return error;
449 }
450
451
452 #ifdef PTRACE_SINGLESTEP
453 #define is_singlestep(request)          ((request) == PTRACE_SINGLESTEP)
454 #else
455 #define is_singlestep(request)          0
456 #endif
457
458 #ifdef PTRACE_SINGLEBLOCK
459 #define is_singleblock(request)         ((request) == PTRACE_SINGLEBLOCK)
460 #else
461 #define is_singleblock(request)         0
462 #endif
463
464 #ifdef PTRACE_SYSEMU
465 #define is_sysemu_singlestep(request)   ((request) == PTRACE_SYSEMU_SINGLESTEP)
466 #else
467 #define is_sysemu_singlestep(request)   0
468 #endif
469
470 static int ptrace_resume(struct task_struct *child, long request, long data)
471 {
472         if (!valid_signal(data))
473                 return -EIO;
474
475         if (request == PTRACE_SYSCALL)
476                 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
477         else
478                 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
479
480 #ifdef TIF_SYSCALL_EMU
481         if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP)
482                 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
483         else
484                 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
485 #endif
486
487         if (is_singleblock(request)) {
488                 if (unlikely(!arch_has_block_step()))
489                         return -EIO;
490                 user_enable_block_step(child);
491         } else if (is_singlestep(request) || is_sysemu_singlestep(request)) {
492                 if (unlikely(!arch_has_single_step()))
493                         return -EIO;
494                 user_enable_single_step(child);
495         }
496         else
497                 user_disable_single_step(child);
498
499         child->exit_code = data;
500         wake_up_process(child);
501
502         return 0;
503 }
504
505 int ptrace_request(struct task_struct *child, long request,
506                    long addr, long data)
507 {
508         int ret = -EIO;
509         siginfo_t siginfo;
510
511         switch (request) {
512         case PTRACE_PEEKTEXT:
513         case PTRACE_PEEKDATA:
514                 return generic_ptrace_peekdata(child, addr, data);
515         case PTRACE_POKETEXT:
516         case PTRACE_POKEDATA:
517                 return generic_ptrace_pokedata(child, addr, data);
518
519 #ifdef PTRACE_OLDSETOPTIONS
520         case PTRACE_OLDSETOPTIONS:
521 #endif
522         case PTRACE_SETOPTIONS:
523                 ret = ptrace_setoptions(child, data);
524                 break;
525         case PTRACE_GETEVENTMSG:
526                 ret = put_user(child->ptrace_message, (unsigned long __user *) data);
527                 break;
528
529         case PTRACE_GETSIGINFO:
530                 ret = ptrace_getsiginfo(child, &siginfo);
531                 if (!ret)
532                         ret = copy_siginfo_to_user((siginfo_t __user *) data,
533                                                    &siginfo);
534                 break;
535
536         case PTRACE_SETSIGINFO:
537                 if (copy_from_user(&siginfo, (siginfo_t __user *) data,
538                                    sizeof siginfo))
539                         ret = -EFAULT;
540                 else
541                         ret = ptrace_setsiginfo(child, &siginfo);
542                 break;
543
544         case PTRACE_DETACH:      /* detach a process that was attached. */
545                 ret = ptrace_detach(child, data);
546                 break;
547
548 #ifdef PTRACE_SINGLESTEP
549         case PTRACE_SINGLESTEP:
550 #endif
551 #ifdef PTRACE_SINGLEBLOCK
552         case PTRACE_SINGLEBLOCK:
553 #endif
554 #ifdef PTRACE_SYSEMU
555         case PTRACE_SYSEMU:
556         case PTRACE_SYSEMU_SINGLESTEP:
557 #endif
558         case PTRACE_SYSCALL:
559         case PTRACE_CONT:
560                 return ptrace_resume(child, request, data);
561
562         case PTRACE_KILL:
563                 if (child->exit_state)  /* already dead */
564                         return 0;
565                 return ptrace_resume(child, request, SIGKILL);
566
567         default:
568                 break;
569         }
570
571         return ret;
572 }
573
574 /**
575  * ptrace_traceme  --  helper for PTRACE_TRACEME
576  *
577  * Performs checks and sets PT_PTRACED.
578  * Should be used by all ptrace implementations for PTRACE_TRACEME.
579  */
580 int ptrace_traceme(void)
581 {
582         int ret = -EPERM;
583
584         /*
585          * Are we already being traced?
586          */
587 repeat:
588         task_lock(current);
589         if (!(current->ptrace & PT_PTRACED)) {
590                 /*
591                  * See ptrace_attach() comments about the locking here.
592                  */
593                 unsigned long flags;
594                 if (!write_trylock_irqsave(&tasklist_lock, flags)) {
595                         task_unlock(current);
596                         do {
597                                 cpu_relax();
598                         } while (!write_can_lock(&tasklist_lock));
599                         goto repeat;
600                 }
601
602                 ret = security_ptrace_traceme(current->parent);
603
604                 /*
605                  * Set the ptrace bit in the process ptrace flags.
606                  * Then link us on our parent's ptraced list.
607                  */
608                 if (!ret) {
609                         current->ptrace |= PT_PTRACED;
610                         __ptrace_link(current, current->real_parent);
611                 }
612
613                 write_unlock_irqrestore(&tasklist_lock, flags);
614         }
615         task_unlock(current);
616         return ret;
617 }
618
619 /**
620  * ptrace_get_task_struct  --  grab a task struct reference for ptrace
621  * @pid:       process id to grab a task_struct reference of
622  *
623  * This function is a helper for ptrace implementations.  It checks
624  * permissions and then grabs a task struct for use of the actual
625  * ptrace implementation.
626  *
627  * Returns the task_struct for @pid or an ERR_PTR() on failure.
628  */
629 struct task_struct *ptrace_get_task_struct(pid_t pid)
630 {
631         struct task_struct *child;
632
633         read_lock(&tasklist_lock);
634         child = find_task_by_vpid(pid);
635         if (child)
636                 get_task_struct(child);
637
638         read_unlock(&tasklist_lock);
639         if (!child)
640                 return ERR_PTR(-ESRCH);
641         return child;
642 }
643
644 #ifndef arch_ptrace_attach
645 #define arch_ptrace_attach(child)       do { } while (0)
646 #endif
647
648 SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
649 {
650         struct task_struct *child;
651         long ret;
652
653         /*
654          * This lock_kernel fixes a subtle race with suid exec
655          */
656         lock_kernel();
657         if (request == PTRACE_TRACEME) {
658                 ret = ptrace_traceme();
659                 if (!ret)
660                         arch_ptrace_attach(current);
661                 goto out;
662         }
663
664         child = ptrace_get_task_struct(pid);
665         if (IS_ERR(child)) {
666                 ret = PTR_ERR(child);
667                 goto out;
668         }
669
670         if (request == PTRACE_ATTACH) {
671                 ret = ptrace_attach(child);
672                 /*
673                  * Some architectures need to do book-keeping after
674                  * a ptrace attach.
675                  */
676                 if (!ret)
677                         arch_ptrace_attach(child);
678                 goto out_put_task_struct;
679         }
680
681         ret = ptrace_check_attach(child, request == PTRACE_KILL);
682         if (ret < 0)
683                 goto out_put_task_struct;
684
685         ret = arch_ptrace(child, request, addr, data);
686         if (ret < 0)
687                 goto out_put_task_struct;
688
689  out_put_task_struct:
690         put_task_struct(child);
691  out:
692         unlock_kernel();
693         return ret;
694 }
695
696 int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
697 {
698         unsigned long tmp;
699         int copied;
700
701         copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
702         if (copied != sizeof(tmp))
703                 return -EIO;
704         return put_user(tmp, (unsigned long __user *)data);
705 }
706
707 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
708 {
709         int copied;
710
711         copied = access_process_vm(tsk, addr, &data, sizeof(data), 1);
712         return (copied == sizeof(data)) ? 0 : -EIO;
713 }
714
715 #if defined CONFIG_COMPAT
716 #include <linux/compat.h>
717
718 int compat_ptrace_request(struct task_struct *child, compat_long_t request,
719                           compat_ulong_t addr, compat_ulong_t data)
720 {
721         compat_ulong_t __user *datap = compat_ptr(data);
722         compat_ulong_t word;
723         siginfo_t siginfo;
724         int ret;
725
726         switch (request) {
727         case PTRACE_PEEKTEXT:
728         case PTRACE_PEEKDATA:
729                 ret = access_process_vm(child, addr, &word, sizeof(word), 0);
730                 if (ret != sizeof(word))
731                         ret = -EIO;
732                 else
733                         ret = put_user(word, datap);
734                 break;
735
736         case PTRACE_POKETEXT:
737         case PTRACE_POKEDATA:
738                 ret = access_process_vm(child, addr, &data, sizeof(data), 1);
739                 ret = (ret != sizeof(data) ? -EIO : 0);
740                 break;
741
742         case PTRACE_GETEVENTMSG:
743                 ret = put_user((compat_ulong_t) child->ptrace_message, datap);
744                 break;
745
746         case PTRACE_GETSIGINFO:
747                 ret = ptrace_getsiginfo(child, &siginfo);
748                 if (!ret)
749                         ret = copy_siginfo_to_user32(
750                                 (struct compat_siginfo __user *) datap,
751                                 &siginfo);
752                 break;
753
754         case PTRACE_SETSIGINFO:
755                 memset(&siginfo, 0, sizeof siginfo);
756                 if (copy_siginfo_from_user32(
757                             &siginfo, (struct compat_siginfo __user *) datap))
758                         ret = -EFAULT;
759                 else
760                         ret = ptrace_setsiginfo(child, &siginfo);
761                 break;
762
763         default:
764                 ret = ptrace_request(child, request, addr, data);
765         }
766
767         return ret;
768 }
769
770 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
771                                   compat_long_t addr, compat_long_t data)
772 {
773         struct task_struct *child;
774         long ret;
775
776         /*
777          * This lock_kernel fixes a subtle race with suid exec
778          */
779         lock_kernel();
780         if (request == PTRACE_TRACEME) {
781                 ret = ptrace_traceme();
782                 goto out;
783         }
784
785         child = ptrace_get_task_struct(pid);
786         if (IS_ERR(child)) {
787                 ret = PTR_ERR(child);
788                 goto out;
789         }
790
791         if (request == PTRACE_ATTACH) {
792                 ret = ptrace_attach(child);
793                 /*
794                  * Some architectures need to do book-keeping after
795                  * a ptrace attach.
796                  */
797                 if (!ret)
798                         arch_ptrace_attach(child);
799                 goto out_put_task_struct;
800         }
801
802         ret = ptrace_check_attach(child, request == PTRACE_KILL);
803         if (!ret)
804                 ret = compat_arch_ptrace(child, request, addr, data);
805
806  out_put_task_struct:
807         put_task_struct(child);
808  out:
809         unlock_kernel();
810         return ret;
811 }
812 #endif  /* CONFIG_COMPAT */