Skip to contentSkip to conversation

MIPS: kernel: scall: Always run the seccomp syscall filters

PATCH Superseded Markos Chandras 2 participants 8 messages Sep 23, 2015 – Sep 25, 2015 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: kernel: 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 chance 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 codepath have been merged in the process which simplifies somewhat the overall syscall code.

---
 arch/mips/kernel/scall32-o32.S | 39 ++++++++++++++++-----------------------
 arch/mips/kernel/scall64-64.S  | 38 ++++++++++++++++----------------------
 arch/mips/kernel/scall64-n32.S | 19 +++++--------------
 arch/mips/kernel/scall64-o32.S | 19 +++++--------------
 4 files changed, 42 insertions(+), 73 deletions(-)
arch/mips/kernel/scall32-o32.S +16 -23
index 4cc13508d967..aa2df3e8dba2 100644
@@ -36,16 +36,8 @@ NESTED(handle_sys, PT_SIZE, sp)
 	lw	t1, PT_EPC(sp)		# skip syscall on return
 
 	subu	v0, v0, __NR_O32_Linux	# check syscall number
-	sltiu	t0, v0, __NR_O32_Linux_syscalls + 1
 	addiu	t1, 4			# skip to next instruction
 	sw	t1, PT_EPC(sp)
-	beqz	t0, illegal_syscall
-
-	sll	t0, v0, 2
-	la	t1, sys_call_table
-	addu	t1, t0
-	lw	t2, (t1)		# syscall routine
-	beqz	t2, illegal_syscall
 
 	sw	a3, PT_R26(sp)		# save a3 for syscall restarting
 
@@ -96,6 +88,16 @@ loads_done:
 	li	t1, _TIF_WORK_SYSCALL_ENTRY
 	and	t0, t1
 	bnez	t0, syscall_trace_entry # -> yes
+syscall_common:
+	sltiu	t0, v0, __NR_O32_Linux_syscalls + 1
+	beqz	t0, illegal_syscall
+
+	sll	t0, v0, 2
+	la	t1, sys_call_table
+	addu	t1, t0
+	lw	t2, (t1)		# syscall routine
+
+	beqz	t2, illegal_syscall
 
 	jalr	t2			# Do The Real Thing (TM)
 
@@ -116,7 +118,7 @@ o32_syscall_exit:
 
 syscall_trace_entry:
 	SAVE_STATIC
-	move	s0, t2
+	move	s0, v0
 	move	a0, sp
 
 	/*
@@ -129,27 +131,18 @@ syscall_trace_entry:
 
 1:	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
+
+	move	v0, s0			# restore syscall
 
-	move	t0, s0
 	RESTORE_STATIC
 	lw	a0, PT_R4(sp)		# Restore argument registers
 	lw	a1, PT_R5(sp)
 	lw	a2, PT_R6(sp)
 	lw	a3, PT_R7(sp)
-	jalr	t0
-
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sw	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	lw	t1, PT_R2(sp)		# syscall number
-	negu	v0			# error
-	sw	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sw	v0, PT_R2(sp)		# result
+	j	syscall_common
 
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 /* ------------------------------------------------------------------------ */
 
arch/mips/kernel/scall64-64.S +16 -22
index a6f6b762c47a..59e754e6241e 100644
@@ -39,18 +39,11 @@ NESTED(handle_sys64, PT_SIZE, sp)
 	.set	at
 #endif
 
-	dsubu	t0, v0, __NR_64_Linux	# check syscall number
-	sltiu	t0, t0, __NR_64_Linux_syscalls + 1
 #if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32)
 	ld	t1, PT_EPC(sp)		# skip syscall on return
 	daddiu	t1, 4			# skip to next instruction
 	sd	t1, PT_EPC(sp)
 #endif
-	beqz	t0, illegal_syscall
-
-	dsll	t0, v0, 3		# offset into table
-	ld	t2, (sys_call_table - (__NR_64_Linux * 8))(t0)
-					# syscall routine
 
 	sd	a3, PT_R26(sp)		# save a3 for syscall restarting
 
