]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/i386/kernel/ptrace.c
Merge branch 'drm-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6
[linux-2.6-omap-h63xx.git] / arch / i386 / kernel / ptrace.c
index 18642f05dde1816d0f3a776360da2a902a8fee75..340980203b095f9cda5113c14369799815dad1e5 100644 (file)
@@ -271,6 +271,8 @@ static void clear_singlestep(struct task_struct *child)
 void ptrace_disable(struct task_struct *child)
 { 
        clear_singlestep(child);
+       clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+       clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
 }
 
 /*
@@ -547,11 +549,17 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
                wake_up_process(child);
                break;
 
+       case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */
        case PTRACE_SINGLESTEP: /* set the trap flag. */
                ret = -EIO;
                if (!valid_signal(data))
                        break;
-               clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
+
+               if (request == PTRACE_SYSEMU_SINGLESTEP)
+                       set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
+               else
+                       clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
+
                clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
                set_singlestep(child);
                child->exit_code = data;
@@ -686,18 +694,39 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
 __attribute__((regparm(3)))
 int do_syscall_trace(struct pt_regs *regs, int entryexit)
 {
-       int is_sysemu, is_singlestep, ret = 0;
+       int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU), ret = 0;
+       /* With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
+        * interception. */
+       int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
+
        /* do the secure computing check first */
        secure_computing(regs->orig_eax);
 
-       if (unlikely(current->audit_context) && entryexit)
-               audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax);
+       if (unlikely(current->audit_context)) {
+               if (entryexit)
+                       audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax);
+               /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
+                * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
+                * not used, entry.S will call us only on syscall exit, not
+                * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
+                * calling send_sigtrap() on syscall entry.
+                *
+                * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
+                * is_singlestep is false, despite his name, so we will still do
+                * the correct thing.
+                */
+               else if (is_singlestep)
+                       goto out;
+       }
 
        if (!(current->ptrace & PT_PTRACED))
                goto out;
 
-       is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
-       is_singlestep = test_thread_flag(TIF_SINGLESTEP);
+       /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
+        * and then is resumed with SYSEMU_SINGLESTEP, it will come in
+        * here. We have to check this and return */
+       if (is_sysemu && entryexit)
+               return 0;
 
        /* Fake a debug trap */
        if (is_singlestep)
@@ -728,6 +757,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
        if (ret == 0)
                return 0;
 
+       regs->orig_eax = -1; /* force skip of syscall restarting */
        if (unlikely(current->audit_context))
                audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax);
        return 1;