arm64: ptrace: allow tracer to skip a system call
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Fri, 28 Nov 2014 05:26:35 +0000 (05:26 +0000)
committerWill Deacon <will.deacon@arm.com>
Fri, 28 Nov 2014 10:24:13 +0000 (10:24 +0000)
If tracer modifies a syscall number to -1, this traced system call should
be skipped with a return value specified in x0.
This patch implements this semantics.

Please note:
* syscall entry tracing and syscall exit tracing (ftrace tracepoint and
  audit) are always executed, if enabled, even when skipping a system call
  (that is, -1).
  In this way, we can avoid a potential bug where audit_syscall_entry()
  might be called without audit_syscall_exit() at the previous system call
  being called, that would cause OOPs in audit_syscall_entry().

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
[will: fixed up conflict with blr rework]
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/kernel/entry.S

index 99c8d13fc00dba198f19cffe150ceac8dab90434..fd4fa374e5d2b276821e324eb6066f86bdb514c7 100644 (file)
@@ -669,8 +669,15 @@ ENDPROC(el0_svc)
         * switches, and waiting for our parent to respond.
         */
 __sys_trace:
-       mov     x0, sp
+       mov     w0, #-1                         // set default errno for
+       cmp     scno, x0                        // user-issued syscall(-1)
+       b.ne    1f
+       mov     x0, #-ENOSYS
+       str     x0, [sp, #S_X0]
+1:     mov     x0, sp
        bl      syscall_trace_enter
+       cmp     w0, #-1                         // skip the syscall?
+       b.eq    __sys_trace_return_skipped
        uxtw    scno, w0                        // syscall number (possibly new)
        mov     x1, sp                          // pointer to regs
        cmp     scno, sc_nr                     // check upper syscall limit
@@ -683,7 +690,8 @@ __sys_trace:
        blr     x16                             // call sys_* routine
 
 __sys_trace_return:
-       str     x0, [sp]                        // save returned x0
+       str     x0, [sp, #S_X0]                 // save returned x0
+__sys_trace_return_skipped:
        mov     x0, sp
        bl      syscall_trace_exit
        b       ret_to_user