@@ -59,6 +52,17 @@ NESTED(handle_sys64, PT_SIZE, sp)
 	and	t0, t1, t0
 	bnez	t0, syscall_trace_entry
 
+syscall_common:
+	dsubu	t2, v0, __NR_64_Linux
+	sltiu   t0, t2, __NR_64_Linux_syscalls + 1
+	beqz	t0, illegal_syscall
+
+	dsll	t0, t2, 3		# offset into table
+	dla	t2, sys_call_table
+	daddu	t2, t0
+	ld	t2, (t0)		# syscall routine
+	beqz	t2, illegal_syscall
+
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -78,14 +82,14 @@ n64_syscall_exit:
 
 syscall_trace_entry:
 	SAVE_STATIC
-	move	s0, t2
+	move	s0, v0
 	move	a0, sp
 	move	a1, v0
 	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	v0, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -93,19 +97,9 @@ syscall_trace_entry:
 	ld	a3, PT_R7(sp)
 	ld	a4, PT_R8(sp)
 	ld	a5, PT_R9(sp)
-	jalr	t0
-
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
+	j	syscall_common
 
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 illegal_syscall:
 	/* This also isn't a 64-bit syscall, throw an error.  */
arch/mips/kernel/scall64-n32.S +5 -14
index 4b2010654c46..8680b92fb6aa 100644
@@ -52,6 +52,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
 	and	t0, t1, t0
 	bnez	t0, n32_syscall_trace_entry
 
+syscall_common:
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -75,9 +76,9 @@ n32_syscall_trace_entry:
 	move	a1, v0
 	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	t2, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -85,19 +86,9 @@ n32_syscall_trace_entry:
 	ld	a3, PT_R7(sp)
 	ld	a4, PT_R8(sp)
 	ld	a5, PT_R9(sp)
-	jalr	t0
+	j	syscall_common
 
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
-
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 not_n32_scall:
 	/* This is not an n32 compatibility syscall, pass it on to
arch/mips/kernel/scall64-o32.S +5 -14
index f543ff4feef9..0fe902ec01ff 100644
@@ -87,6 +87,7 @@ loads_done:
 	and	t0, t1, t0
 	bnez	t0, trace_a_syscall
 
+syscall_common:
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -130,9 +131,9 @@ trace_a_syscall:
 
 1:	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	t2, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -142,19 +143,9 @@ trace_a_syscall:
 	ld	a5, PT_R9(sp)
 	ld	a6, PT_R10(sp)
 	ld	a7, PT_R11(sp)		# For indirect syscalls
-	jalr	t0
+	j	syscall_common
 
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
-
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 /* ------------------------------------------------------------------------ */
 
Signature · 1 line
2.5.2
#1 lore raw

PATCH 1/1 FIXUP: MIPS: fix n64 syscall address calculation

The patch "MIPS: kernel: scall: Always run the seccomp syscall filters" incorrectly calculates the address of the syscall function and instead attempts a load from the offset of the syscall being invoked into the table. This completely trashes all n64 userland syscalls. Fix the address calculation.

Cc Markos Chandras <[email protected]>

---
Markos: could you please test all 3 ABIs you modified? The n64 one at
least has clearly not been tested.

---
 arch/mips/kernel/scall64-64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/scall64-64.S +1 -1
index 59e754e..ffab10a2 100644
@@ -59,7 +59,7 @@ syscall_common:
 
 	dsll	t0, t2, 3		# offset into table
 	dla	t2, sys_call_table
-	daddu	t2, t0
+	daddu	t0, t2
 	ld	t2, (t0)		# syscall routine
 	beqz	t2, illegal_syscall
 
Signature · 1 line
2.5.3
#2 lore raw

Re: [PATCH] FIXUP: MIPS: fix n64 syscall address calculation

Quoted 6 lines · Paul Burton

The patch "MIPS: kernel: scall: Always run the seccomp syscall filters" incorrectly calculates the address of the syscall function and instead attempts a load from the offset of the syscall being invoked into the table. This completely trashes all n64 userland syscalls. Fix the address calculation.

Quoted 6 lines
Cc Markos Chandras <[email protected]>

