MIPS: scall: Handle seccomp filters which redirect syscalls
[cascardo/linux.git] / arch / mips / kernel / scall64-n32.S
index 71f99d5..9c0b387 100644 (file)
@@ -42,9 +42,6 @@ NESTED(handle_sysn32, PT_SIZE, sp)
 #endif
        beqz    t0, not_n32_scall
 
-       dsll    t0, v0, 3               # offset into table
-       ld      t2, (sysn32_call_table - (__NR_N32_Linux * 8))(t0)
-
        sd      a3, PT_R26(sp)          # save a3 for syscall restarting
 
        li      t1, _TIF_WORK_SYSCALL_ENTRY
@@ -53,6 +50,9 @@ NESTED(handle_sysn32, PT_SIZE, sp)
        bnez    t0, n32_syscall_trace_entry
 
 syscall_common:
+       dsll    t0, v0, 3               # offset into table
+       ld      t2, (sysn32_call_table - (__NR_N32_Linux * 8))(t0)
+
        jalr    t2                      # Do The Real Thing (TM)
 
        li      t0, -EMAXERRNO - 1      # error?
@@ -71,21 +71,25 @@ syscall_common:
 
 n32_syscall_trace_entry:
        SAVE_STATIC
-       move    s0, t2
        move    a0, sp
        move    a1, v0
        jal     syscall_trace_enter
 
        bltz    v0, 1f                  # seccomp failed? Skip syscall
 
-       move    t2, s0
        RESTORE_STATIC
+       ld      v0, PT_R2(sp)           # Restore syscall (maybe modified)
        ld      a0, PT_R4(sp)           # Restore argument registers
        ld      a1, PT_R5(sp)
        ld      a2, PT_R6(sp)
        ld      a3, PT_R7(sp)
        ld      a4, PT_R8(sp)
        ld      a5, PT_R9(sp)
+
+       dsubu   t2, v0, __NR_N32_Linux  # check (new) syscall number
+       sltiu   t0, t2, __NR_N32_Linux_syscalls + 1
+       beqz    t0, not_n32_scall
+
        j       syscall_common
 
 1:     j       syscall_exit