Skip to content

Commit b60e714

Browse files
author
Roland McGrath
committed
x86: ptrace: sysret path should reach syscall_trace_leave
If TIF_SYSCALL_TRACE or TIF_SINGLESTEP is set while inside a syscall, the path back to user mode should get to syscall_trace_leave. This does happen in most circumstances. The exception to this is on the 64-bit syscall fastpath, when no such flag was set on syscall entry and nothing else has punted it off the fastpath for exit. That one exit fastpath fails to check for _TIF_WORK_SYSCALL_EXIT flags. This makes the behavior inconsistent with what 32-bit tasks see and what the native 32-bit kernel always does, and what 64-bit tasks see in all cases where the iret path is taken anyhow. Perhaps the only example that is affected is a ptrace stop inside do_fork (for PTRACE_O_TRACE{CLONE,FORK,VFORK,VFORKDONE}). Other syscalls with internal ptrace stop points (execve) already take the iret exit path for unrelated reasons. Test cases for both PTRACE_SYSCALL and PTRACE_SINGLESTEP variants are at: http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/tests/ptrace-tests/tests/syscall-from-clone.c?cvsroot=systemtap http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/tests/ptrace-tests/tests/step-from-clone.c?cvsroot=systemtap There was no special benefit to the sysret path's special path to call do_notify_resume, because it always takes the iret exit path at the end. So this change just makes the sysret exit path join the iret exit path for all the signals and ptrace cases. The fastpath still applies to the plain syscall-audit and resched cases. Signed-off-by: Roland McGrath <roland@redhat.com> CC: Oleg Nesterov <oleg@redhat.com>
1 parent 7fa0772 commit b60e714

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

arch/x86/kernel/entry_64.S

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -536,20 +536,13 @@ sysret_signal:
536536
bt $TIF_SYSCALL_AUDIT,%edx
537537
jc sysret_audit
538538
#endif
539-
/* edx: work flags (arg3) */
540-
leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
541-
xorl %esi,%esi # oldset -> arg2
542-
SAVE_REST
543-
FIXUP_TOP_OF_STACK %r11
544-
call do_notify_resume
545-
RESTORE_TOP_OF_STACK %r11
546-
RESTORE_REST
547-
movl $_TIF_WORK_MASK,%edi
548-
/* Use IRET because user could have changed frame. This
549-
works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
550-
DISABLE_INTERRUPTS(CLBR_NONE)
551-
TRACE_IRQS_OFF
552-
jmp int_with_check
539+
/*
540+
* We have a signal, or exit tracing or single-step.
541+
* These all wind up with the iret return path anyway,
542+
* so just join that path right now.
543+
*/
544+
FIXUP_TOP_OF_STACK %r11, -ARGOFFSET
545+
jmp int_check_syscall_exit_work
553546

554547
badsys:
555548
movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
@@ -654,6 +647,7 @@ int_careful:
654647
int_very_careful:
655648
TRACE_IRQS_ON
656649
ENABLE_INTERRUPTS(CLBR_NONE)
650+
int_check_syscall_exit_work:
657651
SAVE_REST
658652
/* Check for syscall exit trace */
659653
testl $_TIF_WORK_SYSCALL_EXIT,%edx

0 commit comments

Comments
 (0)