---
Markos: could you please test all 3 ABIs you modified? The n64 one at
least has clearly not been tested.
---

Calm down. it was an honest mistake. The version I sent was slighly different to what I had in my tree and that's why the tests were passing for me. I will send it again.

Signature · 1 line
markos
#3 lore raw

Re: [PATCH] FIXUP: MIPS: fix n64 syscall address calculation

Quoted 14 lines · Markos Chandras
Quoted 6 lines · Paul Burton

The patch "MIPS: kernel: scall: Always run the seccomp syscall filters" incorrectly calculates the address of the syscall function and instead attempts a load from the offset of the syscall being invoked into the table. This completely trashes all n64 userland syscalls. Fix the address calculation.

Quoted 6 lines
Cc Markos Chandras <[email protected]>

---
Markos: could you please test all 3 ABIs you modified? The n64 one at
least has clearly not been tested.
---

Quoted 6 lines

Calm down. it was an honest mistake. The version I sent was slighly different to what I had in my tree and that's why the tests were passing for me. I will send it again.

Signature · 1 line
markos

I'm quite calm, simply stating facts & asking you to fix your patch. Please don't presume to know my state of mind in lieu of a very strong indicator!

Thanks for submitting v2, though from your description I presume it's just v1 plus this fixup, correct?

Paul

#4 lore raw

Re: [PATCH] FIXUP: MIPS: fix n64 syscall address calculation

Quoted 22 lines · Paul Burton
Quoted 14 lines · Markos Chandras
Quoted 6 lines · Paul Burton

The patch "MIPS: kernel: scall: Always run the seccomp syscall filters" incorrectly calculates the address of the syscall function and instead attempts a load from the offset of the syscall being invoked into the table. This completely trashes all n64 userland syscalls. Fix the address calculation.

Quoted 6 lines
Cc Markos Chandras <[email protected]>

---
Markos: could you please test all 3 ABIs you modified? The n64 one at
least has clearly not been tested.
---

Quoted 6 lines

Calm down. it was an honest mistake. The version I sent was slighly different to what I had in my tree and that's why the tests were passing for me. I will send it again.

Signature · 1 line
markos
Quoted 8 lines

I'm quite calm, simply stating facts & asking you to fix your patch. Please don't presume to know my state of mind in lieu of a very strong indicator!

Thanks for submitting v2, though from your description I presume it's just v1 plus this fixup, correct?

Paul

There is a changelog in v2 as well.

Signature · 1 line
markos
#5 lore raw

Re: [PATCH] FIXUP: MIPS: fix n64 syscall address calculation

Quoted 27 lines · Markos Chandras
Quoted 26 lines · Paul Burton
Quoted 14 lines · Markos Chandras
Quoted 6 lines · Paul Burton

The patch "MIPS: kernel: scall: Always run the seccomp syscall filters" incorrectly calculates the address of the syscall function and instead attempts a load from the offset of the syscall being invoked into the table. This completely trashes all n64 userland syscalls. Fix the address calculation.

Quoted 6 lines
Cc Markos Chandras <[email protected]>

---
Markos: could you please test all 3 ABIs you modified? The n64 one at
least has clearly not been tested.
---

Quoted 6 lines

Calm down. it was an honest mistake. The version I sent was slighly different to what I had in my tree and that's why the tests were passing for me. I will send it again.

Signature · 1 line
markos

I'm quite calm, simply stating facts & asking you to fix your patch. Please don't presume to know my state of mind in lieu of a very strong indicator!

Quoted 9 lines
Quoted 4 lines

Thanks for submitting v2, though from your description I presume it's just v1 plus this fixup, correct?

Paul

There is a changelog in v2 as well.

Signature · 1 line
markos

Yes, and it simply reads "Fix offset calculation for n64", which I interpret as a slightly less accurately described version of this fixup. Diffing your 2 patches shows that this one line is all that changed, to a form equivalent to this patch, which answers my question:

 +      dsll    t0, t2, 3               # offset into table
 +      dla     t2, sys_call_table
