commit a9f3a74a29af ("entry: Provide generic syscall exit function")
introduce generic syscall exit function and call rseq_syscall()
before audit_syscall_exit() and arch_syscall_exit_tracehook().

And commit b74406f37737 ("arm: Add syscall detection for restartable
sequences") add rseq support for arm32, which also call rseq_syscall()
before audit_syscall_exit() and tracehook_report_syscall().

However, commit 409d5db49867c ("arm64: rseq: Implement backend rseq
calls and select HAVE_RSEQ") implement arm64 rseq and call
rseq_syscall() after audit_syscall_exit() and tracehook_report_syscall().
So compared to the generic entry and arm32 code, arm64 calls
rseq_syscall() a bit later.

But as commit b74406f37737 ("arm: Add syscall detection for restartable
sequences") said, syscalls are not allowed inside restartable sequences,
so should call rseq_syscall() at the very beginning of system call
exiting path for CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect
whether there is a syscall issued inside restartable sequences.

To align the order of the calls with generic entry, move rseq_syscall()
ahead before audit_syscall_exit().

As for the impact of raising SIGSEGV via rseq_syscall(), it makes no
practical difference to signal delivery because signals are processed
in arm64_exit_to_user_mode() at the very end.

As for the "regs", rseq_syscall() only checks and update
instruction_pointer(regs) when CONFIG_DEBUG_RSEQ=y, audit_syscall_exit()
only checks the return value (x0 for arm64), so calling rseq_syscall()
before or after audit syscall exit makes no difference. trace_sys_exit()
only uses syscallno and the return value, so calling rseq_syscall() before
or after trace_sys_exit() makes no difference.

But ptrace can also modify the "pc" on syscall exit path. So when
CONFIG_DEBUG_RSEQ=y, before this patch, rseq could observe the PC
modified by ptrace on the syscall exit path; after this patch, rseq no
longer sees modifications made by ptrace.

Reviewed-by: Kevin Brodsky <[email protected]>
Signed-off-by: Jinjie Ruan <[email protected]>
---
 arch/arm64/kernel/ptrace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index e3dcadf13e99..50344a2d7b88 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -2455,6 +2455,8 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned 
long flags)
 
 void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)
 {
+       rseq_syscall(regs);
+
        audit_syscall_exit(regs);
 
        if (flags & _TIF_SYSCALL_TRACEPOINT)
@@ -2462,8 +2464,6 @@ void syscall_trace_exit(struct pt_regs *regs, unsigned 
long flags)
 
        if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
                report_syscall_exit(regs);
-
-       rseq_syscall(regs);
 }
 
 /*
-- 
2.34.1


Reply via email to