aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--include/asm-x86/signal.h11
-rw-r--r--include/asm-x86/thread_info_32.h2
-rw-r--r--include/asm-x86/thread_info_64.h2
12 files changed, 79 insertions, 59 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 */
diff --git a/include/asm-x86/signal.h b/include/asm-x86/signal.h
index 987a422a2c78..aee7eca585ab 100644
--- a/include/asm-x86/signal.h
+++ b/include/asm-x86/signal.h
@@ -245,21 +245,14 @@ static __inline__ int sigfindinword(unsigned long word)
245 245
246struct pt_regs; 246struct pt_regs;
247 247
248#define ptrace_signal_deliver(regs, cookie) \
249 do { \
250 if (current->ptrace & PT_DTRACE) { \
251 current->ptrace &= ~PT_DTRACE; \
252 (regs)->eflags &= ~TF_MASK; \
253 } \
254 } while (0)
255
256#else /* __i386__ */ 248#else /* __i386__ */
257 249
258#undef __HAVE_ARCH_SIG_BITOPS 250#undef __HAVE_ARCH_SIG_BITOPS
259 251
252#endif /* !__i386__ */
253
260#define ptrace_signal_deliver(regs, cookie) do { } while (0) 254#define ptrace_signal_deliver(regs, cookie) do { } while (0)
261 255
262#endif /* !__i386__ */
263#endif /* __KERNEL__ */ 256#endif /* __KERNEL__ */
264#endif /* __ASSEMBLY__ */ 257#endif /* __ASSEMBLY__ */
265 258
diff --git a/include/asm-x86/thread_info_32.h b/include/asm-x86/thread_info_32.h
index a516e9192f11..009ecc6ad38b 100644
--- a/include/asm-x86/thread_info_32.h
+++ b/include/asm-x86/thread_info_32.h
@@ -138,6 +138,7 @@ static inline struct thread_info *current_thread_info(void)
138#define TIF_IO_BITMAP 18 /* uses I/O bitmap */ 138#define TIF_IO_BITMAP 18 /* uses I/O bitmap */
139#define TIF_FREEZE 19 /* is freezing for suspend */ 139#define TIF_FREEZE 19 /* is freezing for suspend */
140#define TIF_NOTSC 20 /* TSC is not accessible in userland */ 140#define TIF_NOTSC 20 /* TSC is not accessible in userland */
141#define TIF_FORCED_TF 21 /* true if TF in eflags artificially */
141 142
142#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 143#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
143#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 144#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -153,6 +154,7 @@ static inline struct thread_info *current_thread_info(void)
153#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) 154#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP)
154#define _TIF_FREEZE (1<<TIF_FREEZE) 155#define _TIF_FREEZE (1<<TIF_FREEZE)
155#define _TIF_NOTSC (1<<TIF_NOTSC) 156#define _TIF_NOTSC (1<<TIF_NOTSC)
157#define _TIF_FORCED_TF (1<<TIF_FORCED_TF)
156 158
157/* work to do on interrupt/exception return */ 159/* work to do on interrupt/exception return */
158#define _TIF_WORK_MASK \ 160#define _TIF_WORK_MASK \
diff --git a/include/asm-x86/thread_info_64.h b/include/asm-x86/thread_info_64.h
index c8e7736fc792..e0f41b3deced 100644
--- a/include/asm-x86/thread_info_64.h
+++ b/include/asm-x86/thread_info_64.h
@@ -121,6 +121,7 @@ static inline struct thread_info *stack_thread_info(void)
121#define TIF_DEBUG 21 /* uses debug registers */ 121#define TIF_DEBUG 21 /* uses debug registers */
122#define TIF_IO_BITMAP 22 /* uses I/O bitmap */ 122#define TIF_IO_BITMAP 22 /* uses I/O bitmap */
123#define TIF_FREEZE 23 /* is freezing for suspend */ 123#define TIF_FREEZE 23 /* is freezing for suspend */
124#define TIF_FORCED_TF 24 /* true if TF in eflags artificially */
124 125
125#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 126#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
126#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 127#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -138,6 +139,7 @@ static inline struct thread_info *stack_thread_info(void)
138#define _TIF_DEBUG (1<<TIF_DEBUG) 139#define _TIF_DEBUG (1<<TIF_DEBUG)
139#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) 140#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP)
140#define _TIF_FREEZE (1<<TIF_FREEZE) 141#define _TIF_FREEZE (1<<TIF_FREEZE)
142#define _TIF_FORCED_TF (1<<TIF_FORCED_TF)
141 143
142/* work to do on interrupt/exception return */ 144/* work to do on interrupt/exception return */
143#define _TIF_WORK_MASK \ 145#define _TIF_WORK_MASK \