]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
MIPS: Remove pt_regs adjustments in indirect syscall handler
authorJames Cowgill <James.Cowgill@imgtec.com>
Fri, 31 Mar 2017 16:09:59 +0000 (17:09 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 29 Aug 2017 13:48:34 +0000 (15:48 +0200)
If a restartable syscall is called using the indirect o32 syscall
handler - eg: syscall(__NR_waitid, ...), then it is possible for the
incorrect arguments to be passed to the syscall after it has been
restarted. This is because the syscall handler tries to shift all the
registers down one place in pt_regs so that when the syscall is restarted,
the "real" syscall is called instead. Unfortunately it only shifts the
arguments passed in registers, not the arguments on the user stack. This
causes the 4th argument to be duplicated when the syscall is restarted.

Fix by removing all the pt_regs shifting so that the indirect syscall
handler is called again when the syscall is restarted. The comment "some
syscalls like execve get their arguments from struct pt_regs" is long
out of date so this should now be safe.

Signed-off-by: James Cowgill <James.Cowgill@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Tested-by: James Hogan <james.hogan@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/15856/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/kernel/scall32-o32.S
arch/mips/kernel/scall64-o32.S

index 27c2f90eeb21f60e07e6cb4534fb33cdd0b68ef9..a9a7d78803cde30097a02c76aa49bef9f812be7e 100644 (file)
@@ -190,12 +190,6 @@ illegal_syscall:
        sll     t1, t0, 2
        beqz    v0, einval
        lw      t2, sys_call_table(t1)          # syscall routine
-       sw      a0, PT_R2(sp)                   # call routine directly on restart
-
-       /* Some syscalls like execve get their arguments from struct pt_regs
-          and claim zero arguments in the syscall table. Thus we have to
-          assume the worst case and shuffle around all potential arguments.
-          If you want performance, don't use indirect syscalls. */
 
        move    a0, a1                          # shift argument registers
        move    a1, a2
@@ -207,11 +201,6 @@ illegal_syscall:
        sw      t4, 16(sp)
        sw      t5, 20(sp)
        sw      t6, 24(sp)
-       sw      a0, PT_R4(sp)                   # .. and push back a0 - a3, some
-       sw      a1, PT_R5(sp)                   # syscalls expect them there
-       sw      a2, PT_R6(sp)
-       sw      a3, PT_R7(sp)
-       sw      a3, PT_R26(sp)                  # update a3 for syscall restarting
        jr      t2
        /* Unreached */
 
index c30bc520885f985a921b066bfb45d5dea8aadab2..9ebe3e2403b1d7b84d66732cd261364208f6020d 100644 (file)
@@ -198,7 +198,6 @@ LEAF(sys32_syscall)
        dsll    t1, t0, 3
        beqz    v0, einval
        ld      t2, sys32_call_table(t1)                # syscall routine
-       sd      a0, PT_R2(sp)           # call routine directly on restart
 
        move    a0, a1                  # shift argument registers
        move    a1, a2
@@ -207,11 +206,6 @@ LEAF(sys32_syscall)
        move    a4, a5
        move    a5, a6
        move    a6, a7
-       sd      a0, PT_R4(sp)           # ... and push back a0 - a3, some
-       sd      a1, PT_R5(sp)           # syscalls expect them there
-       sd      a2, PT_R6(sp)
-       sd      a3, PT_R7(sp)
-       sd      a3, PT_R26(sp)          # update a3 for syscall restarting
        jr      t2
        /* Unreached */