i386: fix singlestepping though a syscall
PATCH 1/1 i386: fix singlestepping though a syscall
Singlestep through a syscall using vsyscall-sysenter had two bugs:
1. Setting TIF_SINGLESTEP is not enough to force do_notify_resume() to be run on return to user; TIF_IRET must also be set.
2. do_notify_resume() was being passed masked copies of task_thread_flags, so TIF_SINGLESTEP was never seen as set when it was called. This was changed to use the 'test' instruction instead of 'and'; a duplicated piece of code was removed instead of fixing that part too.
Also changed some misleading 'jne' to 'jnz' to make it clearer what is happening.
--- arch/i386/kernel/entry.S | 17 +++++------------ arch/i386/kernel/traps.c | 1 + 2 files changed, 6 insertions(+), 12 deletions(-)
arch/i386/kernel/entry.S +5 -12
@@ -152,9 +152,9 @@ ENTRY(resume_userspace) # setting need_resched or sigpending # between sampling and the iret movl TI_flags(%ebp), %ecx - andl $_TIF_WORK_MASK, %ecx # is there any work to be done on + testl $_TIF_WORK_MASK, %ecx # is there any work to be done on # int/exception return? - jne work_pending + jnz work_pending jmp restore_all #ifdef CONFIG_PREEMPT
@@ -301,21 +301,14 @@ work_pending: jz work_notifysig work_resched: call schedule - cli # make sure we don't miss an interrupt - # setting need_resched or sigpending - # between sampling and the iret - movl TI_flags(%ebp), %ecx - andl $_TIF_WORK_MASK, %ecx # is there any work to be done other - # than syscall tracing? - jz restore_all - testb $_TIF_NEED_RESCHED, %cl - jnz work_resched + jmp resume_userspace + ALIGN work_notifysig: # deal with pending signals and # notify-resume requests testl $VM_MASK, EFLAGS(%esp) movl %esp, %eax - jne work_notifysig_v86 # returning to kernel-space or + jnz work_notifysig_v86 # returning to kernel-space or # vm86-space xorl %edx, %edx call do_notify_resume
arch/i386/kernel/traps.c +1 -0
@@ -795,6 +795,7 @@ debug_vm86: clear_TF_reenable:set_tsk_thread_flag (tsk,TIF_SINGLESTEP ); +set_tsk_thread_flag (tsk,TIF_IRET ); regs->eflags &= ~TF_MASK ;return ; }
Signature · 2 lines
Chuck "Equations are the Devil's sentences." --Stephen Colbert
Quoted 6 lines · Chuck Ebbert
Singlestep through a syscall using vsyscall-sysenter had two bugs:
1. Setting
TIF_SINGLESTEPis not enough to forcedo_notify_resume()to be run on return to user;TIF_IRETmust also be set.
Interesting, but I think you pinpointed the _real_ bug.
TIF_SINGLESTEP very much should be enough to force do_notify_resume() to be run on return to user space.
Sounds like somebody is testing _TIF_WORK_MASK rather than _TIF_ALLWORK_MASK.
I'd suspect the "work_pending" case. Looks like we miss testing the TIF flags there.
Oh, actually, I think you should just remove the clearing of _TIF_SINGLESTEP from _TIF_WORK_MASK. Does that fix the bug.
Linus