Skip to content

Commit 1cf6022

Browse files
Kenoctmarinas
authored andcommitted
arm64: Fix PTRACE_SYSEMU semantics
Quoth the man page: ``` If the tracee was restarted by PTRACE_SYSCALL or PTRACE_SYSEMU, the tracee enters syscall-enter-stop just prior to entering any system call (which will not be executed if the restart was using PTRACE_SYSEMU, regardless of any change made to registers at this point or how the tracee is restarted after this stop). ``` The parenthetical comment is currently true on x86 and powerpc, but not currently true on arm64. arm64 re-checks the _TIF_SYSCALL_EMU flag after the syscall entry ptrace stop. However, at this point, it reflects which method was used to re-start the syscall at the entry stop, rather than the method that was used to reach it. Fix that by recording the original flag before performing the ptrace stop, bringing the behavior in line with documentation and x86/powerpc. Fixes: f086f67 ("arm64: ptrace: add support for syscall emulation") Cc: <[email protected]> # 5.3.x- Signed-off-by: Keno Fischer <[email protected]> Acked-by: Will Deacon <[email protected]> Tested-by: Sudeep Holla <[email protected]> Tested-by: Bin Lu <[email protected]> [[email protected]: moved 'flags' bit masking] [[email protected]: changed 'flags' type to unsigned long] Signed-off-by: Catalin Marinas <[email protected]>
1 parent d51c214 commit 1cf6022

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,10 +1829,11 @@ static void tracehook_report_syscall(struct pt_regs *regs,
18291829

18301830
int syscall_trace_enter(struct pt_regs *regs)
18311831
{
1832-
if (test_thread_flag(TIF_SYSCALL_TRACE) ||
1833-
test_thread_flag(TIF_SYSCALL_EMU)) {
1832+
unsigned long flags = READ_ONCE(current_thread_info()->flags);
1833+
1834+
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
18341835
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1835-
if (!in_syscall(regs) || test_thread_flag(TIF_SYSCALL_EMU))
1836+
if (!in_syscall(regs) || (flags & _TIF_SYSCALL_EMU))
18361837
return -1;
18371838
}
18381839

0 commit comments

Comments
 (0)