Use syscall_get_nr() to get syscall number for syscall_trace_enter().
This aligns arm64's internal tracing logic with the generic
entry framework.

[Changes]
1. Use syscall_get_nr() helper:
   - Replace direct regs->syscallno access with
     syscall_get_nr(current, regs).
   - This helper is functionally equivalent to direct access on arm64.

2. Re-read syscall number after tracepoint:
  - Re-fetch the syscall number after trace_sys_enter() as it may have
    been modified by BPF or ftrace probes, matching generic entry behavior.

[Why this matters]
- Aligns arm64 with the generic entry interface.
- Makes future migration to generic entry framework.
- Properly handles syscall number modifications by tracers.
- Uses standard architecture-independent helpers.

No functional changes intended.

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

diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index e4d524ccbc7b..8d296a07fbf7 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -2410,6 +2410,7 @@ static void report_syscall_exit(struct pt_regs *regs)
 
 int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)
 {
+       long syscall;
        int ret;
 
        if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
@@ -2422,13 +2423,23 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned 
long flags)
        if (secure_computing() == -1)
                return NO_SYSCALL;
 
-       if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
-               trace_sys_enter(regs, regs->syscallno);
+       /* Either of the above might have changed the syscall number */
+       syscall = syscall_get_nr(current, regs);
 
-       audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1],
+       if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) {
+               trace_sys_enter(regs, syscall);
+
+               /*
+                * Probes or BPF hooks in the tracepoint may have changed the
+                * system call number as well.
+                */
+                syscall = syscall_get_nr(current, regs);
+       }
+
+       audit_syscall_entry(syscall, regs->orig_x0, regs->regs[1],
                            regs->regs[2], regs->regs[3]);
 
-       return regs->syscallno;
+       return syscall;
 }
 
 void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)
-- 
2.34.1


Reply via email to