aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2008-01-30 07:30:50 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:30:50 -0500
commite1f287735c1e58c653b516931b5d3dd899edcb77 (patch)
tree1a2948cfe8ff679135971e2c573d11b847fee93d /arch/x86
parent7122ec8158b0f88befd94f4da8feae2c8d08d1b4 (diff)
x86 single_step: TIF_FORCED_TF
This changes the single-step support to use a new thread_info flag TIF_FORCED_TF instead of the PT_DTRACE flag in task_struct.ptrace. This keeps arch implementation uses out of this non-arch field. This changes the ptrace access to eflags to mask TF and maintain the TIF_FORCED_TF flag directly if userland sets TF, instead of relying on ptrace_signal_deliver. The 64-bit and 32-bit kernels are harmonized on this same behavior. The ptrace_signal_deliver approach works now, but this change makes the low-level register access code reliable when called from different contexts than a ptrace stop, which will be possible in the future. The 64-bit do_debug exception handler is also changed not to clear TF from user-mode registers. This matches the 32-bit kernel's behavior. Signed-off-by: Roland McGrath <roland@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/ia32/ptrace32.c20
-rw-r--r--arch/x86/kernel/process_32.c3
-rw-r--r--arch/x86/kernel/process_64.c5
-rw-r--r--arch/x86/kernel/ptrace_32.c17
-rw-r--r--arch/x86/kernel/ptrace_64.c20
-rw-r--r--arch/x86/kernel/signal_32.c12
-rw-r--r--arch/x86/kernel/signal_64.c14
-rw-r--r--arch/x86/kernel/step.c9
-rw-r--r--arch/x86/kernel/traps_64.c23
9 files changed, 73 insertions, 50 deletions
diff --git a/arch/x86/ia32/ptrace32.c b/arch/x86/ia32/ptrace32.c
index 9d754b640205..5dee33417313 100644
--- a/arch/x86/ia32/ptrace32.c
+++ b/arch/x86/ia32/ptrace32.c
@@ -89,6 +89,15 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val)
89 __u64 *flags = &stack[offsetof(struct pt_regs, eflags)/8]; 89 __u64 *flags = &stack[offsetof(struct pt_regs, eflags)/8];
90 90
91 val &= FLAG_MASK; 91 val &= FLAG_MASK;
92 /*
93 * If the user value contains TF, mark that
94 * it was not "us" (the debugger) that set it.
95 * If not, make sure it stays set if we had.
96 */
97 if (val & X86_EFLAGS_TF)
98 clear_tsk_thread_flag(child, TIF_FORCED_TF);
99 else if (test_tsk_thread_flag(child, TIF_FORCED_TF))
100 val |= X86_EFLAGS_TF;
92 *flags = val | (*flags & ~FLAG_MASK); 101 *flags = val | (*flags & ~FLAG_MASK);
93 break; 102 break;
94 } 103 }
@@ -179,9 +188,17 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
179 R32(eax, rax); 188 R32(eax, rax);
180 R32(orig_eax, orig_rax); 189 R32(orig_eax, orig_rax);
181 R32(eip, rip); 190 R32(eip, rip);
182 R32(eflags, eflags);
183 R32(esp, rsp); 191 R32(esp, rsp);
184 192
193 case offsetof(struct user32, regs.eflags):
194 /*
195 * If the debugger set TF, hide it from the readout.
196 */
197 *val = stack[offsetof(struct pt_regs, eflags)/8];
198 if (test_tsk_thread_flag(child, TIF_FORCED_TF))
199 *val &= ~X86_EFLAGS_TF;
200 break;
201
185 case offsetof(struct user32, u_debugreg[0]): 202 case offsetof(struct user32, u_debugreg[0]):
186 *val = child->thread.debugreg0; 203 *val = child->thread.debugreg0;
187 break; 204 break;
@@ -425,4 +442,3 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
425 put_task_struct(child); 442 put_task_struct(child);
426 return ret; 443 return ret;
427} 444}
428
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 4d66a56280d3..d9905c9d0fd5 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -817,9 +817,6 @@ asmlinkage int sys_execve(struct pt_regs regs)
817 (char __user * __user *) regs.edx, 817 (char __user * __user *) regs.edx,
818 &regs); 818 &regs);
819 if (error == 0) { 819 if (error == 0) {
820 task_lock(current);
821 current->ptrace &= ~PT_DTRACE;
822 task_unlock(current);
823 /* Make sure we don't return using sysenter.. */ 820 /* Make sure we don't return using sysenter.. */
824 set_thread_flag(TIF_IRET); 821 set_thread_flag(TIF_IRET);
825 } 822 }
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index ccc9d68d5a58..f7356e5517f6 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -709,11 +709,6 @@ long sys_execve(char __user *name, char __user * __user *argv,
709 if (IS_ERR(filename)) 709 if (IS_ERR(filename))
710 return error; 710 return error;
711 error = do_execve(filename, argv, envp, &regs); 711 error = do_execve(filename, argv, envp, &regs);
712 if (error == 0) {
713 task_lock(current);
714 current->ptrace &= ~PT_DTRACE;
715 task_unlock(current);
716 }
717 putname(filename); 712 putname(filename);
718 return error; 713 return error;
719} 714}
diff --git a/arch/x86/kernel/ptrace_32.c b/arch/x86/kernel/ptrace_32.c
index b73960885c3f..bc7fd802dcc7 100644
--- a/arch/x86/kernel/ptrace_32.c
+++ b/arch/x86/kernel/ptrace_32.c
@@ -104,6 +104,15 @@ static int putreg(struct task_struct *child,
104 break; 104 break;
105 case EFL: 105 case EFL:
106 value &= FLAG_MASK; 106 value &= FLAG_MASK;
107 /*
108 * If the user value contains TF, mark that
109 * it was not "us" (the debugger) that set it.
110 * If not, make sure it stays set if we had.
111 */
112 if (value & X86_EFLAGS_TF)
113 clear_tsk_thread_flag(child, TIF_FORCED_TF);
114 else if (test_tsk_thread_flag(child, TIF_FORCED_TF))
115 value |= X86_EFLAGS_TF;
107 value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK; 116 value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK;
108 break; 117 break;
109 } 118 }
@@ -119,6 +128,14 @@ static unsigned long getreg(struct task_struct *child,
119 unsigned long retval = ~0UL; 128 unsigned long retval = ~0UL;
120 129
121 switch (regno >> 2) { 130 switch (regno >> 2) {
131 case EFL:
132 /*
133 * If the debugger set TF, hide it from the readout.
134 */
135 retval = get_stack_long(child, EFL_OFFSET);
136 if (test_tsk_thread_flag(child, TIF_FORCED_TF))
137 retval &= ~X86_EFLAGS_TF;
138 break;
122 case GS: 139 case GS:
123 retval = child->thread.gs; 140 retval = child->thread.gs;
124 break; 141 break;
diff --git a/arch/x86/kernel/ptrace_64.c b/arch/x86/kernel/ptrace_64.c
index 4abfbced9b26..035d53e99c57 100644
--- a/arch/x86/kernel/ptrace_64.c
+++ b/arch/x86/kernel/ptrace_64.c
@@ -143,6 +143,15 @@ static int putreg(struct task_struct *child,
143 return 0; 143 return 0;
144 case offsetof(struct user_regs_struct, eflags): 144 case offsetof(struct user_regs_struct, eflags):
145 value &= FLAG_MASK; 145 value &= FLAG_MASK;
146 /*
147 * If the user value contains TF, mark that
148 * it was not "us" (the debugger) that set it.
149 * If not, make sure it stays set if we had.
150 */
151 if (value & X86_EFLAGS_TF)
152 clear_tsk_thread_flag(child, TIF_FORCED_TF);
153 else if (test_tsk_thread_flag(child, TIF_FORCED_TF))
154 value |= X86_EFLAGS_TF;
146 tmp = get_stack_long(child, EFL_OFFSET); 155 tmp = get_stack_long(child, EFL_OFFSET);
147 tmp &= ~FLAG_MASK; 156 tmp &= ~FLAG_MASK;
148 value |= tmp; 157 value |= tmp;
@@ -189,6 +198,17 @@ static unsigned long getreg(struct task_struct *child, unsigned long regno)
189 if (child->thread.gsindex != GS_TLS_SEL) 198 if (child->thread.gsindex != GS_TLS_SEL)
190 return 0; 199 return 0;
191 return get_desc_base(&child->thread.tls_array[GS_TLS]); 200 return get_desc_base(&child->thread.tls_array[GS_TLS]);
201 case offsetof(struct user_regs_struct, eflags):
202 /*
203 * If the debugger set TF, hide it from the readout.
204 */
205 regno = regno - sizeof(struct pt_regs);
206 val = get_stack_long(child, regno);
207 if (test_tsk_thread_flag(child, TIF_IA32))
208 val &= 0xffffffff;
209 if (test_tsk_thread_flag(child, TIF_FORCED_TF))
210 val &= ~X86_EFLAGS_TF;
211 return val;
192 default: 212 default:
193 regno = regno - sizeof(struct pt_regs); 213 regno = regno - sizeof(struct pt_regs);
194 val = get_stack_long(child, regno); 214 val = get_stack_long(child, regno);
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c
index 1ac53e9a0859..0a7c812212c9 100644
--- a/arch/x86/kernel/signal_32.c
+++ b/arch/x86/kernel/signal_32.c
@@ -545,14 +545,12 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
545 } 545 }
546 546
547 /* 547 /*
548 * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so 548 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
549 * that register information in the sigcontext is correct. 549 * flag so that register information in the sigcontext is correct.
550 */ 550 */
551 if (unlikely(regs->eflags & TF_MASK) 551 if (unlikely(regs->eflags & X86_EFLAGS_TF) &&
552 && likely(current->ptrace & PT_DTRACE)) { 552 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
553 current->ptrace &= ~PT_DTRACE; 553 regs->eflags &= ~X86_EFLAGS_TF;
554 regs->eflags &= ~TF_MASK;
555 }
556 554
557 /* Set up the stack frame */ 555 /* Set up the stack frame */
558 if (ka->sa.sa_flags & SA_SIGINFO) 556 if (ka->sa.sa_flags & SA_SIGINFO)
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c
index 38d806467c0f..ab0178ebe00a 100644
--- a/arch/x86/kernel/signal_64.c
+++ b/arch/x86/kernel/signal_64.c
@@ -349,16 +349,12 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
349 } 349 }
350 350
351 /* 351 /*
352 * If TF is set due to a debugger (PT_DTRACE), clear the TF 352 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
353 * flag so that register information in the sigcontext is 353 * flag so that register information in the sigcontext is correct.
354 * correct.
355 */ 354 */
356 if (unlikely(regs->eflags & TF_MASK)) { 355 if (unlikely(regs->eflags & X86_EFLAGS_TF) &&
357 if (likely(current->ptrace & PT_DTRACE)) { 356 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
358 current->ptrace &= ~PT_DTRACE; 357 regs->eflags &= ~X86_EFLAGS_TF;
359 regs->eflags &= ~TF_MASK;
360 }
361 }
362 358
363#ifdef CONFIG_IA32_EMULATION 359#ifdef CONFIG_IA32_EMULATION
364 if (test_thread_flag(TIF_IA32)) { 360 if (test_thread_flag(TIF_IA32)) {
diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
index 6732272e3479..243bff650ca5 100644
--- a/arch/x86/kernel/step.c
+++ b/arch/x86/kernel/step.c
@@ -135,7 +135,7 @@ void user_enable_single_step(struct task_struct *child)
135 if (is_setting_trap_flag(child, regs)) 135 if (is_setting_trap_flag(child, regs))
136 return; 136 return;
137 137
138 child->ptrace |= PT_DTRACE; 138 set_tsk_thread_flag(child, TIF_FORCED_TF);
139} 139}
140 140
141void user_disable_single_step(struct task_struct *child) 141void user_disable_single_step(struct task_struct *child)
@@ -144,9 +144,6 @@ void user_disable_single_step(struct task_struct *child)
144 clear_tsk_thread_flag(child, TIF_SINGLESTEP); 144 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
145 145
146 /* But touch TF only if it was set by us.. */ 146 /* But touch TF only if it was set by us.. */
147 if (child->ptrace & PT_DTRACE) { 147 if (test_and_clear_tsk_thread_flag(child, TIF_FORCED_TF))
148 struct pt_regs *regs = task_pt_regs(child); 148 task_pt_regs(child)->eflags &= ~X86_EFLAGS_TF;
149 regs->eflags &= ~X86_EFLAGS_TF;
150 child->ptrace &= ~PT_DTRACE;
151 }
152} 149}
diff --git a/arch/x86/kernel/traps_64.c b/arch/x86/kernel/traps_64.c
index aa248d754533..874aca397b02 100644
--- a/arch/x86/kernel/traps_64.c
+++ b/arch/x86/kernel/traps_64.c
@@ -865,27 +865,14 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
865 865
866 tsk->thread.debugreg6 = condition; 866 tsk->thread.debugreg6 = condition;
867 867
868 /* Mask out spurious TF errors due to lazy TF clearing */ 868
869 /*
870 * Single-stepping through TF: make sure we ignore any events in
871 * kernel space (but re-enable TF when returning to user mode).
872 */
869 if (condition & DR_STEP) { 873 if (condition & DR_STEP) {
870 /*
871 * The TF error should be masked out only if the current
872 * process is not traced and if the TRAP flag has been set
873 * previously by a tracing process (condition detected by
874 * the PT_DTRACE flag); remember that the i386 TRAP flag
875 * can be modified by the process itself in user mode,
876 * allowing programs to debug themselves without the ptrace()
877 * interface.
878 */
879 if (!user_mode(regs)) 874 if (!user_mode(regs))
880 goto clear_TF_reenable; 875 goto clear_TF_reenable;
881 /*
882 * Was the TF flag set by a debugger? If so, clear it now,
883 * so that register information is correct.
884 */
885 if (tsk->ptrace & PT_DTRACE) {
886 regs->eflags &= ~TF_MASK;
887 tsk->ptrace &= ~PT_DTRACE;
888 }
889 } 876 }
890 877
891 /* Ok, finally something we can handle */ 878 /* Ok, finally something we can handle */