-+      daddu   t2, t0
++      daddu   t0, t2, t0
 +      ld      t2, (t0)                # syscall routine
 +      beqz    t2, illegal_syscall

Thanks,
Paul

#6 lore raw

PATCH v2 1/1 MIPS: kernel: scall: Always run the seccomp syscall filters

In reply to Markos Chandras

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 codepath have been merged in the process which simplifies somewhat the overall syscall code.

---
Changes since v1:
- Fix offset calculation for n64

---
 arch/mips/kernel/scall32-o32.S | 39 ++++++++++++++++-----------------------
 arch/mips/kernel/scall64-64.S  | 38 ++++++++++++++++----------------------
 arch/mips/kernel/scall64-n32.S | 19 +++++--------------
 arch/mips/kernel/scall64-o32.S | 19 +++++--------------
 4 files changed, 42 insertions(+), 73 deletions(-)
arch/mips/kernel/scall32-o32.S +16 -23
index 4cc13508d967..aa2df3e8dba2 100644
@@ -36,16 +36,8 @@ NESTED(handle_sys, PT_SIZE, sp)
 	lw	t1, PT_EPC(sp)		# skip syscall on return
 
 	subu	v0, v0, __NR_O32_Linux	# check syscall number
-	sltiu	t0, v0, __NR_O32_Linux_syscalls + 1
 	addiu	t1, 4			# skip to next instruction
 	sw	t1, PT_EPC(sp)
-	beqz	t0, illegal_syscall
-
-	sll	t0, v0, 2
-	la	t1, sys_call_table
-	addu	t1, t0
-	lw	t2, (t1)		# syscall routine
-	beqz	t2, illegal_syscall
 
 	sw	a3, PT_R26(sp)		# save a3 for syscall restarting
 
@@ -96,6 +88,16 @@ loads_done:
 	li	t1, _TIF_WORK_SYSCALL_ENTRY
 	and	t0, t1
 	bnez	t0, syscall_trace_entry # -> yes
+syscall_common:
+	sltiu	t0, v0, __NR_O32_Linux_syscalls + 1
+	beqz	t0, illegal_syscall
+
+	sll	t0, v0, 2
+	la	t1, sys_call_table
+	addu	t1, t0
+	lw	t2, (t1)		# syscall routine
+
+	beqz	t2, illegal_syscall
 
 	jalr	t2			# Do The Real Thing (TM)
 
@@ -116,7 +118,7 @@ o32_syscall_exit:
 
 syscall_trace_entry:
 	SAVE_STATIC
-	move	s0, t2
+	move	s0, v0
 	move	a0, sp
 
 	/*
@@ -129,27 +131,18 @@ syscall_trace_entry:
 
 1:	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
+
+	move	v0, s0			# restore syscall
 
-	move	t0, s0
 	RESTORE_STATIC
 	lw	a0, PT_R4(sp)		# Restore argument registers
 	lw	a1, PT_R5(sp)
 	lw	a2, PT_R6(sp)
 	lw	a3, PT_R7(sp)
-	jalr	t0
-
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sw	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	lw	t1, PT_R2(sp)		# syscall number
-	negu	v0			# error
-	sw	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sw	v0, PT_R2(sp)		# result
+	j	syscall_common
 
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 /* ------------------------------------------------------------------------ */
 
arch/mips/kernel/scall64-64.S +16 -22
index a6f6b762c47a..08a2542dd79e 100644
@@ -39,18 +39,11 @@ NESTED(handle_sys64, PT_SIZE, sp)
 	.set	at
 #endif
 
-	dsubu	t0, v0, __NR_64_Linux	# check syscall number
-	sltiu	t0, t0, __NR_64_Linux_syscalls + 1
 #if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32)
 	ld	t1, PT_EPC(sp)		# skip syscall on return
 	daddiu	t1, 4			# skip to next instruction
 	sd	t1, PT_EPC(sp)
 #endif
-	beqz	t0, illegal_syscall
-
-	dsll	t0, v0, 3		# offset into table
-	ld	t2, (sys_call_table - (__NR_64_Linux * 8))(t0)
-					# syscall routine
 
 	sd	a3, PT_R26(sp)		# save a3 for syscall restarting
 
