]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
x86 ptrace: user-sets-TF nits
authorRoland McGrath <roland@redhat.com>
Wed, 9 Jul 2008 09:39:29 +0000 (02:39 -0700)
committerRoland McGrath <roland@redhat.com>
Wed, 16 Jul 2008 19:15:17 +0000 (12:15 -0700)
This closes some arcane holes in single-step handling that can arise
only when user programs set TF directly (via popf or sigreturn) and
then use vDSO (syscall/sysenter) system call entry.  In those entry
paths, the clear_TF_reenable case hits and we must check TIF_SINGLESTEP
to be sure our bookkeeping stays correct wrt the user's view of TF.

Signed-off-by: Roland McGrath <roland@redhat.com>
arch/x86/kernel/ptrace.c
arch/x86/kernel/step.c
include/asm-x86/thread_info.h

index 34e77b16a42a66042a67f8f5a7efef01883367ac..e37dccce85db5e15922602b833a3821b78ca4ffd 100644 (file)
@@ -1416,6 +1416,16 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 {
        long ret = 0;
 
+       /*
+        * If we stepped into a sysenter/syscall insn, it trapped in
+        * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
+        * If user-mode had set TF itself, then it's still clear from
+        * do_debug() and we need to set it again to restore the user
+        * state.  If we entered on the slow path, TF was already set.
+        */
+       if (test_thread_flag(TIF_SINGLESTEP))
+               regs->flags |= X86_EFLAGS_TF;
+
        /* do the secure computing check first */
        secure_computing(regs->orig_ax);
 
index 0d2cb363ea752a721cf62372c19c8e89423b3756..e8b9863ef8c4f8d09f10344d868450711add7ee5 100644 (file)
@@ -107,6 +107,19 @@ static int enable_single_step(struct task_struct *child)
        struct pt_regs *regs = task_pt_regs(child);
        unsigned long oflags;
 
+       /*
+        * If we stepped into a sysenter/syscall insn, it trapped in
+        * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
+        * If user-mode had set TF itself, then it's still clear from
+        * do_debug() and we need to set it again to restore the user
+        * state so we don't wrongly set TIF_FORCED_TF below.
+        * If enable_single_step() was used last and that is what
+        * set TIF_SINGLESTEP, then both TF and TIF_FORCED_TF are
+        * already set and our bookkeeping is fine.
+        */
+       if (unlikely(test_tsk_thread_flag(child, TIF_SINGLESTEP)))
+               regs->flags |= X86_EFLAGS_TF;
+
        /*
         * Always set TIF_SINGLESTEP - this guarantees that
         * we single-step system calls etc..  This will also
index b2702a1eeac1a69fd7d5cbc75040905581fd0069..0a8f27d31d0db4eb25075a01525827e540488867 100644 (file)
@@ -118,7 +118,7 @@ struct thread_info {
 /* work to do in syscall_trace_enter() */
 #define _TIF_WORK_SYSCALL_ENTRY        \
        (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | \
-        _TIF_SYSCALL_AUDIT | _TIF_SECCOMP)
+        _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP)
 
 /* work to do in syscall_trace_leave() */
 #define _TIF_WORK_SYSCALL_EXIT \