aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkos Chandras <markos.chandras@imgtec.com>2015-09-25 03:17:42 -0400
committerRalf Baechle <ralf@linux-mips.org>2015-10-04 06:10:56 -0400
commitd218af78492a36a4ae607c08fedfb59258440314 (patch)
treefb9a1d1c08161c39c6f8b8db04b0cc116959718b
parent66803dd9198cb57a4b7ed4a6846a63ab1d59a2e0 (diff)
MIPS: scall: Always run the seccomp syscall filters
The MIPS syscall handler code used to return -ENOSYS on invalid syscalls. Whilst this is expected, it caused problems for seccomp filters because the said filters never had the change to run since the code returned -ENOSYS before triggering them. This caused problems on the chromium testsuite for filters looking for invalid syscalls. This has now changed and the seccomp filters are always run even if the syscall is invalid. We return -ENOSYS once we return from the seccomp filters. Moreover, similar codepaths have been merged in the process which simplifies somewhat the overall syscall code. Signed-off-by: Markos Chandras <markos.chandras@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/11236/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/kernel/scall32-o32.S39
-rw-r--r--arch/mips/kernel/scall64-64.S38
-rw-r--r--arch/mips/kernel/scall64-n32.S19
-rw-r--r--arch/mips/kernel/scall64-o32.S19
4 files changed, 42 insertions, 73 deletions
diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
index d06e30c1e4cd..65a74e4f0f45 100644
--- a/arch/mips/kernel/scall32-o32.S
+++ b/arch/mips/kernel/scall32-o32.S
@@ -36,16 +36,8 @@ NESTED(handle_sys, PT_SIZE, sp)
36 lw t1, PT_EPC(sp) # skip syscall on return 36 lw t1, PT_EPC(sp) # skip syscall on return
37 37
38 subu v0, v0, __NR_O32_Linux # check syscall number 38 subu v0, v0, __NR_O32_Linux # check syscall number
39 sltiu t0, v0, __NR_O32_Linux_syscalls + 1
40 addiu t1, 4 # skip to next instruction 39 addiu t1, 4 # skip to next instruction
41 sw t1, PT_EPC(sp) 40 sw t1, PT_EPC(sp)
42 beqz t0, illegal_syscall
43
44 sll t0, v0, 2
45 la t1, sys_call_table
46 addu t1, t0
47 lw t2, (t1) # syscall routine
48 beqz t2, illegal_syscall
49 41
50 sw a3, PT_R26(sp) # save a3 for syscall restarting 42 sw a3, PT_R26(sp) # save a3 for syscall restarting
51 43
@@ -96,6 +88,16 @@ loads_done:
96 li t1, _TIF_WORK_SYSCALL_ENTRY 88 li t1, _TIF_WORK_SYSCALL_ENTRY
97 and t0, t1 89 and t0, t1
98 bnez t0, syscall_trace_entry # -> yes 90 bnez t0, syscall_trace_entry # -> yes
91syscall_common:
92 sltiu t0, v0, __NR_O32_Linux_syscalls + 1
93 beqz t0, illegal_syscall
94
95 sll t0, v0, 2
96 la t1, sys_call_table
97 addu t1, t0
98 lw t2, (t1) # syscall routine
99
100 beqz t2, illegal_syscall
99 101
100 jalr t2 # Do The Real Thing (TM) 102 jalr t2 # Do The Real Thing (TM)
101 103
@@ -116,7 +118,7 @@ o32_syscall_exit:
116 118
117syscall_trace_entry: 119syscall_trace_entry:
118 SAVE_STATIC 120 SAVE_STATIC
119 move s0, t2 121 move s0, v0
120 move a0, sp 122 move a0, sp
121 123
122 /* 124 /*
@@ -129,27 +131,18 @@ syscall_trace_entry:
129 131
1301: jal syscall_trace_enter 1321: jal syscall_trace_enter
131 133
132 bltz v0, 2f # seccomp failed? Skip syscall 134 bltz v0, 1f # seccomp failed? Skip syscall
135
136 move v0, s0 # restore syscall
133 137
134 move t0, s0
135 RESTORE_STATIC 138 RESTORE_STATIC
136 lw a0, PT_R4(sp) # Restore argument registers 139 lw a0, PT_R4(sp) # Restore argument registers
137 lw a1, PT_R5(sp) 140 lw a1, PT_R5(sp)
138 lw a2, PT_R6(sp) 141 lw a2, PT_R6(sp)
139 lw a3, PT_R7(sp) 142 lw a3, PT_R7(sp)
140 jalr t0 143 j syscall_common
141
142 li t0, -EMAXERRNO - 1 # error?
143 sltu t0, t0, v0
144 sw t0, PT_R7(sp) # set error flag
145 beqz t0, 1f
146
147 lw t1, PT_R2(sp) # syscall number
148 negu v0 # error
149 sw t1, PT_R0(sp) # save it for syscall restarting
1501: sw v0, PT_R2(sp) # result
151 144
1522: j syscall_exit 1451: j syscall_exit
153 146
154/* ------------------------------------------------------------------------ */ 147/* ------------------------------------------------------------------------ */
155 148
diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
index 428c2cd2326c..e732981cf99f 100644
--- a/arch/mips/kernel/scall64-64.S
+++ b/arch/mips/kernel/scall64-64.S
@@ -39,18 +39,11 @@ NESTED(handle_sys64, PT_SIZE, sp)
39 .set at 39 .set at
40#endif 40#endif
41 41
42 dsubu t0, v0, __NR_64_Linux # check syscall number
43 sltiu t0, t0, __NR_64_Linux_syscalls + 1
44#if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32) 42#if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32)
45 ld t1, PT_EPC(sp) # skip syscall on return 43 ld t1, PT_EPC(sp) # skip syscall on return
46 daddiu t1, 4 # skip to next instruction 44 daddiu t1, 4 # skip to next instruction
47 sd t1, PT_EPC(sp) 45 sd t1, PT_EPC(sp)
48#endif 46#endif
49 beqz t0, illegal_syscall
50
51 dsll t0, v0, 3 # offset into table
52 ld t2, (sys_call_table - (__NR_64_Linux * 8))(t0)
53 # syscall routine
54 47
55 sd a3, PT_R26(sp) # save a3 for syscall restarting 48 sd a3, PT_R26(sp) # save a3 for syscall restarting
56 49
@@ -59,6 +52,17 @@ NESTED(handle_sys64, PT_SIZE, sp)
59 and t0, t1, t0 52 and t0, t1, t0
60 bnez t0, syscall_trace_entry 53 bnez t0, syscall_trace_entry
61 54
55syscall_common:
56 dsubu t2, v0, __NR_64_Linux
57 sltiu t0, t2, __NR_64_Linux_syscalls + 1
58 beqz t0, illegal_syscall
59
60 dsll t0, t2, 3 # offset into table
61 dla t2, sys_call_table
62 daddu t0, t2, t0
63 ld t2, (t0) # syscall routine
64 beqz t2, illegal_syscall
65
62 jalr t2 # Do The Real Thing (TM) 66 jalr t2 # Do The Real Thing (TM)
63 67
64 li t0, -EMAXERRNO - 1 # error? 68 li t0, -EMAXERRNO - 1 # error?
@@ -78,14 +82,14 @@ n64_syscall_exit:
78 82
79syscall_trace_entry: 83syscall_trace_entry:
80 SAVE_STATIC 84 SAVE_STATIC
81 move s0, t2 85 move s0, v0
82 move a0, sp 86 move a0, sp
83 move a1, v0 87 move a1, v0
84 jal syscall_trace_enter 88 jal syscall_trace_enter
85 89
86 bltz v0, 2f # seccomp failed? Skip syscall 90 bltz v0, 1f # seccomp failed? Skip syscall
87 91
88 move t0, s0 92 move v0, s0
89 RESTORE_STATIC 93 RESTORE_STATIC
90 ld a0, PT_R4(sp) # Restore argument registers 94 ld a0, PT_R4(sp) # Restore argument registers
91 ld a1, PT_R5(sp) 95 ld a1, PT_R5(sp)
@@ -93,19 +97,9 @@ syscall_trace_entry:
93 ld a3, PT_R7(sp) 97 ld a3, PT_R7(sp)
94 ld a4, PT_R8(sp) 98 ld a4, PT_R8(sp)
95 ld a5, PT_R9(sp) 99 ld a5, PT_R9(sp)
96 jalr t0 100 j syscall_common
97
98 li t0, -EMAXERRNO - 1 # error?
99 sltu t0, t0, v0
100 sd t0, PT_R7(sp) # set error flag
101 beqz t0, 1f
102
103 ld t1, PT_R2(sp) # syscall number
104 dnegu v0 # error
105 sd t1, PT_R0(sp) # save it for syscall restarting
1061: sd v0, PT_R2(sp) # result
107 101
1082: j syscall_exit 1021: j syscall_exit
109 103
110illegal_syscall: 104illegal_syscall:
111 /* This also isn't a 64-bit syscall, throw an error. */ 105 /* This also isn't a 64-bit syscall, throw an error. */
diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
index 3868cf4c83df..c79484397584 100644
--- a/arch/mips/kernel/scall64-n32.S
+++ b/arch/mips/kernel/scall64-n32.S
@@ -52,6 +52,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
52 and t0, t1, t0 52 and t0, t1, t0
53 bnez t0, n32_syscall_trace_entry 53 bnez t0, n32_syscall_trace_entry
54 54
55syscall_common:
55 jalr t2 # Do The Real Thing (TM) 56 jalr t2 # Do The Real Thing (TM)
56 57
57 li t0, -EMAXERRNO - 1 # error? 58 li t0, -EMAXERRNO - 1 # error?
@@ -75,9 +76,9 @@ n32_syscall_trace_entry:
75 move a1, v0 76 move a1, v0
76 jal syscall_trace_enter 77 jal syscall_trace_enter
77 78
78 bltz v0, 2f # seccomp failed? Skip syscall 79 bltz v0, 1f # seccomp failed? Skip syscall
79 80
80 move t0, s0 81 move t2, s0
81 RESTORE_STATIC 82 RESTORE_STATIC
82 ld a0, PT_R4(sp) # Restore argument registers 83 ld a0, PT_R4(sp) # Restore argument registers
83 ld a1, PT_R5(sp) 84 ld a1, PT_R5(sp)
@@ -85,19 +86,9 @@ n32_syscall_trace_entry:
85 ld a3, PT_R7(sp) 86 ld a3, PT_R7(sp)
86 ld a4, PT_R8(sp) 87 ld a4, PT_R8(sp)
87 ld a5, PT_R9(sp) 88 ld a5, PT_R9(sp)
88 jalr t0 89 j syscall_common
89 90
90 li t0, -EMAXERRNO - 1 # error? 911: j syscall_exit
91 sltu t0, t0, v0
92 sd t0, PT_R7(sp) # set error flag
93 beqz t0, 1f
94
95 ld t1, PT_R2(sp) # syscall number
96 dnegu v0 # error
97 sd t1, PT_R0(sp) # save it for syscall restarting
981: sd v0, PT_R2(sp) # result
99
1002: j syscall_exit
101 92
102not_n32_scall: 93not_n32_scall:
103 /* This is not an n32 compatibility syscall, pass it on to 94 /* This is not an n32 compatibility syscall, pass it on to
diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
index 6622980d82ea..6369cfd390c6 100644
--- a/arch/mips/kernel/scall64-o32.S
+++ b/arch/mips/kernel/scall64-o32.S
@@ -87,6 +87,7 @@ loads_done:
87 and t0, t1, t0 87 and t0, t1, t0
88 bnez t0, trace_a_syscall 88 bnez t0, trace_a_syscall
89 89
90syscall_common:
90 jalr t2 # Do The Real Thing (TM) 91 jalr t2 # Do The Real Thing (TM)
91 92
92 li t0, -EMAXERRNO - 1 # error? 93 li t0, -EMAXERRNO - 1 # error?
@@ -130,9 +131,9 @@ trace_a_syscall:
130 131
1311: jal syscall_trace_enter 1321: jal syscall_trace_enter
132 133
133 bltz v0, 2f # seccomp failed? Skip syscall 134 bltz v0, 1f # seccomp failed? Skip syscall
134 135
135 move t0, s0 136 move t2, s0
136 RESTORE_STATIC 137 RESTORE_STATIC
137 ld a0, PT_R4(sp) # Restore argument registers 138 ld a0, PT_R4(sp) # Restore argument registers
138 ld a1, PT_R5(sp) 139 ld a1, PT_R5(sp)
@@ -142,19 +143,9 @@ trace_a_syscall:
142 ld a5, PT_R9(sp) 143 ld a5, PT_R9(sp)
143 ld a6, PT_R10(sp) 144 ld a6, PT_R10(sp)
144 ld a7, PT_R11(sp) # For indirect syscalls 145 ld a7, PT_R11(sp) # For indirect syscalls
145 jalr t0 146 j syscall_common
146 147
147 li t0, -EMAXERRNO - 1 # error? 1481: j syscall_exit
148 sltu t0, t0, v0
149 sd t0, PT_R7(sp) # set error flag
150 beqz t0, 1f
151
152 ld t1, PT_R2(sp) # syscall number
153 dnegu v0 # error
154 sd t1, PT_R0(sp) # save it for syscall restarting
1551: sd v0, PT_R2(sp) # result
156
1572: j syscall_exit
158 149
159/* ------------------------------------------------------------------------ */ 150/* ------------------------------------------------------------------------ */
160 151