@@ -59,6 +52,17 @@ NESTED(handle_sys64, PT_SIZE, sp)
 	and	t0, t1, t0
 	bnez	t0, syscall_trace_entry
 
+syscall_common:
+	dsubu	t2, v0, __NR_64_Linux
+	sltiu   t0, t2, __NR_64_Linux_syscalls + 1
+	beqz	t0, illegal_syscall
+
+	dsll	t0, t2, 3		# offset into table
+	dla	t2, sys_call_table
+	daddu	t0, t2, t0
+	ld	t2, (t0)		# syscall routine
+	beqz	t2, illegal_syscall
+
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -78,14 +82,14 @@ n64_syscall_exit:
 
 syscall_trace_entry:
 	SAVE_STATIC
-	move	s0, t2
+	move	s0, v0
 	move	a0, sp
 	move	a1, v0
 	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	v0, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -93,19 +97,9 @@ syscall_trace_entry:
 	ld	a3, PT_R7(sp)
 	ld	a4, PT_R8(sp)
 	ld	a5, PT_R9(sp)
-	jalr	t0
-
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
+	j	syscall_common
 
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 illegal_syscall:
 	/* This also isn't a 64-bit syscall, throw an error.  */
arch/mips/kernel/scall64-n32.S +5 -14
index 4b2010654c46..8680b92fb6aa 100644
@@ -52,6 +52,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
 	and	t0, t1, t0
 	bnez	t0, n32_syscall_trace_entry
 
+syscall_common:
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -75,9 +76,9 @@ n32_syscall_trace_entry:
 	move	a1, v0
 	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	t2, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -85,19 +86,9 @@ n32_syscall_trace_entry:
 	ld	a3, PT_R7(sp)
 	ld	a4, PT_R8(sp)
 	ld	a5, PT_R9(sp)
-	jalr	t0
+	j	syscall_common
 
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
-
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 not_n32_scall:
 	/* This is not an n32 compatibility syscall, pass it on to
arch/mips/kernel/scall64-o32.S +5 -14
index f543ff4feef9..0fe902ec01ff 100644
@@ -87,6 +87,7 @@ loads_done:
 	and	t0, t1, t0
 	bnez	t0, trace_a_syscall
 
+syscall_common:
 	jalr	t2			# Do The Real Thing (TM)
 
 	li	t0, -EMAXERRNO - 1	# error?
@@ -130,9 +131,9 @@ trace_a_syscall:
 
 1:	jal	syscall_trace_enter
 
-	bltz	v0, 2f			# seccomp failed? Skip syscall
+	bltz	v0, 1f			# seccomp failed? Skip syscall
 
-	move	t0, s0
+	move	t2, s0
 	RESTORE_STATIC
 	ld	a0, PT_R4(sp)		# Restore argument registers
 	ld	a1, PT_R5(sp)
@@ -142,19 +143,9 @@ trace_a_syscall:
 	ld	a5, PT_R9(sp)
 	ld	a6, PT_R10(sp)
 	ld	a7, PT_R11(sp)		# For indirect syscalls
-	jalr	t0
+	j	syscall_common
 
-	li	t0, -EMAXERRNO - 1	# error?
-	sltu	t0, t0, v0
-	sd	t0, PT_R7(sp)		# set error flag
-	beqz	t0, 1f
-
-	ld	t1, PT_R2(sp)		# syscall number
-	dnegu	v0			# error
-	sd	t1, PT_R0(sp)		# save it for syscall restarting
-1:	sd	v0, PT_R2(sp)		# result
-
-2:	j	syscall_exit
+1:	j	syscall_exit
 
 /* ------------------------------------------------------------------------ */
 
Signature · 1 line
2.5.3
#7 lore raw
Quoted 11 lines · Markos Chandras

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 codepath have been merged in the process which simplifies somewhat the overall syscall code.

Quoted 2 lines

---

Ralf,

I didn't add CC: stable 3.15+ on this patch. Feel free to add it yourself if you think this patch is useful for stable releases.

Signature · 1 line
markos